FLEX-35341 find a place to try to make css parser errors more readable
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/24ab3ad0 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/24ab3ad0 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/24ab3ad0 Branch: refs/heads/develop Commit: 24ab3ad024d650a5e6c87a056cb1572f44ed5057 Parents: 6e58797 Author: Alex Harui <aha...@apache.org> Authored: Sun Jul 16 08:35:49 2017 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Sun Jul 16 08:35:49 2017 -0700 ---------------------------------------------------------------------- .../resources/flexjs/files/CSSTestSource.css | 4 ++++ .../compiler/problems/CSSParserProblem.java | 23 +++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/24ab3ad0/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css ---------------------------------------------------------------------- diff --git a/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css b/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css index 74340ba..cb96b51 100755 --- a/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css +++ b/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css @@ -22,6 +22,10 @@ @namespace basic "library://ns.apache.org/flexjs/basic"; @namespace "http://www.w3.org/1999/xhtml"; +.foo{ + 8px 24px 0px; +} + /* //---------------------------- // Named styles http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/24ab3ad0/compiler/src/main/java/org/apache/flex/compiler/problems/CSSParserProblem.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/problems/CSSParserProblem.java b/compiler/src/main/java/org/apache/flex/compiler/problems/CSSParserProblem.java index cffa94b..db480d1 100644 --- a/compiler/src/main/java/org/apache/flex/compiler/problems/CSSParserProblem.java +++ b/compiler/src/main/java/org/apache/flex/compiler/problems/CSSParserProblem.java @@ -62,7 +62,7 @@ public final class CSSParserProblem extends CompilerProblem { final String messageHeader = baseRecognizer.getErrorHeader(e); final String messageBody = baseRecognizer.getErrorMessage(e, tokenNames); - final String reason = String.format("%s %s", messageHeader, messageBody); + final String reason = String.format("%s %s", messageHeader, makeNice(messageBody)); final ISourceLocation location = new SourceLocation( e.input.getSourceName(), @@ -71,4 +71,25 @@ public final class CSSParserProblem extends CompilerProblem return new CSSParserProblem(location, reason, baseRecognizer.getClass()); } + + private static String makeNice(String s) + { + if (s.contains("mismatched tree node: <mismatched token")) + { + int c = s.indexOf("expecting"); + if (c != -1) + { + String expecting = s.substring(c); + expecting = expecting.replace("I_DECL", "CSS property name"); + c = s.indexOf("resync"); + if (c != -1) + { + s = s.substring(0, c); + } + String token = s.replaceFirst("mismatched tree node: <mismatched token: \\[\\@([^=]+)=([^,]+),<([^>]+)>.*$", "unexpected token $2"); + s = token + " " + expecting; + } + } + return s; + } }