[antlr-interest] Do Lexer rules allow catch?

Brenden Bain bbain at atlassian.com
Tue Jul 7 18:40:10 PDT 2009


Hello,

Should it possible to add "catch" elements to lexer rules?

Consider the following with a Lexer rule:

> INT:
>    '0'..'9'+
>    ;
>    catch [RecognitionException e]
>    {
>        System.out.println("Houston, we've had a problem.");
>    }

When I try to process the grammar I get the following exception (also  
attached):

> java.util.NoSuchElementException: no such attribute: exceptions in  
> template context [lexerRule]
> org 
> .antlr 
> .stringtemplate.StringTemplate.rawSetAttribute(StringTemplate.java: 
> 647)
> org 
> .antlr 
> .stringtemplate.StringTemplate.setAttribute(StringTemplate.java:508)
> org 
> .antlr 
> .stringtemplate.StringTemplate.setAttribute(StringTemplate.java:590)
> org 
> .antlr 
> .stringtemplate.StringTemplate.setAttribute(StringTemplate.java:551)
> org 
> .antlr 
> .grammar 
> .v2.CodeGenTreeWalker.exceptionHandler(CodeGenTreeWalker.java:1479)
> org 
> .antlr 
> .grammar.v2.CodeGenTreeWalker.exceptionGroup(CodeGenTreeWalker.java: 
> 1150)
> org.antlr.grammar.v2.CodeGenTreeWalker.rule(CodeGenTreeWalker.java: 
> 849)
> org.antlr.grammar.v2.CodeGenTreeWalker.rules(CodeGenTreeWalker.java: 
> 588)
> org 
> .antlr 
> .grammar.v2.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:530)
> org 
> .antlr.grammar.v2.CodeGenTreeWalker.grammar(CodeGenTreeWalker.java: 
> 312)
> org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:429)
> org.antlr.Tool.generateRecognizer(Tool.java:607)
> org.antlr.Tool.process(Tool.java:484)
> org.antlr.Tool.main(Tool.java:91)

Thanks,
Brenden.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: error.txt
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20090708/4b942b7c/attachment.txt 
-------------- next part --------------



More information about the antlr-interest mailing list