Changeset View
Changeset View
Standalone View
Standalone View
support/xhpast/scanner.l
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | /* The different lexing states. Note that the transitions are done either | ||||
| * in the lex actions, or in a generic manner in yy_token(). */ | * in the lex actions, or in a generic manner in yy_token(). */ | ||||
| %s PHP | %s PHP | ||||
| %s PHP_COMMENT | %s PHP_COMMENT | ||||
| %s PHP_EOL_COMMENT | %s PHP_EOL_COMMENT | ||||
| %s PHP_DOC_COMMENT | %s PHP_DOC_COMMENT | ||||
| %s PHP_HEREDOC_START | %s PHP_HEREDOC_START | ||||
| %s PHP_HEREDOC_NSTART | %s PHP_HEREDOC_NSTART | ||||
| %s PHP_HEREDOC_NEWLINE | %s PHP_HEREDOC_NEWLINE | ||||
| %s PHP_HEREDOC_DATA | |||||
| %s PHP_NO_RESERVED_WORDS | %s PHP_NO_RESERVED_WORDS | ||||
| %s PHP_NO_RESERVED_WORDS_PERSIST | %s PHP_NO_RESERVED_WORDS_PERSIST | ||||
| %s PHP_ | %s PHP_ | ||||
| LNUM [0-9]+ | LNUM [0-9]+ | ||||
| DNUM ([0-9]*"."[0-9]+)|([0-9]+"."[0-9]*) | DNUM ([0-9]*"."[0-9]+)|([0-9]+"."[0-9]*) | ||||
| EXPONENT_DNUM (({LNUM}|{DNUM})[eE][+-]?{LNUM}) | EXPONENT_DNUM (({LNUM}|{DNUM})[eE][+-]?{LNUM}) | ||||
| HNUM "0x"[0-9a-fA-F]+ | HNUM "0x"[0-9a-fA-F]+ | ||||
| BNUM "0b"[01]+ | |||||
| LABEL [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* | LABEL [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* | ||||
| BYTE (.|\n) | BYTE (.|\n) | ||||
| WHITESPACE [ \n\r\t]+ | WHITESPACE [ \n\r\t]+ | ||||
| TABS_AND_SPACES [ \t]* | TABS_AND_SPACES [ \t]* | ||||
| NEWLINE ("\r\n"|"\n"|"\r") | NEWLINE ("\r\n"|"\n"|"\r") | ||||
| ▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | <PHP>{ | ||||
| __class__ tok(T_CLASS_C); | __class__ tok(T_CLASS_C); | ||||
| __method__ tok(T_METHOD_C); | __method__ tok(T_METHOD_C); | ||||
| __function__ tok(T_FUNC_C); | __function__ tok(T_FUNC_C); | ||||
| __line__ tok(T_LINE); | __line__ tok(T_LINE); | ||||
| __file__ tok(T_FILE); | __file__ tok(T_FILE); | ||||
| namespace tok(T_NAMESPACE); | namespace tok(T_NAMESPACE); | ||||
| __namespace__ tok(T_NS_C); | __namespace__ tok(T_NS_C); | ||||
| __dir__ tok(T_DIR); | __dir__ tok(T_DIR); | ||||
| insteadof tok(T_INSTEADOF); | |||||
| callable tok(T_CALLABLE); | |||||
| trait tok(T_TRAIT); | |||||
| __trait__ tok(T_TRAIT_C); | |||||
| yield tok(T_YIELD); | |||||
| } | } | ||||
| /* Operators */ | /* Operators */ | ||||
| <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | ||||
| "+=" tok(T_PLUS_EQUAL); | "+=" tok(T_PLUS_EQUAL); | ||||
| "-=" tok(T_MINUS_EQUAL); | "-=" tok(T_MINUS_EQUAL); | ||||
| "*=" tok(T_MUL_EQUAL); | "*=" tok(T_MUL_EQUAL); | ||||
| "/=" tok(T_DIV_EQUAL); | "/=" tok(T_DIV_EQUAL); | ||||
| Show All 21 Lines | <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | ||||
| "::" tok(T_PAAMAYIM_NEKUDOTAYIM); | "::" tok(T_PAAMAYIM_NEKUDOTAYIM); | ||||
| "\\" tok(T_NS_SEPARATOR); | "\\" tok(T_NS_SEPARATOR); | ||||
| } | } | ||||
| /* Casts */ | /* Casts */ | ||||
| <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | ||||
| "("{TABS_AND_SPACES}(int|integer){TABS_AND_SPACES}")" tok(T_INT_CAST); | "("{TABS_AND_SPACES}(int|integer){TABS_AND_SPACES}")" tok(T_INT_CAST); | ||||
| "("{TABS_AND_SPACES}(real|double|float){TABS_AND_SPACES}")" tok(T_DOUBLE_CAST); | "("{TABS_AND_SPACES}(real|double|float){TABS_AND_SPACES}")" tok(T_DOUBLE_CAST); | ||||
| "("{TABS_AND_SPACES}string{TABS_AND_SPACES}")" tok(T_STRING_CAST); | "("{TABS_AND_SPACES}(string|binary){TABS_AND_SPACES}")" tok(T_STRING_CAST); | ||||
| "("{TABS_AND_SPACES}unicode{TABS_AND_SPACES}")" tok(T_UNICODE_CAST); | |||||
| "("{TABS_AND_SPACES}binary{TABS_AND_SPACES}")" tok(T_BINARY_CAST); | |||||
| "("{TABS_AND_SPACES}array{TABS_AND_SPACES}")" tok(T_ARRAY_CAST); | "("{TABS_AND_SPACES}array{TABS_AND_SPACES}")" tok(T_ARRAY_CAST); | ||||
| "("{TABS_AND_SPACES}object{TABS_AND_SPACES}")" tok(T_OBJECT_CAST); | "("{TABS_AND_SPACES}object{TABS_AND_SPACES}")" tok(T_OBJECT_CAST); | ||||
| "("{TABS_AND_SPACES}(bool|boolean){TABS_AND_SPACES}")" tok(T_BOOL_CAST); | "("{TABS_AND_SPACES}(bool|boolean){TABS_AND_SPACES}")" tok(T_BOOL_CAST); | ||||
| "("{TABS_AND_SPACES}unset{TABS_AND_SPACES}")" tok(T_UNSET_CAST); | "("{TABS_AND_SPACES}unset{TABS_AND_SPACES}")" tok(T_UNSET_CAST); | ||||
| } | } | ||||
| /* Scalars (parsing these doesn't really matter since we just pass them through literally) */ | /* Scalars (parsing these doesn't really matter since we just pass them through literally) */ | ||||
| <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | ||||
| {LNUM}|{HNUM} tok(T_LNUMBER); | {LNUM}|{HNUM}|{BNUM} tok(T_LNUMBER); | ||||
| {DNUM}|{EXPONENT_DNUM} tok(T_DNUMBER); | {DNUM}|{EXPONENT_DNUM} tok(T_DNUMBER); | ||||
| {LABEL} tok(T_STRING); | {LABEL} tok(T_STRING); | ||||
| "$"{LABEL} tok(T_VARIABLE); | "$"{LABEL} tok(T_VARIABLE); | ||||
| b?'(\\.|\\\n|[^\\']+)*'|b?\"(\\.|\\\n|[^\\\"]+)*\" { | b?'(\\.|\\\n|[^\\']+)*'|b?\"(\\.|\\\n|[^\\\"]+)*\" { | ||||
| yy_scan_newlines(yytext, yyg); | yy_scan_newlines(yytext, yyg); | ||||
| tok(T_CONSTANT_ENCAPSED_STRING); | tok(T_CONSTANT_ENCAPSED_STRING); | ||||
| } | } | ||||
| `[^`]*` { | `[^`]*` { | ||||
| Show All 22 Lines | <PHP_HEREDOC_START>{ | ||||
| {LABEL} { | {LABEL} { | ||||
| yyextra->heredoc_label = string(yytext + yyextra->heredoc_yyleng); | yyextra->heredoc_label = string(yytext + yyextra->heredoc_yyleng); | ||||
| set_state(PHP_HEREDOC_NSTART); | set_state(PHP_HEREDOC_NSTART); | ||||
| yyextra->heredoc_yyleng = yyleng; | yyextra->heredoc_yyleng = yyleng; | ||||
| yymore(); | yymore(); | ||||
| } | } | ||||
| } | } | ||||
| <PHP_HEREDOC_NSTART>{NEWLINE} { | <PHP_HEREDOC_NSTART>{NEWLINE} { | ||||
| ++yyextra->lineno; | |||||
| yyextra->heredoc_data = yytext + yyleng; | |||||
| set_state(PHP_HEREDOC_DATA); | |||||
| yymore(); | |||||
| } | |||||
| <PHP_HEREDOC_DATA>{ | |||||
| [^\r\n]*{NEWLINE} { | |||||
| ++yyextra->lineno; | |||||
| set_state(PHP_HEREDOC_NEWLINE); | |||||
| yyextra->heredoc_yyleng = yyleng; | yyextra->heredoc_yyleng = yyleng; | ||||
| set_state(PHP_HEREDOC_NEWLINE); | |||||
| yymore(); | yymore(); | ||||
| } | } | ||||
| } | |||||
| <PHP_HEREDOC_NEWLINE>{ | <PHP_HEREDOC_NEWLINE>{ | ||||
| {LABEL};?{NEWLINE} { | {LABEL};?{NEWLINE} { | ||||
| if (strncmp(yyextra->heredoc_label.c_str(), yytext + yyextra->heredoc_yyleng, yyextra->heredoc_label.size()) == 0) { | if (strncmp(yyextra->heredoc_label.c_str(), yytext + yyextra->heredoc_yyleng, yyextra->heredoc_label.size()) == 0) { | ||||
| switch (yytext[yyextra->heredoc_yyleng + yyextra->heredoc_label.size()]) { | switch (yytext[yyextra->heredoc_yyleng + yyextra->heredoc_label.size()]) { | ||||
| case ';': case '\n': case '\r': | case ';': case '\n': case '\r': | ||||
| yyless(yyleng - (yyleng - yyextra->heredoc_yyleng - yyextra->heredoc_label.size())); | yyless(yyleng - (yyleng - yyextra->heredoc_yyleng - yyextra->heredoc_label.size())); | ||||
| pop_state(); | pop_state(); | ||||
| tok(T_HEREDOC); | tok(T_HEREDOC); | ||||
| } | } | ||||
| } | } | ||||
| ++yyextra->lineno; | ++yyextra->lineno; | ||||
| yyextra->heredoc_yyleng = yyleng; | yyextra->heredoc_yyleng = yyleng; | ||||
| yymore(); | yymore(); | ||||
| } | } | ||||
| [^\r\n]+ { | [^\r\n]+ { | ||||
| set_state(PHP_HEREDOC_DATA); | |||||
| yyextra->heredoc_yyleng = yyleng; | yyextra->heredoc_yyleng = yyleng; | ||||
| yymore(); | yymore(); | ||||
| } | } | ||||
| {NEWLINE} { | {NEWLINE} { | ||||
| ++yyextra->lineno; | ++yyextra->lineno; | ||||
| yyextra->heredoc_yyleng = yyleng; | yyextra->heredoc_yyleng = yyleng; | ||||
| yymore(); | yymore(); | ||||
| } | } | ||||
| Show All 23 Lines | switch (state) { | ||||
| case PHP_DOC_COMMENT: | case PHP_DOC_COMMENT: | ||||
| return "PHP_DOC_COMMENT"; | return "PHP_DOC_COMMENT"; | ||||
| case PHP_HEREDOC_START: | case PHP_HEREDOC_START: | ||||
| return "PHP_HEREDOC_START"; | return "PHP_HEREDOC_START"; | ||||
| case PHP_HEREDOC_NSTART: | case PHP_HEREDOC_NSTART: | ||||
| return "PHP_HEREDOC_NSTART"; | return "PHP_HEREDOC_NSTART"; | ||||
| case PHP_HEREDOC_NEWLINE: | case PHP_HEREDOC_NEWLINE: | ||||
| return "PHP_HEREDOC_NEWLINE"; | return "PHP_HEREDOC_NEWLINE"; | ||||
| case PHP_HEREDOC_DATA: | |||||
| return "PHP_HEREDOC_DATA"; | |||||
| case PHP_NO_RESERVED_WORDS: | case PHP_NO_RESERVED_WORDS: | ||||
| return "PHP_NO_RESERVED_WORDS"; | return "PHP_NO_RESERVED_WORDS"; | ||||
| case PHP_NO_RESERVED_WORDS_PERSIST: | case PHP_NO_RESERVED_WORDS_PERSIST: | ||||
| return "PHP_NO_RESERVED_WORDS_PERSIST"; | return "PHP_NO_RESERVED_WORDS_PERSIST"; | ||||
| default: | default: | ||||
| return "???"; | return "???"; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines | |||||