[PATCH] Add support for PHP5 and 7 to built-in parser

Fabian Wiget <[email protected]>
Newsgroups gmane.comp.gnu.global.bugs
Message-ID <CABBhTm-i1iC4YLzfZjWdu++gAVCmURvhbtVjRnOvqN_ur8duQQ@mail.gmail.com>
Hi everybody

I updated the built-in PHP parser to support namespaces and traits, which
were introduced in PHP5. The following keywords have been removed:

- failure: not a keyword
- header: normal built-in function
- is_array: normal built-in function
- is_set: typo -> isset
- printf: normal built-in function
- setcookie: normal built-in function
- success: not a keyword

The parser should now support PHP4, PHP5 and PHP7.

Thank you & best regards
fabian

_______________________________________________
Bug-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-global
php_parser.patch (application/octet-stream, 3.4 KB)
diff --git a/libparser/php.l b/libparser/php.l
index 410f1e5..fe9bfd7 100644
--- a/libparser/php.l
+++ b/libparser/php.l
@@ -305,6 +305,8 @@ php(const struct parser_param *param)
 			PUT(PARSER_DEF, strbuf_value(string), LEXLINENO);
 			break;
 		case PHP_CLASS:
+		case PHP_INTERFACE:
+		case PHP_TRAIT:
 			if (LEXLEX(param) != PHP_TOKEN)
 				break;
 			PUT(PARSER_DEF, LEXTEXT, LEXLINENO);
diff --git a/libparser/php_res.in b/libparser/php_res.in
index 5f8bd75..28e8dfc 100644
--- a/libparser/php_res.in
+++ b/libparser/php_res.in
@@ -13,24 +13,32 @@
 ;
 ; PHP reserved word list.
 ;
+__CLASS__		word
+__DIR__			word
 __FILE__		word
-__LINE__		word
 __FUNCTION__		word
-__CLASS__		word
+__LINE__		word
+__METHOD__		word
+__NAMESPACE__		word
+__TRAIT__		word
+abstract,ABSTRACT,Abstract				word
 and,AND,And						word
 array,ARRAY,Array					word
 as,AS,As						word
 break,BREAK,Break					word
+callable,CALLABLE,Callable				word
 case,CASE,Case						word
+catch,CATCH,Catch					word
 cfunction,CFUNCTION,Cfunction,CFunction			word
 class,CLASS,Class					word
+clone,CLONE,Clone					word
 const,CONST,Const					word
 continue,CONTINUE,Continue				word
 declare,DECLARE,Declare					word
 default,DEFAULT,Default					word
 define,DEFINE,Define					word
-do,DO,Do						word
 die,DIE,Die						word
+do,DO,Do						word
 each,EACH,Each						word
 echo,ECHO,Echo						word
 else,ELSE,Else						word
@@ -40,40 +48,51 @@ enddeclare,ENDDECLARE,Enddeclare,EndDeclare		word
 endfor,ENDFOR,Endfor,EndFor				word
 endforeach,ENDFOREACH,Endforeach,EndForeach		word
 endif,ENDIF,Endif,EndIf					word
-endwhile,ENDWHILE,Endwhile,EndWhile			word
 endswitch,ENDSWITCH,Endswitch,EndSwitch			word
+endwhile,ENDWHILE,Endwhile,EndWhile			word
 eval,EVAL,Eval						word
 exit,EXIT,Exit						word
-failure,FAILURE,Failure					word
+extends,EXTENDS,Extends					word
 false,FALSE,False					word
+final,FINAL,Final					word
+finally,FINALLY,Finally					word
 for,FOR,For						word
 foreach,FOREACH,Foreach,ForEach				word
 function,FUNCTION,Function				word
 global,GLOBAL,Global					word
-header,HEADER,Header					word
-list,LIST,List						word
+goto,GOTO,Goto						word
 if,IF,If						word
+implements,IMPLEMENTS,Implements			word
 include,INCLUDE,Include					word
 include_once,INCLUDE_ONCE,Include_once,Include_Once	word
-is_array,IS_ARRAY,Is_array,Is_Array			word
-is_set,IS_SET,Is_set,Is_Set				word
+instanceof,INSTANCEOF,Instanceof,InstanceOf		word
+insteadof,INSTEADOF,Insteadof,InsteadOf			word
+interface,INTERFACE,Interface				word
+isset,ISSET,Isset					word
+list,LIST,List						word
+namespace,NAMESPACE,Namespace				word
 new,NEW,New						word
 old_function,OLD_FUNCTION,Old_function,Old_Function	word
 or,OR,Or						word
 print,PRINT,Print					word
-printf,PRINTF,Printf					word
-return,RETURN,Return					word
+private,PRIVATE,Private					word
+protected,PROTECTED,Protected				word
+public,PUBLIC,Public					word
 require,REQUIRE,Require					word
 require_once,REQUIRE_ONCE,Require_once,Require_Once	word
-setcookie,SETCOOKIE,Setcookie,SetCookie			word
-success,SUCCESS,Success					word
+return,RETURN,Return					word
 static,STATIC,Static					word
 switch,SWITCH,Switch					word
+throw,THROW,Throw					word
+trait,TRAIT,Trait					word
+try,TRY,Try						word
 true,TRUE,True						word
+unset,UNSET,Unset					word
+use,USE,Use						word
 var,VAR,Var						word
 while,WHILE,While					word
-unset,UNSET,Unset					word
 xor,XOR,Xor						word
+yield,YIELD,Yield					word
 
 ;
 ; PHP reserved variable list.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.