diff --git a/php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java b/php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java index 990b543de..c4bb122f0 100644 --- a/php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java +++ b/php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java @@ -217,7 +217,7 @@ public VariableDeclarationTree MEMBER_CONST_DECLARATION() { return b.nonterminal(PHPLexicalGrammar.MEMBER_CONST_DECLARATION).is( f.memberConstDeclaration( b.token(PHPLexicalGrammar.IDENTIFIER_OR_KEYWORD), - b.optional(f.newTuple(b.token(EQU), STATIC_SCALAR())))); + b.optional(f.newTuple(b.token(EQU), EXPRESSION())))); } public VariableDeclarationTree CONST_VAR() { @@ -225,14 +225,14 @@ public VariableDeclarationTree CONST_VAR() { f.constDeclaration( b.token(PHPLexicalGrammar.IDENTIFIER), b.token(EQU), - STATIC_SCALAR())); + EXPRESSION())); } public VariableDeclarationTree VARIABLE_DECLARATION() { return b.nonterminal(PHPLexicalGrammar.VARIABLE_DECLARATION).is( f.variableDeclaration( b.token(PHPLexicalGrammar.REGULAR_VAR_IDENTIFIER), - b.optional(f.newTuple(b.token(EQU), STATIC_SCALAR())))); + b.optional(f.newTuple(b.token(EQU), EXPRESSION())))); } public NamespaceNameTree NAMESPACE_NAME() { @@ -358,7 +358,7 @@ public EnumCaseTree ENUM_CASE() { b.zeroOrMore(ATTRIBUTE_GROUP()), b.token(CASE), NAME_IDENTIFIER_OR_KEYWORD(), - b.optional(f.newTuple(b.token(EQU), STATIC_SCALAR())), + b.optional(f.newTuple(b.token(EQU), EXPRESSION())), EOS())); } @@ -509,7 +509,7 @@ public ParameterTree PARAMETER() { b.optional( f.newTuple( b.token(PHPPunctuator.EQU), - STATIC_SCALAR())), + EXPRESSION())), b.optional(PROPERTY_HOOK_LIST()))); } @@ -798,7 +798,7 @@ public VariableDeclarationTree STATIC_VAR() { return b.nonterminal(PHPLexicalGrammar.STATIC_VAR).is( f.staticVar( b.token(PHPLexicalGrammar.REGULAR_VAR_IDENTIFIER), - b.optional(f.newTuple(b.token(EQU), STATIC_SCALAR())))); + b.optional(f.newTuple(b.token(EQU), EXPRESSION())))); } public DeclareStatementTree DECLARE_STATEMENT() { @@ -1816,13 +1816,6 @@ public VariableTree LEXICAL_VARIABLE() { VARIABLE_IDENTIFIER())); } - public ExpressionTree STATIC_SCALAR() { - return b.nonterminal(PHPLexicalGrammar.STATIC_SCALAR).is( - b.firstOf( - f.combinedScalarOffset(ARRAY_INITIALIZER(), b.zeroOrMore(DIMENSIONAL_OFFSET())), - EXPRESSION())); - } - public FunctionCallTree INTERNAL_FUNCTION() { return b.nonterminal(PHPLexicalGrammar.INTERNAL_FUNCTION).is( b.firstOf( diff --git a/php-frontend/src/main/java/org/sonar/php/parser/PHPLexicalGrammar.java b/php-frontend/src/main/java/org/sonar/php/parser/PHPLexicalGrammar.java index 9cb649529..25e8b6813 100644 --- a/php-frontend/src/main/java/org/sonar/php/parser/PHPLexicalGrammar.java +++ b/php-frontend/src/main/java/org/sonar/php/parser/PHPLexicalGrammar.java @@ -195,7 +195,6 @@ public enum PHPLexicalGrammar implements GrammarRuleKey { OBJECT_MEMBER_ACCESS, FUNCTION_CALL_PARAMETER_LIST, DIMENSIONAL_OFFSET, - STATIC_SCALAR, ARRAY_INIALIZER, COMMON_SCALAR, YIELD_SCALAR, diff --git a/php-frontend/src/test/java/org/sonar/php/parser/expression/StaticScalarTest.java b/php-frontend/src/test/java/org/sonar/php/parser/expression/StaticScalarTest.java deleted file mode 100644 index 0edc93150..000000000 --- a/php-frontend/src/test/java/org/sonar/php/parser/expression/StaticScalarTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube PHP Plugin - * Copyright (C) 2010-2025 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Sonar Source-Available License for more details. - * - * You should have received a copy of the Sonar Source-Available License - * along with this program; if not, see https://sonarsource.com/license/ssal/ - */ -package org.sonar.php.parser.expression; - -import org.junit.jupiter.api.Test; -import org.sonar.php.parser.PHPLexicalGrammar; - -import static org.sonar.php.utils.Assertions.assertThat; - -class StaticScalarTest { - - @Test - void test() { - assertThat(PHPLexicalGrammar.STATIC_SCALAR) - .matches("Foo") - .matches("array()") - .matches("$a = 1") - .matches("1 or 2"); - } -}