added new Java 1.4 grammar
This commit is contained in:
parent
78bc37d673
commit
e4434ebe00
24
build.xml
24
build.xml
|
|
@ -17,7 +17,7 @@
|
|||
<property name="testreport.dir" value="target/testreports"/>
|
||||
<property name="dist.dir" value="target/dist"/>
|
||||
|
||||
<property name="version" value="2.4" />
|
||||
<property name="version" value="3.0" />
|
||||
|
||||
<path id="build.classpath">
|
||||
<pathelement location="${antlr.jar}" />
|
||||
|
|
@ -76,7 +76,7 @@
|
|||
description="Checks whether the grammar file is newer that the generated code">
|
||||
<uptodate property="uptodate.antlr"
|
||||
targetfile="${checkstyle.dir}/GeneratedJava14Lexer.java" >
|
||||
<srcfiles dir= "${checkstyle.dir}" includes="java_new.g,java.g,java14.g"/>
|
||||
<srcfiles dir= "${checkstyle.dir}" includes="java_new.g,java14_new.g,java.g,java14.g"/>
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
|
|
@ -85,12 +85,20 @@
|
|||
<!-- which creates lots of problems. -->
|
||||
<target name="build.antlr" depends="check.antlr" unless="uptodate.antlr"
|
||||
description="Conditionally compiles the grammar files">
|
||||
<java classname="antlr.Tool"
|
||||
classpath="${antlr-tools.jar}"
|
||||
fork="yes"
|
||||
dir="${checkstyle.dir}">
|
||||
<arg value="java_new.g" />
|
||||
</java>
|
||||
<java classname="antlr.Tool"
|
||||
classpath="${antlr-tools.jar}"
|
||||
fork="yes"
|
||||
dir="${checkstyle.dir}">
|
||||
<arg value="java_new.g" />
|
||||
</java>
|
||||
<java classname="antlr.Tool"
|
||||
classpath="${antlr-tools.jar}"
|
||||
fork="yes"
|
||||
dir="${checkstyle.dir}">
|
||||
<arg value="-glib" />
|
||||
<arg value="java_new.g" />
|
||||
<arg value="java14_new.g" />
|
||||
</java>
|
||||
<java classname="antlr.Tool"
|
||||
classpath="${antlr-tools.jar}"
|
||||
fork="yes"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
// Copyright (C) 2001-2002 Oliver Burn
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
header {
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
}
|
||||
|
||||
|
||||
/** Java 1.4 Recognizer
|
||||
*
|
||||
* Based heavily on the Grammer example that comes with ANTLR. See
|
||||
* http://www.antlr.org.
|
||||
*
|
||||
*/
|
||||
class Java14Recognizer extends JavaRecognizer;
|
||||
|
||||
// Options don't get inherited, copy of option block required.
|
||||
options {
|
||||
k = 2; // two token lookahead
|
||||
exportVocab=Java14; // Call its vocabulary "Java14"
|
||||
codeGenMakeSwitchThreshold = 2; // Some optimizations
|
||||
codeGenBitsetTestThreshold = 3;
|
||||
defaultErrorHandler = false; // Don't generate parser error handlers
|
||||
buildAST = true;
|
||||
}
|
||||
|
||||
// overrides the statement production in java.g, adds assertStatement
|
||||
statement
|
||||
: traditionalStatement
|
||||
| assertStatement
|
||||
;
|
||||
|
||||
// assert statement, available since JDK 1.4
|
||||
assertStatement
|
||||
: ASSERT^ expression ( COLON! expression )? SEMI!
|
||||
;
|
||||
|
||||
class Java14Lexer extends JavaLexer;
|
||||
|
||||
options {
|
||||
exportVocab=Java14; // call the vocabulary "Java14",
|
||||
testLiterals=false; // don't automatically test for literals
|
||||
k=4; // four characters of lookahead
|
||||
charVocabulary='\u0003'..'\uFFFF';
|
||||
codeGenBitsetTestThreshold=20;
|
||||
}
|
||||
|
||||
tokens {
|
||||
ASSERT="assert";
|
||||
}
|
||||
|
||||
// antlr expects a definition here: 'unexpected token: null'
|
||||
// To avoid that message, one definition from GeneratedJavaLexer
|
||||
// is repeated. Rather inelegant but I didn't find a better solution :-(
|
||||
// Feel free to improve this...
|
||||
protected
|
||||
FLOAT_SUFFIX
|
||||
: 'f'|'F'|'d'|'D'
|
||||
;
|
||||
|
|
@ -440,8 +440,15 @@ compoundStatement
|
|||
RCURLY!
|
||||
;
|
||||
|
||||
|
||||
// This production provides a slot for adding additional statement productions.
|
||||
// It is used to simplify an inherited grammar that includes assert statements
|
||||
// (new Java language feature in JDK 1.4)
|
||||
statement
|
||||
: traditionalStatement
|
||||
;
|
||||
|
||||
// a traditional (JDK < 1.4) java statement, assert keyword is not allowed
|
||||
traditionalStatement
|
||||
// A list of statements in curly braces -- start a new scope!
|
||||
: compoundStatement
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue