Changeset View
Changeset View
Standalone View
Standalone View
support/xhpast/parser.y
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | static void replacestr(string &source, const string &find, const string &rep) { | ||||
| while ((j = source.find(find)) != std::string::npos) { | while ((j = source.find(find)) != std::string::npos) { | ||||
| source.replace(j, find.length(), rep); | source.replace(j, find.length(), rep); | ||||
| } | } | ||||
| } | } | ||||
| */ | */ | ||||
| %} | %} | ||||
| %expect 12 | %expect 13 | ||||
| // 2: PHP's if/else grammar | // 2: PHP's if/else grammar | ||||
| // 7: expr '[' dim_offset ']' -- shift will default to first grammar | // 7: expr '[' dim_offset ']' -- shift will default to first grammar | ||||
| %name-prefix = "xhpast" | %name-prefix = "xhpast" | ||||
| %pure-parser | %pure-parser | ||||
| %parse-param { void* yyscanner } | %parse-param { void* yyscanner } | ||||
| %parse-param { xhpast::Node** root } | %parse-param { xhpast::Node** root } | ||||
| %lex-param { void* yyscanner } | %lex-param { void* yyscanner } | ||||
| %error-verbose | %error-verbose | ||||
| ▲ Show 20 Lines • Show All 1,374 Lines • ▼ Show 20 Lines | | variable '=' '&' T_NEW class_name_reference ctor_arguments { | ||||
| $4->appendChild($5); | $4->appendChild($5); | ||||
| $4->appendChild($6); | $4->appendChild($6); | ||||
| NTYPE($3, n_VARIABLE_REFERENCE); | NTYPE($3, n_VARIABLE_REFERENCE); | ||||
| $3->appendChild($4); | $3->appendChild($4); | ||||
| $$->appendChild($3); | $$->appendChild($3); | ||||
| } | } | ||||
| | T_NEW class_name_reference ctor_arguments { | |||||
| NTYPE($1, n_NEW); | |||||
| $1->appendChild($2); | |||||
| $1->appendChild($3); | |||||
| $$ = $1; | |||||
| } | |||||
| | T_CLONE expr { | | T_CLONE expr { | ||||
| $$ = NNEW(n_UNARY_PREFIX_EXPRESSION); | $$ = NNEW(n_UNARY_PREFIX_EXPRESSION); | ||||
| $$->appendChild(NTYPE($1, n_OPERATOR)); | $$->appendChild(NTYPE($1, n_OPERATOR)); | ||||
| $$->appendChild($2); | $$->appendChild($2); | ||||
| } | } | ||||
| | variable T_PLUS_EQUAL expr { | | variable T_PLUS_EQUAL expr { | ||||
| $$ = NNEW(n_BINARY_EXPRESSION); | $$ = NNEW(n_BINARY_EXPRESSION); | ||||
| $$->appendChild($1); | $$->appendChild($1); | ||||
| ▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | | expr T_IS_GREATER_OR_EQUAL expr { | ||||
| $$->appendChild($3); | $$->appendChild($3); | ||||
| } | } | ||||
| | expr T_INSTANCEOF class_name_reference { | | expr T_INSTANCEOF class_name_reference { | ||||
| $$ = NNEW(n_BINARY_EXPRESSION); | $$ = NNEW(n_BINARY_EXPRESSION); | ||||
| $$->appendChild($1); | $$->appendChild($1); | ||||
| $$->appendChild(NTYPE($2, n_OPERATOR)); | $$->appendChild(NTYPE($2, n_OPERATOR)); | ||||
| $$->appendChild($3); | $$->appendChild($3); | ||||
| } | } | ||||
| | '(' expr ')' { | | parenthesis_expr | ||||
| NSPAN($1, n_PARENTHETICAL_EXPRESSION, $3); | | new_expr | ||||
| $1->appendChild($2); | |||||
| $$ = $1; | |||||
| } | |||||
| | expr '?' expr ':' expr { | | expr '?' expr ':' expr { | ||||
| $$ = NNEW(n_TERNARY_EXPRESSION); | $$ = NNEW(n_TERNARY_EXPRESSION); | ||||
| $$->appendChild($1); | $$->appendChild($1); | ||||
| $$->appendChild($3); | $$->appendChild($3); | ||||
| $$->appendChild($5); | $$->appendChild($5); | ||||
| } | } | ||||
| | expr '?' ':' expr { | | expr '?' ':' expr { | ||||
| $$ = NNEW(n_TERNARY_EXPRESSION); | $$ = NNEW(n_TERNARY_EXPRESSION); | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | | T_EXIT exit_expr { | ||||
| $$->appendChild(NTYPE($1, n_OPERATOR)); | $$->appendChild(NTYPE($1, n_OPERATOR)); | ||||
| $$->appendChild($2); | $$->appendChild($2); | ||||
| } | } | ||||
| | '@' expr { | | '@' expr { | ||||
| $$ = NNEW(n_UNARY_PREFIX_EXPRESSION); | $$ = NNEW(n_UNARY_PREFIX_EXPRESSION); | ||||
| $$->appendChild(NTYPE($1, n_OPERATOR)); | $$->appendChild(NTYPE($1, n_OPERATOR)); | ||||
| $$->appendChild($2); | $$->appendChild($2); | ||||
| } | } | ||||
| | T_ARRAY '(' array_pair_list ')' { | |||||
| NTYPE($1, n_ARRAY_LITERAL); | |||||
| $1->appendChild($3); | |||||
| NMORE($1, $4); | |||||
| $$ = $1; | |||||
| } | |||||
| | '[' array_pair_list ']' { | |||||
| NTYPE($1, n_ARRAY_LITERAL); | |||||
| $1->appendChild($2); | |||||
| NMORE($1, $3); | |||||
| $$ = $1; | |||||
| } | |||||
| | T_BACKTICKS_EXPR { | | T_BACKTICKS_EXPR { | ||||
| NTYPE($1, n_BACKTICKS_EXPRESSION); | NTYPE($1, n_BACKTICKS_EXPRESSION); | ||||
| $$ = $1; | $$ = $1; | ||||
| } | } | ||||
| | scalar | | scalar | ||||
| | combined_scalar | |||||
| | T_PRINT expr { | | T_PRINT expr { | ||||
| $$ = NNEW(n_UNARY_PREFIX_EXPRESSION); | $$ = NNEW(n_UNARY_PREFIX_EXPRESSION); | ||||
| $$->appendChild(NTYPE($1, n_OPERATOR)); | $$->appendChild(NTYPE($1, n_OPERATOR)); | ||||
| $$->appendChild($2); | $$->appendChild($2); | ||||
| } | } | ||||
| | T_YIELD { | | T_YIELD { | ||||
| NTYPE($1, n_YIELD); | NTYPE($1, n_YIELD); | ||||
| $1->appendChild(NNEW(n_EMPTY)); | $1->appendChild(NNEW(n_EMPTY)); | ||||
| $1->appendChild(NNEW(n_EMPTY)); | $1->appendChild(NNEW(n_EMPTY)); | ||||
| $$ = $1; | $$ = $1; | ||||
| } | } | ||||
| | '(' yield_expr ')' { | |||||
| $$ = NEXPAND($1, $2, $3); | |||||
| } | |||||
| | function is_reference '(' parameter_list ')' lexical_vars '{' inner_statement_list '}' { | | function is_reference '(' parameter_list ')' lexical_vars '{' inner_statement_list '}' { | ||||
| NSPAN($1, n_FUNCTION_DECLARATION, $9); | NSPAN($1, n_FUNCTION_DECLARATION, $9); | ||||
| $1->appendChild(NNEW(n_EMPTY)); | $1->appendChild(NNEW(n_EMPTY)); | ||||
| $1->appendChild($2); | $1->appendChild($2); | ||||
| $1->appendChild(NNEW(n_EMPTY)); | $1->appendChild(NNEW(n_EMPTY)); | ||||
| $1->appendChild(NEXPAND($3, $4, $5)); | $1->appendChild(NEXPAND($3, $4, $5)); | ||||
| $$->appendChild($6); | $$->appendChild($6); | ||||
| $1->appendChild(NEXPAND($7, $8, $9)); | $1->appendChild(NEXPAND($7, $8, $9)); | ||||
| ▲ Show 20 Lines • Show All 474 Lines • ▼ Show 20 Lines | |||||
| base_variable_with_function_calls: | base_variable_with_function_calls: | ||||
| base_variable | base_variable | ||||
| | function_call | | function_call | ||||
| ; | ; | ||||
| base_variable: | base_variable: | ||||
| reference_variable | reference_variable | ||||
| | '(' new_expr ')' { | |||||
| $$ = NEXPAND($1, $2, $3); | |||||
epriestley: I think this should either look like the `parenthesis_expr` rule does, and generate a… | |||||
| } | |||||
| | simple_indirect_reference reference_variable { | | simple_indirect_reference reference_variable { | ||||
| xhpast::Node *last = $1; | xhpast::Node *last = $1; | ||||
| NMORE($1, $2); | NMORE($1, $2); | ||||
| while (last->firstChild() && | while (last->firstChild() && | ||||
| last->firstChild()->type == n_VARIABLE_VARIABLE) { | last->firstChild()->type == n_VARIABLE_VARIABLE) { | ||||
| NMORE(last, $2); | NMORE(last, $2); | ||||
| last = last->firstChild(); | last = last->firstChild(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| | variable_without_objects | | variable_without_objects | ||||
| ; | ; | ||||
| object_dim_list: | object_dim_list: | ||||
| object_dim_list '[' dim_offset ']' { | object_dim_list '[' dim_offset ']' { | ||||
| $$ = NNEW(n_INDEX_ACCESS); | $$ = NNEW(n_INDEX_ACCESS); | ||||
| $$->appendChild($1); | $$->appendChild($1); | ||||
| $$->appendChild($3); | $$->appendChild($3); | ||||
| NMORE($$, $4) | NMORE($$, $4); | ||||
| } | } | ||||
| | object_dim_list '{' expr '}' { | | object_dim_list '{' expr '}' { | ||||
| $$ = NNEW(n_INDEX_ACCESS); | $$ = NNEW(n_INDEX_ACCESS); | ||||
| $$->appendChild($1); | $$->appendChild($1); | ||||
| $$->appendChild($3); | $$->appendChild($3); | ||||
| NMORE($$, $4); | NMORE($$, $4); | ||||
| } | } | ||||
| | variable_name | | variable_name | ||||
| ▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | variable { | ||||
| $$ = NNEW(n_EMPTY); | $$ = NNEW(n_EMPTY); | ||||
| $$->appendChild($1); | $$->appendChild($1); | ||||
| } | } | ||||
| | isset_variables ',' variable { | | isset_variables ',' variable { | ||||
| $$ = $1->appendChild($3); | $$ = $1->appendChild($3); | ||||
| } | } | ||||
| ; | ; | ||||
| parenthesis_expr: | |||||
| '(' expr ')' { | |||||
| NSPAN($1, n_PARENTHETICAL_EXPRESSION, $3); | |||||
| $1->appendChild($2); | |||||
| $$ = $1; | |||||
| } | |||||
| | '(' yield_expr ')' { | |||||
| $$ = NEXPAND($1, $2, $3); | |||||
| } | |||||
| ; | |||||
| combined_scalar: | |||||
| T_ARRAY '(' array_pair_list ')' { | |||||
| NTYPE($1, n_ARRAY_LITERAL); | |||||
| $1->appendChild($3); | |||||
| NMORE($1, $4); | |||||
| $$ = $1; | |||||
| } | |||||
| | '[' array_pair_list ']' { | |||||
| NTYPE($1, n_ARRAY_LITERAL); | |||||
| $1->appendChild($2); | |||||
| NMORE($1, $3); | |||||
| $$ = $1; | |||||
| } | |||||
| ; | |||||
| new_expr: | |||||
| T_NEW class_name_reference ctor_arguments { | |||||
| NTYPE($1, n_NEW); | |||||
| $1->appendChild($2); | |||||
| $1->appendChild($3); | |||||
| $$ = $1; | |||||
| } | |||||
| ; | |||||
| class_constant: | class_constant: | ||||
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { | class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { | ||||
| $$ = NNEW(n_CLASS_STATIC_ACCESS); | $$ = NNEW(n_CLASS_STATIC_ACCESS); | ||||
| $$->appendChild($1); | $$->appendChild($1); | ||||
| $$->appendChild(NTYPE($3, n_STRING)); | $$->appendChild(NTYPE($3, n_STRING)); | ||||
| } | } | ||||
| | variable_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { | | variable_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { | ||||
| $$ = NNEW(n_CLASS_STATIC_ACCESS); | $$ = NNEW(n_CLASS_STATIC_ACCESS); | ||||
| Show All 31 Lines | |||||
I think this should either look like the parenthesis_expr rule does, and generate a n_PARENTHETICAL_EXPRESSION node, or look like the yield_expr rule does and do NEXPAND($1, $2, $3). Since the parens are required, maybe the NEXPAND is more consistent.