parse InlineHtml

This commit is contained in:
z7zmey 2017-11-29 00:35:21 +02:00
parent ed0771f7a0
commit aa1c9b9257
4 changed files with 770 additions and 714 deletions

View File

@ -7664,8 +7664,28 @@ yyrule1: // [ \t\n\r]+
goto yystate0
yyrule2: // .
{
tb := []byte{}
for {
if c == -1 {
break
}
if '?' == rune(c) {
tb = l.TokenBytes(nil)
if len(tb) < 2 || tb[len(tb)-1] != '<' {
c = l.Next()
continue
}
tb = l.ungetN(1)
break
}
c = l.Next()
}
lval.token = string(tb)
return T_INLINE_HTML
goto yystate0
}
yyrule3: // \<\?php([ \t]|{NEW_LINE})
{
begin(PHP) //lval.token = string(l.TokenBytes(nil)); return T_OPEN_TAG;
@ -7690,9 +7710,7 @@ yyrule6: // [ \t\n\r]+
}
yyrule7: // \?\>{NEW_LINE}?
{
begin(INITIAL)
lval.token = string(l.TokenBytes(nil))
return T_CLOSE_TAG
begin(INITIAL) //lval.token = string(l.TokenBytes(nil)); return T_CLOSE_TAG;
goto yystate0
}
yyrule8: // {DNUM}|{EXPONENT_DNUM}

25
lexer.l
View File

@ -154,12 +154,35 @@ NEW_LINE (\r|\n|\r\n)
<INITIAL>[ \t\n\r]+
<INITIAL>.
tb := []byte{}
for {
if c == -1 {
break;
}
if '?' == rune(c) {
tb = l.TokenBytes(nil);
if (len(tb) < 2 || tb[len(tb)-1] != '<') {
c = l.Next()
continue;
}
tb = l.ungetN(1)
break;
}
c = l.Next()
}
lval.token = string(tb); return T_INLINE_HTML
<INITIAL>\<\?php([ \t]|{NEW_LINE}) begin(PHP);//lval.token = string(l.TokenBytes(nil)); return T_OPEN_TAG;
<INITIAL>\<\? begin(PHP);//lval.token = string(l.TokenBytes(nil)); return T_OPEN_TAG;
<INITIAL>\<\?= begin(PHP);lval.token = string(l.TokenBytes(nil)); return T_OPEN_TAG_WITH_ECHO;
<PHP>[ \t\n\r]+ //lval.token = string(l.TokenBytes(nil)); return T_WHITESPACE
<PHP>\?\>{NEW_LINE}? begin(INITIAL);lval.token = string(l.TokenBytes(nil)); return T_CLOSE_TAG;
<PHP>\?\>{NEW_LINE}? begin(INITIAL);//lval.token = string(l.TokenBytes(nil)); return T_CLOSE_TAG;
<PHP>{DNUM}|{EXPONENT_DNUM} lval.token = string(l.TokenBytes(nil)); return T_DNUMBER
<PHP>{BNUM}

1428
parser.go

File diff suppressed because it is too large Load Diff

View File

@ -303,6 +303,7 @@ statement:
| T_GLOBAL global_var_list ';' { $$ = $2; }
| T_STATIC static_var_list ';' { $$ = $2; }
| T_ECHO echo_expr_list ';' { $$ = $2; }
| T_INLINE_HTML { $$ = Node("Echo").append(Node("InlineHtml").attribute("value", $1)) }
| expr ';' { $$ = $1; }
if_stmt_without_else:
@ -610,10 +611,12 @@ simple_variable:
%%
const src = `<?
const src = `a<?
static $a, $b = $c;
?> test<?php
echo $a, $b = $c;
`