Skip to content

Commit

Permalink
SONARPHP-492 Extract the lexical part from the grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
vilchik-elena authored and pynicolas committed Oct 2, 2015
1 parent 70a7423 commit 7a16a9c
Show file tree
Hide file tree
Showing 23 changed files with 1,414 additions and 27 deletions.
4 changes: 2 additions & 2 deletions php-frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<dependencies>
<dependency>
<groupId>org.codehaus.sonar.sslr</groupId>
<groupId>org.sonarsource.sslr</groupId>
<artifactId>sslr-core</artifactId>
</dependency>
<dependency>
Expand All @@ -26,7 +26,7 @@
<artifactId>sonar-deprecated</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.sonar.sslr</groupId>
<groupId>org.sonarsource.sslr</groupId>
<artifactId>sslr-testing-harness</artifactId>
</dependency>
<!-- unit tests -->
Expand Down
41 changes: 41 additions & 0 deletions php-frontend/src/main/java/org/sonar/php/parser/NewPHPGrammar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SonarQube PHP Plugin
* Copyright (C) 2010 SonarSource and Akram Ben Aissi
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.php.parser;

import com.sonar.sslr.api.typed.GrammarBuilder;
import org.sonar.php.tree.impl.lexical.InternalSyntaxToken;
import org.sonar.plugins.php.api.tree.expression.ExpressionTree;

public class NewPHPGrammar {

private final GrammarBuilder<InternalSyntaxToken> b;
private final TreeFactory f;

public NewPHPGrammar(GrammarBuilder<InternalSyntaxToken> b, TreeFactory f) {
this.b = b;
this.f = f;
}

public ExpressionTree EXPRESSION() {
return b.<ExpressionTree>nonterminal(PHPLexicalGrammar.EXPRESSION)
.is(f.expression(b.token(PHPLexicalGrammar.VARIABLE_IDENTIFIER)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

import com.sonar.sslr.api.GenericTokenType;
import org.sonar.php.api.PHPKeyword;
import org.sonar.php.api.PHPPunctuator;
import org.sonar.sslr.grammar.GrammarRuleKey;
import org.sonar.sslr.grammar.LexerlessGrammarBuilder;
import org.sonar.sslr.parser.LexerlessGrammar;

import static org.sonar.php.api.PHPKeyword.ABSTRACT;
import static org.sonar.php.api.PHPKeyword.ARRAY;
import static org.sonar.php.api.PHPKeyword.AS;
Expand Down Expand Up @@ -85,7 +90,6 @@
import static org.sonar.php.api.PHPKeyword.VAR;
import static org.sonar.php.api.PHPKeyword.WHILE;
import static org.sonar.php.api.PHPKeyword.YIELD;
import org.sonar.php.api.PHPPunctuator;
import static org.sonar.php.api.PHPPunctuator.AMPERSAND;
import static org.sonar.php.api.PHPPunctuator.ANDAND;
import static org.sonar.php.api.PHPPunctuator.ANDEQUAL;
Expand Down Expand Up @@ -141,9 +145,6 @@
import static org.sonar.php.api.PHPPunctuator.TILDA;
import static org.sonar.php.api.PHPPunctuator.XOR;
import static org.sonar.php.api.PHPPunctuator.XOR_EQU;
import org.sonar.sslr.grammar.GrammarRuleKey;
import org.sonar.sslr.grammar.LexerlessGrammarBuilder;
import org.sonar.sslr.parser.LexerlessGrammar;

public enum PHPGrammar implements GrammarRuleKey {

Expand Down
Loading

0 comments on commit 7a16a9c

Please sign in to comment.