diff --git a/php/PhpParser.g4 b/php/PhpParser.g4 index 6530645bda..5fc682d95a 100644 --- a/php/PhpParser.g4 +++ b/php/PhpParser.g4 @@ -501,20 +501,20 @@ expression | Exit ( '(' ')' | parentheses)? # SpecialWordExpression | lambdaFunctionExpr # LambdaFunctionExpression | matchExpr # MatchExpression - | expression op = '**' expression # ArithmeticExpression + | expression op = '**' expression # ExponentiationExpression | expression InstanceOf typeRef # InstanceOfExpression - | expression op = ('*' | Divide | '%') expression # ArithmeticExpression - | expression op = ('+' | '-' | '.') expression # ArithmeticExpression - | expression op = ('<<' | '>>') expression # ComparisonExpression - | expression op = (Less | '<=' | Greater | '>=') expression # ComparisonExpression - | expression op = ('===' | '!==' | '==' | IsNotEq) expression # ComparisonExpression - | expression op = '&' expression # BitwiseExpression - | expression op = '^' expression # BitwiseExpression - | expression op = '|' expression # BitwiseExpression - | expression op = '&&' expression # BitwiseExpression - | expression op = '||' expression # BitwiseExpression + | expression op = ('*' | Divide | '%') expression # MultiplicativeExpression + | expression op = ('+' | '-' | '.') expression # AdditiveExpression + | expression op = ('<<' | '>>') expression # ShiftExpression + | expression op = (Less | '<=' | Greater | '>=') expression # RelationalExpression + | expression op = ('===' | '!==' | '==' | IsNotEq) expression # EqualityExpression + | expression op = '&' expression # BitwiseAndExpression + | expression op = '^' expression # BitwiseExcOrExpression + | expression op = '|' expression # BitwiseIncOrExpression + | expression op = '&&' expression # LogicalAndExpression + | expression op = '||' expression # LogicalIncOrExpression | expression op = QuestionMark expression? ':' expression # ConditionalExpression - | expression op = '??' expression # NullCoalescingExpression + | expression op = '??' expression # CoalesceExpression | expression op = '<=>' expression # SpaceshipExpression | (Include | IncludeOnce) expression # IncludeExpression | (Require | RequireOnce) expression # RequireExpression @@ -522,9 +522,9 @@ expression | arrayDestructuring Eq expression # ArrayDestructExpression | assignable assignmentOperator attributes? expression # AssignmentExpression | assignable Eq attributes? '&' (chain | newExpr) # AssignmentExpression - | expression op = LogicalAnd expression # LogicalExpression - | expression op = LogicalXor expression # LogicalExpression - | expression op = LogicalOr expression # LogicalExpression + | expression op = LogicalAnd expression # LogicalAndExpression + | expression op = LogicalXor expression # LogicalExcOrExpression + | expression op = LogicalOr expression # LogicalIncOrExpression ; assignable @@ -930,25 +930,6 @@ magicConstant | Dir__ ; -magicMethod - : Get - | Set - | Call - | CallStatic - | Constructor - | Destruct - | Wakeup - | Sleep - | Autoload - | IsSet__ - | Unset__ - | ToString__ - | Invoke - | SetState - | Clone__ - | DebugInfo - ; - primitiveType : BoolType | IntType diff --git a/php/Python/PhpLexerBase.py b/php/Python/PhpLexerBase.py deleted file mode 100644 index d59df9b2a3..0000000000 --- a/php/Python/PhpLexerBase.py +++ /dev/null @@ -1,131 +0,0 @@ -""" -PHP grammar. -The MIT License (MIT). -Copyright (c) 2015-2017, Ivan Kochurkin (kvanttt@gmail.com), Positive Technologies. -Copyright (c) 2016, Jorrit Kronjee (Python port) -Copyright (c) 2019, Thierry Marianne (thierry.marianne@weaving-the-web.org) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -""" - -from antlr4 import * -from antlr4.Token import CommonToken - - -class PhpLexerBase(Lexer): - AspTags = True - _scriptTag = False - _styleTag = False - _heredocIdentifier = None - _prevTokenType = 0 - _htmlNameText = None - _phpScript = False - _insideString = False - - def nextToken(self): - token = super(PhpLexerBase, self).nextToken() - - if token.type == self.PHPEnd or token.type == self.PHPEndSingleLineComment: - if self._mode == self.SingleLineCommentMode: - # SingleLineCommentMode for such allowed syntax: - # // - self.popMode() - self.popMode() - - if token.text == "": - self._phpScript = False - token.type = self.HtmlScriptClose - else: - # Add semicolon to the end of statement if it is absent. - # For example: - if self._prevTokenType == self.SemiColon or \ - self._prevTokenType == self.Colon or \ - self._prevTokenType == self.OpenCurlyBracket or \ - self._prevTokenType == self.CloseCurlyBracket: - token = super(PhpLexerBase, self).nextToken() - else: - token = CommonToken(type=self.SemiColon) - token.text = ';' - elif token.type == self.HtmlName: - self._htmlNameText = token.text - elif token.type == self.HtmlDoubleQuoteString: - if token.text == "php" and self._htmlNameText == "language": - self._phpScript = True - elif self._mode == self.HereDoc: - # Heredoc and Nowdoc syntax support: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc - if token.type == self.StartHereDoc or token.type == self.StartNowDoc: - self._heredocIdentifier = token.text[3:].strip().replace("'", "") - if token.type == self.HereDocText: - if self.CheckHeredocEnd(token.text): - self.popMode() - heredoc_identifier = self.GetHeredocEnd(token.text) - if token.text.strip().endswith(';'): - text = heredoc_identifier + ";\n" - token = CommonToken(type=self.SemiColon) - token.text = text - else: - token = super(PhpLexerBase, self).nextToken() - token.text = heredoc_identifier + "\n;" - elif self._mode == self.PHP: - if self._channel == self.HIDDEN: - self._prevTokenType = token.type - - return token - - def GetHeredocEnd(self, text): - return text.strip().rstrip(';') - - def CheckHeredocEnd(self, text): - return self.GetHeredocEnd(text) == self._heredocIdentifier - - def IsNewLineOrStart(self, pos): - return self._input.LA(-1) <= 0 or self._input.LA(-1) == ord('\r') or self._input.LA(-1) == ord('\n') - - def PushModeOnHtmlClose(self): - self.popMode() - if self._scriptTag: - if not self._phpScript: - self.pushMode(self.SCRIPT) - else: - self.pushMode(self.PHP) - self._scriptTag = False - elif self._styleTag: - self.pushMode(self.STYLE) - self._styleTag = False - - def HasAspTags(self): - return self.AspTags - - def HasPhpScriptTag(self): - return self._phpScript - - def PopModeOnCurlyBracketClose(self): - if self._insideString: - self._insideString = False - self.channel(SkipChannel) - self.popMode() - - def ShouldPushHereDocMode(self, pos): - return self._input.LA(pos) == ord('\r') or self._input.LA(pos) == ord('\n') - - def IsCurlyDollar(self, pos): - return self._input.LA(pos) == ord('$') - - def SetInsideString(self): - self._insideString = True diff --git a/php/Python/README.md b/php/Python/README.md deleted file mode 100644 index 8a94d14b10..0000000000 --- a/php/Python/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Python - -The default Grammar is not compatible with Python. -Before generating the Lexer and Parser files for the Python Runtime run -``` -python transformGrammar.py -``` diff --git a/php/Python/transformGrammar.py b/php/Python/transformGrammar.py deleted file mode 100644 index 3267bcae87..0000000000 --- a/php/Python/transformGrammar.py +++ /dev/null @@ -1,41 +0,0 @@ -import sys, os, re, shutil - -# This script was originally found in the directory of the Golang Grammar, used for the transformation of the Golang Parser to be compatible with Python Runtime -# It was copied and modified to handle the PHP Grammar transformation. -def main(argv): - # Only the PhpLexer.g4 file needs to be transformed. - # However, the script also checks the PhpParser in case of a future change that may render it incompatible - fix("PhpLexer.g4") - fix("PhpParser.g4") - - -def fix(file_path): - print("Altering " + file_path) - if not os.path.exists(file_path): - print(f"Could not find file: {file_path}") - sys.exit(1) - parts = os.path.split(file_path) - file_name = parts[-1] - - if file_name.lower() not in ["phpparser.g4", "phplexer.g4"]: - print("Could not determine which grammar you have specified, please specify either the Parser or the Lexer") - sys.exit(1) - - shutil.move(file_path, file_path + ".bak") - input_file = open(file_path + ".bak",'r') - output_file = open(file_path, 'w') - for x in input_file: - if 'this.' in x: - x = x.replace('this.', 'self.') - output_file.write(x) - output_file.flush() - - print("Writing ...") - input_file.close() - output_file.close() - - -if __name__ == '__main__': - main(sys.argv) - - diff --git a/php/desc.xml b/php/desc.xml index ad4cdbfa37..e2954d4c91 100644 --- a/php/desc.xml +++ b/php/desc.xml @@ -2,4 +2,5 @@ ^4.10 CSharp;Java;Python3;Antlr4ng + examples/**/*.php