Skip to content

Commit

Permalink
- support for -ve numbers in {arrays[-1]}
Browse files Browse the repository at this point in the history
- support for variable replacements in commented out blocks of styles


git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Template_Flexy/trunk@170052 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
roojs committed Oct 8, 2004
1 parent 2fded0d commit 7886e6f
Show file tree
Hide file tree
Showing 14 changed files with 2,725 additions and 1,134 deletions.
2 changes: 1 addition & 1 deletion Flexy/Token.php
Expand Up @@ -492,7 +492,7 @@ function toVar($s) {
$s = str_replace('%5d',"']",$s);
$s = str_replace('%5D',"']",$s);
// strip the quotes if it's only numbers..
$s = preg_replace("/'([0-9]+)'/", "\\1",$s);
$s = preg_replace("/'([-]?[0-9]+)'/", "\\1",$s);

$parts = explode(".",$s);

Expand Down
73 changes: 65 additions & 8 deletions Flexy/Tokenizer.lex
Expand Up @@ -56,6 +56,7 @@ 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);
Expand Down Expand Up @@ -104,6 +105,16 @@ define('YY_EOF' , 258);
);


/**
* flag if inside a style tag. (so comments are ignored.. )
*
* @var boolean
* @access private
*/


var $inStyle = false;

/**
* the start position of a cdata block
*
Expand Down Expand Up @@ -219,7 +230,7 @@ define('YY_EOF' , 258);
%line
%full
%char
%state IN_SINGLEQUOTE IN_TAG IN_ATTR IN_ATTRVAL IN_NETDATA IN_ENDTAG IN_DOUBLEQUOTE IN_MD IN_COM IN_DS IN_FLEXYMETHOD IN_FLEXYMETHODQUOTED IN_FLEXYMETHODQUOTED_END IN_SCRIPT IN_CDATA IN_DSCOM IN_PHP
%state IN_SINGLEQUOTE IN_TAG IN_ATTR IN_ATTRVAL IN_NETDATA IN_ENDTAG IN_DOUBLEQUOTE IN_MD IN_COM IN_DS IN_FLEXYMETHOD IN_FLEXYMETHODQUOTED IN_FLEXYMETHODQUOTED_END IN_SCRIPT IN_CDATA IN_DSCOM IN_PHP IN_COMSTYLE



Expand Down Expand Up @@ -291,7 +302,7 @@ FLEXY_GTEND = ")_}"
FLEXY_START = ("%7B"|"%7b"|"{")
FLEXY_NEGATE = "!"
FLEXY_SIMPLEVAR = (({NAME_START_CHARACTER}|"_")({LCLETTER}|{UCLETTER}|"_"|{DIGIT})*)
FLEXY_ARRAY = (("["|"%5B"|"%5b")({DIGIT}|{NAME_START_CHARACTER}|"_")+("]"|"%5D"|"%5d"))
FLEXY_ARRAY = (("["|"%5B"|"%5b")({DIGIT}|{NAME_START_CHARACTER}|"_"|"-")+("]"|"%5D"|"%5d"))
FLEXY_VAR = ({FLEXY_SIMPLEVAR}{FLEXY_ARRAY}*("."{FLEXY_SIMPLEVAR}{FLEXY_ARRAY}*)*)
FLEXY_METHOD = ({FLEXY_SIMPLEVAR}|{FLEXY_SIMPLEVAR}{FLEXY_ARRAY}*("."{FLEXY_SIMPLEVAR}{FLEXY_ARRAY}*)*"."{FLEXY_SIMPLEVAR})
FLEXY_END = ("%7D"|"%7d"|"}")
Expand Down Expand Up @@ -344,6 +355,9 @@ END_SCRIPT = {ETAGO}(S|s)(C|c)(r|R)(I|i)(P|p)(T|t){TAGC}
if ($this->options['ignore_html']) {
return $this->returnSimple();
}
if ($this->inStyle) {
$this->inStyle = false;
}
$this->tagName = trim(substr($this->yytext(),1));
$this->tokenName = 'EndTag';
$this->yybegin(IN_ENDTAG);
Expand Down Expand Up @@ -389,8 +403,14 @@ END_SCRIPT = {ETAGO}(S|s)(C|c)(r|R)(I|i)(P|p)(T|t){TAGC}
if ($this->options['ignore_html']) {
return $this->returnSimple();
}
$this->yyCommentBegin = $this->yy_buffer_end;

if ($this->inStyle) {
$this->value = $this->createToken('Text',$this->yytext(),$this->yyline);
$this->yybegin(IN_COMSTYLE);
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}

$this->yyCommentBegin = $this->yy_buffer_end;
//$this->value = $this->createToken('Comment',$this->yytext(),$this->yyline);
$this->yybegin(IN_COM);
return HTML_TEMPLATE_FLEXY_TOKEN_NONE;
Expand Down Expand Up @@ -703,9 +723,13 @@ END_SCRIPT = {ETAGO}(S|s)(C|c)(r|R)(I|i)(P|p)(T|t){TAGC}

if (strtoupper($this->tagName) == 'SCRIPT') {
$this->yybegin(IN_SCRIPT);

return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}
if (strtoupper($this->tagName) == 'STYLE') {
$this->inStyle = true;
} else {
$this->inStyle = false;
}
$this->yybegin(YYINITIAL);
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}
Expand Down Expand Up @@ -787,16 +811,31 @@ END_SCRIPT = {ETAGO}(S|s)(C|c)(r|R)(I|i)(P|p)(T|t){TAGC}
<IN_COM>([^-]|-[^-])*{WHITESPACE} {
// inside a comment (not - or not --
// <!^--...--> -- comment */

