📄 tokenizer.php
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4: */// +----------------------------------------------------------------------+// | PHP Version 4 |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2002 The PHP Group |// +----------------------------------------------------------------------+// | This source file is subject to version 2.02 of the PHP license, |// | that is bundled with this package in the file LICENSE, and is |// | available at through the world-wide-web at |// | http://www.php.net/license/2_02.txt. |// | If you did not receive a copy of the PHP license and are unable to |// | obtain it through the world-wide-web, please send a note to |// | license@php.net so we can mail you a copy immediately. |// +----------------------------------------------------------------------+// | Authors: Alan Knowles <alan@akbkhome.com> |// +----------------------------------------------------------------------+//// $Id: Tokenizer.php,v 1.61 2005/05/14 04:01:41 alan_k Exp $//// The Source Lex file. (Tokenizer.lex) and the Generated one (Tokenizer.php)// You should always work with the .lex file and generate by//// #mono phpLex/phpLex.exe Tokenizer.lex// The lexer is available at http://sourceforge.net/projects/php-sharp/// // or the equivialant .NET runtime on windows...//// Note need to change a few of these defines, and work out// how to modifiy the lexer to handle the changes..//define('HTML_TEMPLATE_FLEXY_TOKEN_NONE',1);define('HTML_TEMPLATE_FLEXY_TOKEN_OK',2);define('HTML_TEMPLATE_FLEXY_TOKEN_ERROR',3);define("YYINITIAL" ,0);define("IN_SINGLEQUOTE" , 1) ;define("IN_TAG" , 2) ;define("IN_ATTR" , 3);define("IN_ATTRVAL" , 4) ;define("IN_NETDATA" , 5);define("IN_ENDTAG" , 6);define("IN_DOUBLEQUOTE" , 7);define("IN_MD" , 8);define("IN_COM" , 9);define("IN_DS", 10);define("IN_FLEXYMETHOD" , 11);define("IN_FLEXYMETHODQUOTED" ,12);define("IN_FLEXYMETHODQUOTED_END" ,13);define("IN_SCRIPT", 14);define("IN_CDATA" , 15);define("IN_DSCOM", 16);define("IN_PHP", 17);define("IN_COMSTYLE" , 18);define('YY_E_INTERNAL', 0);define('YY_E_MATCH', 1);define('YY_BUFFER_SIZE', 4096);define('YY_F' , -1);define('YY_NO_STATE', -1);define('YY_NOT_ACCEPT' , 0);define('YY_START' , 1);define('YY_END' , 2);define('YY_NO_ANCHOR' , 4);define('YY_BOL' , 257);define('YY_EOF' , 258);class HTML_Template_Flexy_Tokenizer{ /** * options array : meanings: * ignore_html - return all tags as text tokens * * * @var boolean public * @access public */ var $options = array( 'ignore_html' => false, 'token_factory' => array('HTML_Template_Flexy_Token','factory'), ); /** * flag if inside a style tag. (so comments are ignored.. ) * * @var boolean * @access private */ var $inStyle = false; /** * the start position of a cdata block * * @var int * @access private */ var $yyCdataBegin = 0; /** * the start position of a comment block * * @var int * @access private */ var $yyCommentBegin = 0; /** * the name of the file being parsed (used by error messages) * * @var string * @access public */ var $fileName; /** * the string containing an error if it occurs.. * * @var string * @access public */ var $error; /** * Flexible constructor * * @param string string to tokenize * @param array options array (see options above) * * * @return HTML_Template_Flexy_Tokenizer * @access public */ function &construct($data,$options= array()) { $t = new HTML_Template_Flexy_Tokenizer($data); foreach($options as $k=>$v) { if (is_object($v) || is_array($v)) { $t->options[$k] = &$v; continue; } $t->options[$k] = $v; } return $t; } /** * raise an error: = return an error token and set the error variable. * * * @param string Error type * @param string Full Error message * @param boolean is it fatal.. * * @return int the error token. * @access public */ function raiseError($s,$n='',$isFatal=false) { $this->error = "ERROR $n in File {$this->fileName} on Line {$this->yyline} Position:{$this->yy_buffer_end}: $s\n"; return HTML_TEMPLATE_FLEXY_TOKEN_ERROR; } /** * return text * * Used mostly by the ignore HTML code. - really a macro :) * * @return int token ok. * @access public */ function returnSimple() { $this->value = $this->createToken('TextSimple'); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } /** * Create a token based on the value of $this->options['token_call'] * * * @return Object some kind of token.. * @access public */ function createToken($token, $value = false, $line = false, $charPos = false) { if ($value === false) { $value = $this->yytext(); } if ($line === false) { $line = $this->yyline; } if ($charPos === false) { $charPos = $this->yy_buffer_start; } return call_user_func_array($this->options['token_factory'],array($token,$value,$line,$charPos)); } var $yy_reader; var $yy_buffer_index; var $yy_buffer_read; var $yy_buffer_start; var $yy_buffer_end; var $yy_buffer; var $yychar; var $yyline; var $yyEndOfLine; var $yy_at_bol; var $yy_lexical_state; function HTML_Template_Flexy_Tokenizer($data) { $this->yy_buffer = $data; $this->yy_buffer_read = strlen($data); $this->yy_buffer_index = 0; $this->yy_buffer_start = 0; $this->yy_buffer_end = 0; $this->yychar = 0; $this->yyline = 0; $this->yy_at_bol = true; $this->yy_lexical_state = YYINITIAL; } var $yy_state_dtrans = array ( 0, 227, 35, 134, 251, 252, 253, 254, 54, 65, 262, 264, 286, 300, 301, 309, 83, 85, 87 ); function yybegin ($state) { $this->yy_lexical_state = $state; } function yy_advance () { if ($this->yy_buffer_index < $this->yy_buffer_read) { return ord($this->yy_buffer{$this->yy_buffer_index++}); } return YY_EOF; } function yy_move_end () { if ($this->yy_buffer_end > $this->yy_buffer_start && '\n' == $this->yy_buffer{$this->yy_buffer_end-1}) { $this->yy_buffer_end--; } if ($this->yy_buffer_end > $this->yy_buffer_start && '\r' == $this->yy_buffer{$this->yy_buffer_end-1}) { $this->yy_buffer_end--; } } var $yy_last_was_cr=false; function yy_mark_start () { for ($i = $this->yy_buffer_start; $i < $this->yy_buffer_index; $i++) { if ($this->yy_buffer{$i} == "\n" && !$this->yy_last_was_cr) { $this->yyline++; $this->yyEndOfLine = $this->yychar; } if ($this->yy_buffer{$i} == "\r") { $this->yyline++; $this->yyEndOfLine = $this->yychar; $this->yy_last_was_cr=true; } else { $this->yy_last_was_cr=false; } } $this->yychar = $this->yychar + $this->yy_buffer_index - $this->yy_buffer_start; $this->yy_buffer_start = $this->yy_buffer_index; } function yy_mark_end () { $this->yy_buffer_end = $this->yy_buffer_index; } function yy_to_mark () { $this->yy_buffer_index = $this->yy_buffer_end; $this->yy_at_bol = ($this->yy_buffer_end > $this->yy_buffer_start) && ($this->yy_buffer{$this->yy_buffer_end-1} == '\r' || $this->yy_buffer{$this->yy_buffer_end-1} == '\n'); } function yytext() { return substr($this->yy_buffer,$this->yy_buffer_start,$this->yy_buffer_end - $this->yy_buffer_start); } function yylength () { return $this->yy_buffer_end - $this->yy_buffer_start; } var $yy_error_string = array( "Error: Internal error.\n", "Error: Unmatched input.\n" ); function yy_error ($code,$fatal) { if (method_exists($this,'raiseError')) { return $this->raiseError($code, $this->yy_error_string[$code], $fatal); } echo $this->yy_error_string[$code]; if ($fatal) { exit; } } var $yy_acpt = array ( /* 0 */ YY_NOT_ACCEPT, /* 1 */ YY_NO_ANCHOR,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -