common tokens

This commit is contained in:
vadim 2017-11-16 12:53:21 +02:00
parent 841e92a8bd
commit 17f05837ea
2 changed files with 5256 additions and 304 deletions

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,7 @@ const (
STRING_VAR
STRING_VAR_INDEX
STRING_VAR_NAME
PROPERTY
)
@ -126,7 +127,7 @@ func (l *lexer) Lex() int { // Lex(lval *yySymType)
%}
%s PHP STRING STRING_VAR STRING_VAR_INDEX STRING_VAR_NAME
%s PHP STRING STRING_VAR STRING_VAR_INDEX STRING_VAR_NAME PROPERTY
%yyb last == '\n' || last = '\0'
%yyt sc
@ -134,9 +135,13 @@ func (l *lexer) Lex() int { // Lex(lval *yySymType)
%yyn c = l.Next()
%yym l.Mark()
D ([0-9]+)
VAR_NAME [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
OPERATORS [;:,.\[\]()|\/\^&\+-*=%!~$<>?@]
LNUM [0-9]+
DNUM ([0-9]*"."[0-9]+)|([0-9]+"."[0-9]*)
HNUM 0x[0-9a-fA-F]+
BNUM 0b[01]+
EXPONENT_DNUM (({LNUM}|{DNUM})[eE][+-]?{LNUM})
VAR_NAME [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
OPERATORS [;:,.\[\]()|\/\^&\+-*=%!~$<>?@]
%%
c = l.Rule0()
@ -144,13 +149,127 @@ OPERATORS [;:,.\[\]()|\/\^&\+-*=%!~$<>?@]
<INITIAL>[ \t\n\r]+
<INITIAL>.
<INITIAL>\<\?|\<\?php fmt.Println("T_OPEN_TAG");begin(PHP)
<INITIAL>\<\?= fmt.Println("T_OPEN_TAG_WITH_ECHO");begin(PHP)
<INITIAL>\<\?|\<\?php fmt.Println("T_OPEN_TAG");begin(PHP)
<INITIAL>\<\?= fmt.Println("T_OPEN_TAG_WITH_ECHO");begin(PHP)
<PHP>[ \t\n\r]+ fmt.Println("T_WHITESPACE")
<PHP>\?\> fmt.Println("T_CLOSE_TAG");begin(INITIAL)
<PHP>[ \t\n\r]+ fmt.Println("T_WHITESPACE")
<PHP>\?\> fmt.Println("T_CLOSE_TAG");begin(INITIAL)
<PHP>[\']([^\\\']*([\\][\'])*)*[\'] fmt.Printf("T_CONSTANT_ENCAPSED_STRING: %s\n", l.TokenBytes(nil));
<PHP>abstract fmt.Println("T_ABSTRACT")
<PHP>array fmt.Println("T_ARRAY")
<PHP>as fmt.Println("T_AS")
<PHP>break fmt.Println("T_BREAK")
<PHP>callable fmt.Println("T_CALLABLE")
<PHP>case fmt.Println("T_CASE")
<PHP>catch fmt.Println("T_CATCH")
<PHP>class fmt.Println("T_CLASS")
<PHP>clone fmt.Println("T_CLONE")
<PHP>const fmt.Println("T_CONST");
<PHP>continue fmt.Println("T_CONTINUE");
<PHP>declare fmt.Println("T_DECLARE");
<PHP>default fmt.Println("T_DEFAULT");
<PHP>do fmt.Println("T_DO");
<PHP>echo fmt.Println("T_ECHO");
<PHP>else fmt.Println("T_ELSE");
<PHP>elseif fmt.Println("T_ELSEIF");
<PHP>empty fmt.Println("T_EMPTY");
<PHP>endfor fmt.Println("T_ENDFOR")
<PHP>endforeach fmt.Println("T_ENDFOREACH")
<PHP>endif fmt.Println("T_ENDIF")
<PHP>endswitch fmt.Println("T_ENDSWITCH")
<PHP>endwhile fmt.Println("T_ENDWHILE")
<PHP>exit|die fmt.Println("T_EXIT")
<PHP>extends fmt.Println("T_EXTENDS")
<PHP>final fmt.Println("T_FINAL")
<PHP>finally fmt.Println("T_FINALLY")
<PHP>for fmt.Println("T_FOR")
<PHP>foreach fmt.Println("T_FOREACH")
<PHP>function|cfunction fmt.Println("T_FUNCTION")
<PHP>global fmt.Println("T_GLOBAL")
<PHP>goto fmt.Println("T_GOTO")
<PHP>if fmt.Println("T_IF")
<PHP>implements fmt.Println("T_IMPLEMENTS")
<PHP>instanceof fmt.Println("T_INSTANCEOF")
<PHP>insteadof fmt.Println("T_INSTEADOF")
<PHP>interface fmt.Println("T_INTERFACE")
<PHP>namespace fmt.Println("T_NAMESPACE")
<PHP>private fmt.Println("T_PRIVATE")
<PHP>public fmt.Println("T_PUBLIC")
<PHP>protected fmt.Println("T_PROTECTED")
<PHP>return fmt.Println("T_RETURN")
<PHP>static fmt.Println("T_STATIC")
<PHP>switch fmt.Println("T_SWITCH")
<PHP>throw fmt.Println("T_THROW")
<PHP>trait fmt.Println("T_TRAIT")
<PHP>try fmt.Println("T_TRY")
<PHP>use fmt.Println("T_USE")
<PHP>var fmt.Println("T_VAR")
<PHP>while fmt.Println("T_WHILE")
<PHP>yield[ \t\n\r]+from[^a-zA-Z0-9_\x80-\xff] fmt.Println("T_YIELD_FROM")
<PHP>yield fmt.Println("T_YIELD")
<PHP>__CLASS__ fmt.Println("T_CLASS_C")
<PHP>__DIR__ fmt.Println("T_DIR")
<PHP>__FILE__ fmt.Println("T_FILE")
<PHP>__FUNCTION__ fmt.Println("T_FUNC_C")
<PHP>__LINE__ fmt.Println("T_LINE")
<PHP>__NAMESPACE__ fmt.Println("T_NS_C")
<PHP>__METHOD__ fmt.Println("T_METHOD_C")
<PHP>__TRAIT__ fmt.Println("T_TRAIT_C")
<PHP>\([ \t]*array[ \t]*\) fmt.Println("T_ARRAY_CAST")
<PHP>\([ \t]*(bool|boolean)[ \t]*\) fmt.Println("T_BOOL_CAST")
<PHP>\([ \t]*(real|double|float)[ \t]*\) fmt.Println("T_DOUBLE_CAST")
<PHP>\([ \t]*(int|integer)[ \t]*\) fmt.Println("T_INT_CAST")
<PHP>\([ \t]*object[ \t]*\) fmt.Println("T_OBJECT_CAST")
<PHP>\([ \t]*string[ \t]*\) fmt.Println("T_STRING_CAST")
<PHP>\([ \t]*unset[ \t]*\) fmt.Println("T_UNSET_CAST")
<PHP>new fmt.Println("T_NEW")
<PHP>and fmt.Println("T_LOGICAL_AND")
<PHP>or fmt.Println("T_LOGICAL_OR")
<PHP>xor fmt.Println("T_LOGICAL_XOR")
<PHP>\\ fmt.Println("T_NS_SEPARATOR")
<PHP>\.\.\. fmt.Println("T_ELLIPSIS");
<PHP>:: fmt.Println("T_PAAMAYIM_NEKUDOTAYIM"); // T_DOUBLE_COLON
<PHP>&& fmt.Println("T_BOOLEAN_AND")
<PHP>\|\| fmt.Println("T_BOOLEAN_OR")
<PHP>&= fmt.Println("T_AND_EQUAL")
<PHP>\|= fmt.Println("T_OR_EQUAL")
<PHP>\.= fmt.Println("T_CONCAT_EQUAL");
<PHP>\*= fmt.Println("T_MUL_EQUAL")
<PHP>\*\*= fmt.Println("T_POW_EQUAL")
<PHP>[/]= fmt.Println("T_DIV_EQUAL");
<PHP>\+= fmt.Println("T_PLUS_EQUAL")
<PHP>-= fmt.Println("T_MINUS_EQUAL")
<PHP>\^= fmt.Println("T_XOR_EQUAL")
<PHP>%= fmt.Println("T_MOD_EQUAL")
<PHP>-- fmt.Println("T_DEC");
<PHP>\+\+ fmt.Println("T_INC")
<PHP>=> fmt.Println("T_DOUBLE_ARROW");
<PHP>\<=\> fmt.Println("T_SPACESHIP")
<PHP>\!=|\<\> fmt.Println("T_IS_NOT_EQUAL")
<PHP>\!== fmt.Println("T_IS_NOT_IDENTICAL")
<PHP>== fmt.Println("T_IS_EQUAL")
<PHP>=== fmt.Println("T_IS_IDENTICAL")
<PHP>\<\<= fmt.Println("T_SL_EQUAL")
<PHP>\>\>= fmt.Println("T_SR_EQUAL")
<PHP>\>= fmt.Println("T_IS_GREATER_OR_EQUAL")
<PHP>\<= fmt.Println("T_IS_SMALLER_OR_EQUAL")
<PHP>\*\* fmt.Println("T_POW")
<PHP>\<\< fmt.Println("T_SL")
<PHP>\>\> fmt.Println("T_SR")
<PHP>(#|[/][/])[^\n]+ fmt.Println("T_COMMENT"); // TODO: handle \r\n and allow ?>
<PHP>'[^']*(\\')*' fmt.Println("T_CONSTANT_ENCAPSED_STRING")
<PHP>{OPERATORS} fmt.Printf("%s\n", l.TokenBytes(nil));
<PHP>\} fmt.Println("}"); popState();
<PHP>\${VAR_NAME} fmt.Printf("T_VARIABLE: %q\n", l.TokenBytes(nil))
<PHP>-> fmt.Println("T_OBJECT_OPERATOR");begin(PROPERTY)
<PROPERTY>[ \t\n\r]+ fmt.Println("T_WHITESPACE");
<PROPERTY>-> fmt.Println("T_OBJECT_OPERATOR");
<PROPERTY>{VAR_NAME} fmt.Println("T_STRING");begin(PHP)
<PROPERTY>. l.ungetN(1);begin(PHP)
<PHP>[\']([^\\\']*([\\][\'])*)*[\'] fmt.Printf("T_CONSTANT_ENCAPSED_STRING: %s\n", l.TokenBytes(nil));
<PHP>[b]?[\"]
binPrefix := l.TokenBytes(nil)[0] == 'b'
@ -245,7 +364,7 @@ OPERATORS [;:,.\[\]()|\/\^&\+-*=%!~$<>?@]
<STRING_VAR>\[ fmt.Println("["); begin(STRING_VAR_INDEX)
<STRING_VAR>. l.ungetN(1);begin(STRING)
<STRING_VAR_INDEX>{D} fmt.Printf("T_NUM_STRING: %q\n", l.TokenBytes(nil));
<STRING_VAR_INDEX>{LNUM} fmt.Printf("T_NUM_STRING: %q\n", l.TokenBytes(nil));
<STRING_VAR_INDEX>\${VAR_NAME} fmt.Printf("T_VARIABLE: %q\n", l.TokenBytes(nil));
<STRING_VAR_INDEX>{VAR_NAME} fmt.Printf("T_STRING: %q\n", l.TokenBytes(nil));
<STRING_VAR_INDEX>\] fmt.Println("\"]\""); begin(STRING)
@ -256,8 +375,6 @@ OPERATORS [;:,.\[\]()|\/\^&\+-*=%!~$<>?@]
<STRING_VAR_NAME>{VAR_NAME}[\[\}] fmt.Printf("T_STRING_VARNAME: %q\n", l.ungetN(1));popState();pushState(PHP)
<STRING_VAR_NAME>. l.ungetN(1);popState();pushState(PHP)
<PHP>\} fmt.Println("}"); popState();
<PHP>\${VAR_NAME} fmt.Printf("T_VARIABLE: %q\n", l.TokenBytes(nil))
<PHP>. fmt.Printf("other: %q\n", l.TokenBytes(nil))
%%