Dear all, I'd like to catch the exception at the *last token* in the rule. I managed to test some rules to catch the last token mismatch but I couldn't do. Here is my test:
1. In "T.g" :
grammar T;
options {
language=Java;
}
@members {
String s;
}
// Alter code generation so catch-clauses get replace with
// this action.
@rulecatch {
catch (RecognitionException e) {
throw e;
}
}
// END:override
r : ID '#' {s = $ID.text; System.out.println("found "+s);} ;
ID: 'a'..'z'+ ;
WS: (' '|'\n'|'\r')+ {skip();} ; // ignore whitespace
2. In "input.txt":
b
3. In "Test.java":
import org.antlr.runtime.*;
public class Test {
public static void main(String[] args) throws Exception {
//ANTLRInputStream input = new ANTLRInputStream(System.in);
//TLexer lexer = new TLexer(input);
TLexer lexer = new TLexer(new ANTLRFileStream("input.txt"));
CommonTokenStream tokens = new CommonTokenStream(lexer);
TParser parser = new TParser(tokens);
try{
parser.r();
}
catch (RecognitionException e) {
System.out.println(e.getClass().toString());
//e.printStackTrace();
}
}
}
4. The output in console when I run Test:
$ java Test
line 0:-1 missing '#' at '<EOF>'
found b
I don't know why the last token mismatch couldn't catch in the main function
of Test. Could you please help me?
Thank you very much,
Ha Luong
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
b
T.g
Description: Binary data
Test.java
Description: Binary data
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
