diff --git a/pmd-javascript/etc/grammar/es5.jj b/pmd-javascript/etc/grammar/Ecmascript5.jj similarity index 98% rename from pmd-javascript/etc/grammar/es5.jj rename to pmd-javascript/etc/grammar/Ecmascript5.jj index 688692d61d..e180c2f760 100644 --- a/pmd-javascript/etc/grammar/es5.jj +++ b/pmd-javascript/etc/grammar/Ecmascript5.jj @@ -12,17 +12,17 @@ options { // JDK_VERSION = "1.5"; } -PARSER_BEGIN(Ecmascript5Parser) +PARSER_BEGIN(Ecmascript5ParserImpl) package net.sourceforge.pmd.lang.ecmascript5.ast; import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; -public class Ecmascript5Parser { +public class Ecmascript5ParserImpl { } -PARSER_END(Ecmascript5Parser) +PARSER_END(Ecmascript5ParserImpl) /* WHITE SPACE - 7.2 */ @@ -756,9 +756,9 @@ TOKEN : | < NE: "!=" > : DEFAULT | < SC_OR: "||" > : DEFAULT | < SC_AND: "&&" > : DEFAULT -| < INCR: "++" > { if (matchedToken.specialToken != null && matchedToken.specialToken.kind == EOL) { matchedToken.kind = NL_INCR; } } : DEFAULT +| < INCR: "++" > { if (matchedToken.specialToken != null && matchedToken.specialToken.kind == EOL) { matchedToken = matchedToken.withKind(NL_INCR); } } : DEFAULT | < NL_INCR: [ "\r" , "\n" , "\u2028" , "\u2029"] "++" > : DEFAULT -| < DECR: "--" > { if (matchedToken.specialToken != null && matchedToken.specialToken.kind == EOL) { matchedToken.kind = NL_DECR; } } : DEFAULT +| < DECR: "--" > { if (matchedToken.specialToken != null && matchedToken.specialToken.kind == EOL) { matchedToken = matchedToken.withKind(NL_DECR); } } : DEFAULT | < NL_DECR: [ "\r" , "\n" , "\u2028" , "\u2029"] "--" > : DEFAULT | < PLUS: "+" > : DEFAULT | < MINUS: "-" > : DEFAULT diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index 74d7303482..1265609c0d 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -37,8 +37,10 @@ generate-sources - - + + + + diff --git a/pmd-javascript/src/main/ant/alljavacc.xml b/pmd-javascript/src/main/ant/alljavacc.xml deleted file mode 100644 index 405026b5cd..0000000000 --- a/pmd-javascript/src/main/ant/alljavacc.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public class Token implements java.io.Serializable - - - - - - public Token specialToken; - - - - - - - - - - - - - - - - - - - - diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java index ebfb3e4ce8..988d7f234b 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java @@ -8,16 +8,15 @@ import java.io.StringReader; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.GenericToken; -import net.sourceforge.pmd.lang.ecmascript5.Ecmascript5TokenManager; -import net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5ParserConstants; -import net.sourceforge.pmd.lang.ecmascript5.ast.Token; +import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; +import net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5TokenKinds; +import net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5TokenManager; import net.sourceforge.pmd.util.IOUtil; /** * The Ecmascript Tokenizer */ -public class EcmascriptTokenizer extends JavaCCTokenizer { +public class EcmascriptTokenizer extends JavaCCTokenizer { @Override protected TokenManager getLexerForSource(SourceCode sourceCode) { @@ -26,18 +25,12 @@ public class EcmascriptTokenizer extends JavaCCTokenizer { } @Override - protected TokenEntry processToken(Tokens tokenEntries, GenericToken currentToken, String filename) { - return new TokenEntry(getTokenImage(currentToken), filename, currentToken.getBeginLine(), - currentToken.getBeginColumn(), currentToken.getEndColumn()); - } - - private String getTokenImage(GenericToken token) { - Token jsToken = (Token) token; + protected String getImage(JavaccToken jsToken) { // Remove line continuation characters from string literals - if (jsToken.kind == Ecmascript5ParserConstants.STRING_LITERAL - || jsToken.kind == Ecmascript5ParserConstants.UNTERMINATED_STRING_LITERAL) { - return token.getImage().replaceAll("(?