Changeset View
Changeset View
Standalone View
Standalone View
support/xhpast/scanner.l
Show All 17 Lines | if (yyextra->insert_token) { \ | ||||
yyg->yy_init = 0; \ | yyg->yy_init = 0; \ | ||||
int ft = yyextra->insert_token; \ | int ft = yyextra->insert_token; \ | ||||
yyextra->insert_token = 0; \ | yyextra->insert_token = 0; \ | ||||
return yy_token(ft, yyg); \ | return yy_token(ft, yyg); \ | ||||
} | } | ||||
using namespace std; | using namespace std; | ||||
const char* yytokname(int tok); | const char * yytokname(int tok); | ||||
static int yy_token(int tok, struct yyguts_t* yyg); | static int yy_token(int tok, struct yyguts_t * yyg); | ||||
static void yy_scan_newlines(const char* text, struct yyguts_t* yyg); | static void yy_scan_newlines(const char * text, struct yyguts_t * yyg); | ||||
%} | %} | ||||
%option prefix="xhpast" | %option prefix="xhpast" | ||||
%option reentrant | %option reentrant | ||||
/* PHP allows IF or if */ | /* PHP allows IF or if */ | ||||
%option case-insensitive | %option case-insensitive | ||||
%option noyywrap nodefault | %option noyywrap nodefault | ||||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | ||||
"=>" tok(T_DOUBLE_ARROW); | "=>" tok(T_DOUBLE_ARROW); | ||||
"::" 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|binary){TABS_AND_SPACES}")" tok(T_STRING_CAST); | "("{TABS_AND_SPACES}(string|binary){TABS_AND_SPACES}")" tok(T_STRING_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 | /* Scalars (parsing these doesn't really matter since we just pass them | ||||
Show All 9 Lines | <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>{ | ||||
} | } | ||||
`[^`]*` { | `[^`]*` { | ||||
yy_scan_newlines(yytext, yyg); | yy_scan_newlines(yytext, yyg); | ||||
tok(T_BACKTICKS_EXPR); | tok(T_BACKTICKS_EXPR); | ||||
} | } | ||||
} | } | ||||
/* (HERE|NOW)DOC's */ | /* (HERE|NOW)DOC's */ | ||||
<PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>b?"<<<"{TABS_AND_SPACES} { | <PHP,PHP_NO_RESERVED_WORDS,PHP_NO_RESERVED_WORDS_PERSIST>b?"<<<" | ||||
{TABS_AND_SPACES} { | |||||
push_state(PHP_HEREDOC_START); | push_state(PHP_HEREDOC_START); | ||||
yyextra->heredoc_yyleng = yyleng; | yyextra->heredoc_yyleng = yyleng; | ||||
yymore(); | yymore(); | ||||
} | } | ||||
<PHP_HEREDOC_START>{ | <PHP_HEREDOC_START>{ | ||||
"'"{LABEL}"'"|\"{LABEL}\" { | "'"{LABEL}"'"|\"{LABEL}\" { | ||||
// Create a new string for the heredoc label. Since we're using yymore above | // Create a new string for the heredoc label. Since we're using yymore above | ||||
// yytext will actually start at the "<<<" and not the label. Use of | // yytext will actually start at the "<<<" and not the label. Use of | ||||
Show All 20 Lines | |||||
} | } | ||||
<PHP_HEREDOC_NEWLINE>{ | <PHP_HEREDOC_NEWLINE>{ | ||||
{LABEL};?{NEWLINE} { | {LABEL};?{NEWLINE} { | ||||
if (strncmp( | if (strncmp( | ||||
yyextra->heredoc_label.c_str(), | yyextra->heredoc_label.c_str(), | ||||
yytext + yyextra->heredoc_yyleng, yyextra->heredoc_label.size()) == 0) { | 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( | yyless( | ||||
yyleng - ( | yyleng - ( | ||||
yyleng - | yyleng - | ||||
yyextra->heredoc_yyleng - | yyextra->heredoc_yyleng - | ||||
yyextra->heredoc_label.size())); | yyextra->heredoc_label.size())); | ||||
pop_state(); | pop_state(); | ||||
tok(T_HEREDOC); | tok(T_HEREDOC); | ||||
} | } | ||||
Show All 19 Lines | <*>{BYTE} { | ||||
// fix unused function warnings | // fix unused function warnings | ||||
yy_top_state(NULL); | yy_top_state(NULL); | ||||
yyunput(0, 0, NULL); | yyunput(0, 0, NULL); | ||||
} | } | ||||
%% | %% | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
static const char* yy_state_name(int state) { | static const char * yy_state_name(int state) { | ||||
switch (state) { | switch (state) { | ||||
case INITIAL: | case INITIAL: | ||||
return "INITIAL"; | return "INITIAL"; | ||||
case PHP: | case PHP: | ||||
return "PHP"; | return "PHP"; | ||||
case PHP_COMMENT: | case PHP_COMMENT: | ||||
return "PHP_COMMENT"; | return "PHP_COMMENT"; | ||||
case PHP_EOL_COMMENT: | case PHP_EOL_COMMENT: | ||||
Show All 11 Lines | switch (state) { | ||||
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 "???"; | ||||
} | } | ||||
} | } | ||||
static void yy_log_token(int tok) { | static void yy_log_token(int tok) { | ||||
const char* tokname = yytokname(tok); | const char * tokname = yytokname(tok); | ||||
if (tokname) { | if (tokname) { | ||||
fprintf(stderr, "--> %s\n", tokname); | fprintf(stderr, "--> %s\n", tokname); | ||||
} else { | } else { | ||||
fprintf(stderr, "--> '%c'\n", tok); | fprintf(stderr, "--> '%c'\n", tok); | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
Show All 35 Lines | case '{': | ||||
break; | break; | ||||
} | } | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
yy_log_token(tok); | yy_log_token(tok); | ||||
#endif | #endif | ||||
return yyextra->last_token = tok; | return yyextra->last_token = tok; | ||||
} | } | ||||
static inline void yy_scan_newlines(const char* text, struct yyguts_t* yyg) { | static inline void yy_scan_newlines(const char * text, struct yyguts_t * yyg) { | ||||
for (; *text; ++text) { | for (; *text; ++text) { | ||||
if (*text == '\r') { | if (*text == '\r') { | ||||
if (text[1] == '\n') { | if (text[1] == '\n') { | ||||
++text; | ++text; | ||||
} | } | ||||
++yyextra->lineno; | ++yyextra->lineno; | ||||
} else if (*text == '\n') { | } else if (*text == '\n') { | ||||
++yyextra->lineno; | ++yyextra->lineno; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void xhp_new_push_state(int s, struct yyguts_t* yyg) { | void xhp_new_push_state(int s, struct yyguts_t * yyg) { | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
fprintf( | fprintf( | ||||
stderr, | stderr, | ||||
"--> PUSH(%s -> %s)\n", | "--> PUSH(%s -> %s)\n", | ||||
yy_state_name(YY_START), | yy_state_name(YY_START), | ||||
yy_state_name(s)); | yy_state_name(s)); | ||||
#endif | #endif | ||||
yy_push_state(s, yyg); | yy_push_state(s, yyg); | ||||
} | } | ||||
void xhp_new_pop_state(struct yyguts_t* yyg) { | void xhp_new_pop_state(struct yyguts_t * yyg) { | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
int s = YY_START; | int s = YY_START; | ||||
#endif | #endif | ||||
yy_pop_state(yyg); | yy_pop_state(yyg); | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
fprintf( | fprintf( | ||||
stderr, | stderr, | ||||
"--> POP(%s -> %s)\n", | "--> POP(%s -> %s)\n", | ||||
yy_state_name(s), | yy_state_name(s), | ||||
yy_state_name(YY_START)); | yy_state_name(YY_START)); | ||||
#endif | #endif | ||||
} | } | ||||
void xhp_set_state(int s, struct yyguts_t* yyg) { | void xhp_set_state(int s, struct yyguts_t * yyg) { | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
fprintf(stderr, "--> SET(%s)\n", yy_state_name(s)); | fprintf(stderr, "--> SET(%s)\n", yy_state_name(s)); | ||||
#endif | #endif | ||||
BEGIN(s); | BEGIN(s); | ||||
} | } |