From 890da3168247e19a83f14815b76866ce73a4193f Mon Sep 17 00:00:00 2001 From: fscheffer Date: Sat, 19 Jul 2014 14:17:17 +0200 Subject: [PATCH 1/2] upgraded to antlr-runtime 3.5.2 --- pom.xml | 2 +- .../antlr3/com/github/sommeri/less4j/core/parser/Less.g | 2 +- .../sommeri/less4j/core/parser/HiddenTokenAwareTree.java | 5 +++-- .../com/github/sommeri/less4j/grammar/GrammarAsserts.java | 8 ++++---- .../sommeri/less4j/resources/Less4jExceptionTest.java | 2 +- .../import-syntactically-incorrect-unclosed-ruleset.err | 2 +- src/test/resources/error-handling/lexer-errors.err | 2 +- src/test/resources/error-handling/parser-errors.err | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 949098ff..73a787cf 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ Less4j is a port. The original compiler was written in JavaScript and is called 1.6.6 1.4.6 - 3.4 + 3.5.2 diff --git a/src/main/antlr3/com/github/sommeri/less4j/core/parser/Less.g b/src/main/antlr3/com/github/sommeri/less4j/core/parser/Less.g index 9fd2e3b1..5ab2e007 100644 --- a/src/main/antlr3/com/github/sommeri/less4j/core/parser/Less.g +++ b/src/main/antlr3/com/github/sommeri/less4j/core/parser/Less.g @@ -142,7 +142,7 @@ tokens { public Token nextToken() { super.nextToken(); if ( tokens.size()==0 ) { - return Token.EOF_TOKEN; + return getEOFToken(); } return (Token)tokens.remove(0); } diff --git a/src/main/java/com/github/sommeri/less4j/core/parser/HiddenTokenAwareTree.java b/src/main/java/com/github/sommeri/less4j/core/parser/HiddenTokenAwareTree.java index 74f88158..a4c89075 100644 --- a/src/main/java/com/github/sommeri/less4j/core/parser/HiddenTokenAwareTree.java +++ b/src/main/java/com/github/sommeri/less4j/core/parser/HiddenTokenAwareTree.java @@ -46,10 +46,11 @@ public HiddenTokenAwareTree getChild(int i) { @SuppressWarnings("unchecked") public List getChildren() { - List result = super.getChildren(); + List result = super.getChildren(); if (result == null) result = Collections.emptyList(); - return result; + + return (List) result; } public boolean hasChildren() { diff --git a/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java b/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java index 766c24f7..3ffd25fc 100644 --- a/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java +++ b/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java @@ -125,11 +125,11 @@ public Object post(Object t) { } private int countOnChannelTokes(int start, int end) { - @SuppressWarnings("unchecked") - List list = tokens.get(start, end); + List list = tokens.get(start, end); int count = 0; - for (CommonToken token : list) { - if (isOnChannel(token) && !isDummy(token)) + for (Token token : list) { + CommonToken commonToke = CommonToken.class.cast(token); + if (isOnChannel(commonToke) && !isDummy(commonToke)) count++; } return count; diff --git a/src/test/java/com/github/sommeri/less4j/resources/Less4jExceptionTest.java b/src/test/java/com/github/sommeri/less4j/resources/Less4jExceptionTest.java index 09d1c98e..9b2f9610 100644 --- a/src/test/java/com/github/sommeri/less4j/resources/Less4jExceptionTest.java +++ b/src/test/java/com/github/sommeri/less4j/resources/Less4jExceptionTest.java @@ -40,7 +40,7 @@ public void testThreeErrors() { @Test public void testAntlrError() { String less = ".class { margin: 1 1 1 1; "; - String expectedError = "Could not compile less. 1 error(s) occurred:\nERROR 0:0 no viable alternative at input '' in ruleset (which started at 1:1)\n"; + String expectedError = "Could not compile less. 1 error(s) occurred:\nERROR 1:27 no viable alternative at input '' in ruleset (which started at 1:1)\n"; expectCompileError(less, expectedError); } diff --git a/src/test/resources/compile-basic-features/import/import-syntactically-incorrect-unclosed-ruleset.err b/src/test/resources/compile-basic-features/import/import-syntactically-incorrect-unclosed-ruleset.err index aaa249dc..c41bedf2 100644 --- a/src/test/resources/compile-basic-features/import/import-syntactically-incorrect-unclosed-ruleset.err +++ b/src/test/resources/compile-basic-features/import/import-syntactically-incorrect-unclosed-ruleset.err @@ -1,2 +1,2 @@ Errors produced by compilation of testCase -ERROR import#FILE_SEPARATOR#syntactically-incorrect-unclosed-ruleset.less 0:0 no viable alternative at input '' in ruleset (which started at 2:1) +ERROR import#FILE_SEPARATOR#syntactically-incorrect-unclosed-ruleset.less 4:3 no viable alternative at input '' in ruleset (which started at 2:1) diff --git a/src/test/resources/error-handling/lexer-errors.err b/src/test/resources/error-handling/lexer-errors.err index c98b38e2..8046fa1f 100644 --- a/src/test/resources/error-handling/lexer-errors.err +++ b/src/test/resources/error-handling/lexer-errors.err @@ -1,4 +1,4 @@ Errors produced by compilation of testCase ERROR 2:29 no viable alternative at character ';' ERROR 7:2 mismatched character '' expecting '*' -ERROR 0:0 no viable alternative at input '' in ruleset (which started at 5:1) +ERROR 7:2 no viable alternative at input '' in ruleset (which started at 5:1) diff --git a/src/test/resources/error-handling/parser-errors.err b/src/test/resources/error-handling/parser-errors.err index 264b8877..17fb95b0 100644 --- a/src/test/resources/error-handling/parser-errors.err +++ b/src/test/resources/error-handling/parser-errors.err @@ -1,4 +1,4 @@ Errors produced by compilation of testCase ERROR 1:10 no viable alternative at input ':' in unknown ruleset (which started at 1:1) ERROR 1:12 extraneous input '2' expecting 'identifier' in selectors (which started at 1:10) -ERROR 0:0 no viable alternative at input '' in ruleset (which started at 1:10) +ERROR 5:1 no viable alternative at input '' in ruleset (which started at 1:10) From 7b63f89c008a62b81fb11f0251bf848934c9510b Mon Sep 17 00:00:00 2001 From: fscheffer Date: Sat, 19 Jul 2014 16:52:52 +0200 Subject: [PATCH 2/2] fixed typo in GrammarAsserts --- .../com/github/sommeri/less4j/grammar/GrammarAsserts.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java b/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java index 3ffd25fc..00a907c4 100644 --- a/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java +++ b/src/test/java/com/github/sommeri/less4j/grammar/GrammarAsserts.java @@ -128,8 +128,8 @@ private int countOnChannelTokes(int start, int end) { List list = tokens.get(start, end); int count = 0; for (Token token : list) { - CommonToken commonToke = CommonToken.class.cast(token); - if (isOnChannel(commonToke) && !isDummy(commonToke)) + CommonToken commonToken = CommonToken.class.cast(token); + if (isOnChannel(commonToken) && !isDummy(commonToken)) count++; } return count;