//$this->value = $this->createToken('Comment',$this->yytext(),$this->yyline);


return HTML_TEMPLATE_FLEXY_TOKEN_NONE;
}
<IN_COM>{COM}[^>] {
// inside comment -- without a >
return HTML_TEMPLATE_FLEXY_TOKEN_NONE;
}


<IN_COMSTYLE>([^"{"][^-]|-[^-])*{WHITESPACE} {
// inside a style comment (not - or not --
// <!^--...--> -- comment */
$this->value = $this->createToken('Comment', $this->yytext(),$this->yyline);
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}
<IN_COMSTYLE>{COM}[^>] {
// inside style comment -- without a >
$this->value = $this->createToken('Comment', $this->yytext(),$this->yyline);
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}





<IN_DSCOM>([^-]|-[^-])*{WHITESPACE} {
// inside a comment (not - or not --
// <!^--...--> -- comment */
Expand Down Expand Up @@ -857,6 +896,24 @@ END_SCRIPT = {ETAGO}(S|s)(C|c)(r|R)(I|i)(P|p)(T|t){TAGC}
$this->yybegin(YYINITIAL);
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}

<IN_COMSTYLE>[-]*{COM}{TAGC} {
// --> inside a style tag.
$this->value = $this->createToken('Comment', $this->yytext(),$this->yyline);
$this->yybegin(YYINITIAL);
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}

<IN_COMSTYLE>("{"{FLEXY_VAR}":"{FLEXY_MODIFIER}"}")|("{"{FLEXY_VAR}"}") {
// var in commented out style bit..
$t = $this->yytext();
$t = substr($t,1,-1);

$this->value = $this->createToken('Var' , $t, $this->yyline);
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}


<IN_DSCOM>{COM}{TAGC} {
$this->value = $this->createToken('DSEnd', $this->yytext(),$this->yyline);
$this->yybegin(YYINITIAL);
Expand All @@ -879,7 +936,7 @@ END_SCRIPT = {ETAGO}(S|s)(C|c)(r|R)(I|i)(P|p)(T|t){TAGC}
return HTML_TEMPLATE_FLEXY_TOKEN_OK;
}

<IN_MD,IN_COM>. {
<IN_MD,IN_COM,IN_COMSTYLE>. {
return $this->raiseError("illegal character in markup declaration");
}

Expand Down

0 comments on commit 7886e6f

Please sign in to comment.