diff --git a/ext.cpp b/ext.cpp index dbe20a5f..42e2db81 100644 --- a/ext.cpp +++ b/ext.cpp @@ -95,7 +95,14 @@ static zend_op_array* xhp_compile_file(zend_file_handle* f, int type TSRMLS_DC) maybe_xhp = 1; break; } - } else if (*ii == '/' && ii[1] == '>') { // + } else if (*ii == '/') { // + if (ii[1] == '>') { + maybe_xhp = 1; + break; + } + } else if (*ii == 'e' && ii[1] == 'l' && ii[2] == 'e' && ii[3] == 'm' && ii[4] == 'e' && ii[5] == 'n' && ii[6] == 't') { +// } else if (memcmp(ii, "element", 7)) { + // why is this faster than memcmp? i'm bad at computers and i don't know. maybe_xhp = 1; break; } diff --git a/xhp_parser.y b/xhp_parser.y index d5695c49..14048df1 100644 --- a/xhp_parser.y +++ b/xhp_parser.y @@ -971,8 +971,17 @@ xhp_whitespace_hack: // element declarations xhp_element_declaration: - t_ELEMENT { yy_push_state(PHP_NO_RESERVED_WORDS); } xhp_label xhp_whitespace_hack xhp_element_extends xhp_element_implements t_LCURLY class_statement_list t_RCURLY { - $$ = cr("class xhp_") + $3 + " " + $5 + " " + $6 + "{" + $8 + cr("}"); + xhp_element_entry { yy_push_state(PHP_NO_RESERVED_WORDS); } xhp_label xhp_whitespace_hack xhp_element_extends xhp_element_implements t_LCURLY class_statement_list t_RCURLY { + $$ = $1 + $3 + " " + $5 + " " + $6 + "{" + $8 + cr("}"); + } +; + +xhp_element_entry: + t_ELEMENT { + $$ = cr("class xhp_"); + } +| t_ABSTRACT t_ELEMENT { + $$ = cr("abstract class xhp_"); } ; diff --git a/xhp_scanner.l b/xhp_scanner.l index d87f4393..b9cf9590 100644 --- a/xhp_scanner.l +++ b/xhp_scanner.l @@ -314,8 +314,8 @@ B b? return tok(t_HEREDOC); } else { ++yylloc->actual_line_offset; + yyextra->heredoc_data_last = yytext + yyleng; yymore(); - BEGIN(HEREDOC_DATA); } } [^\r\n]+ { @@ -324,8 +324,8 @@ B b? } {NEWLINE} { ++yylloc->actual_line_offset; + yyextra->heredoc_data_last = yytext + yyleng; yymore(); - BEGIN(HEREDOC_LINE_START); } } { @@ -348,7 +348,7 @@ B b? ">" return tok(t_XHP_GREATER_THAN); } { - " " { + {WHITESPACE} { flex_pop_state(yyg); return tok(t_XHP_WHITESPACE); }