Akim Demaille <[email protected]> wrote: > [...] >> Also on this topic: Are there useful Emacs tidbits and/or >> git hooks to format and check commit messages?
> Have a look at vc-dwim. I am not using it, yet. That seems interesting. >> +AT_DATA([[input1.txt]], [[-- >> +]]) >> +AT_DATA([[input2.txt]], [[-+ >> +]]) >> +AT_DATA([[input3.txt]], [[+- >> +]]) >> +AT_BISON_CHECK([[YYParser.y]]) >> +AT_JAVA_COMPILE([[YYParser.java]]) >> +AT_JAVA_PARSER_CHECK([[YYParser < input1.txt]], [[0]], [[]], [[]]) >> +AT_JAVA_PARSER_CHECK([[YYParser < input2.txt]], [[0]], [[]], [[syntax error >> +]]) >> +AT_JAVA_PARSER_CHECK([[YYParser < input3.txt]], [[0]], [[]], [[syntax error >> +]]) > I would prefer > AT_BISON_CHECK([[YYParser.y]]) > AT_JAVA_COMPILE([[YYParser.java]]) > AT_DATA(input.txt, …) > AT_JAVA_PARSER_CHECK(YYParser < input.txt) > AT_DATA(input.txt, …) > AT_JAVA_PARSER_CHECK(YYParser < input.txt) > AT_DATA(input.txt, …) > AT_JAVA_PARSER_CHECK(YYParser < input.txt) Yeah, that'd look more readable. > Actually, I would even prefer not using stdin, but passing the > string as argv. And 'a', 'b' are more traditional than - and + :) > See for instance actions.at, snippets such as > AT_PARSER_CHECK([./input '(x)'], 0, > AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1, > etc. I chose stdin because: - the other Java test cases use it, - it's (very :-)) slightly shorter, and - I don't have to worry about various powers that be (AT_JAVA_PARSER_CHECK, javaexec.sh, etc.) mangling the ar- guments and/or guarding against args [] being empty (albe- it with arguments "aa" instead of "--" this is probably never the case). but I'm not married to that idea, so attached a patch again with the args [] method (and no TABs :-)). Tim
>From 00169673af95b50c780423054a7718ba6b96472e Mon Sep 17 00:00:00 2001 From: Tim Landscheidt <[email protected]> Date: Sun, 12 Feb 2012 01:29:41 +0000 Subject: [PATCH] Java: Fix syntax error handling without error token. * data/lalr1.java (YYParser::parse): Here. * tests/java.at: Add test case. --- data/lalr1.java | 2 +- tests/java.at | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletions(-) diff --git a/data/lalr1.java b/data/lalr1.java index 57ff993..a40d6c2 100644 --- a/data/lalr1.java +++ b/data/lalr1.java @@ -686,7 +686,7 @@ m4_popdef([b4_at_dollar])])dnl } /* Pop the current state because it cannot handle the error token. */ - if (yystack.height == 1) + if (yystack.height == 0) return false; ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[ diff --git a/tests/java.at b/tests/java.at index b3e79e9..b6ea163 100644 --- a/tests/java.at +++ b/tests/java.at @@ -781,3 +781,69 @@ AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore]) AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore]) AT_CLEANUP + + +# ----------------------------------------------- # +# Java syntax error handling without error token. # +# ----------------------------------------------- # + +AT_SETUP([Java syntax error handling without error token]) + +AT_DATA([[YYParser.y]], [[%language "Java" + +%lex-param { String s } + +%code imports { + import java.io.IOException; +} + +%code lexer { + String Input; + int Position; + + public YYLexer (String s) + { + Input = s; + Position = 0; + } + + public void yyerror (String s) + { + System.err.println (s); + } + + public Object getLVal () + { + return null; + } + + public int yylex () throws IOException + { + if (Position >= Input.length ()) + return EOF; + else + return Input.charAt (Position++); + } +} + +%code { + public static void main (String args []) throws IOException + { + YYParser p = new YYParser (args [0]); + p.parse (); + } +} +%% +input: + 'a' 'a' +; +]]) +AT_BISON_CHECK([[YYParser.y]]) +AT_JAVA_COMPILE([[YYParser.java]]) +AT_JAVA_PARSER_CHECK([[YYParser aa]], [[0]], [[]], [[]]) +AT_JAVA_PARSER_CHECK([[YYParser ab]], [[0]], [[]], [[syntax error +]]) +AT_JAVA_PARSER_CHECK([[YYParser ba]], [[0]], [[]], [[syntax error +]]) + +AT_CLEANUP -- 1.6.2.5
