[stringtemplate-interest] ST4: throw new Error in STLexer?

Terence Parr parrt at cs.usfca.edu
Tue Jan 25 11:13:34 PST 2011


Excellent point. fixed.
Ter
On Jan 23, 2011, at 3:12 PM, Udo Borkowski wrote:

> (Using ST4 Beta 2)
> 
> I noticed in STLexer#match there is a 
>         else throw new Error(getErrorHeader()+": expecting "+x+"; found "+c);
> 
> I wonder if this shouldn't be a throw new RecognitionException or some other exception that is than converted into something that is delegated to the error listeners.
> 
> Because of the current implementation a malformed (group) template file will raise an exception when trying to load that file. I thought these things would be covered by the ErrorListeners.
> 
> Here an stack trace when trying to load a file with the (invalid) content:
> 
> main(p) ::= <<
> <\
> >>
> 
> Exception in thread "AWT-EventQueue-0" java.lang.Error: 1:0: expecting >; found ?
> 	at org.stringtemplate.v4.compiler.STLexer.match(STLexer.java:172)
> 	at org.stringtemplate.v4.compiler.STLexer.ESCAPE(STLexer.java:346)
> 	at org.stringtemplate.v4.compiler.STLexer.outside(STLexer.java:206)
> 	at org.stringtemplate.v4.compiler.STLexer._nextToken(STLexer.java:192)
> 	at org.stringtemplate.v4.compiler.STLexer.nextToken(STLexer.java:146)
> 	at org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:133)
> 	at org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:127)
> 	at org.antlr.runtime.CommonTokenStream.setup(CommonTokenStream.java:127)
> 	at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:91)
> 	at org.stringtemplate.v4.compiler.STParser.templateAndEOF(STParser.java:121)
> 	at org.stringtemplate.v4.compiler.Compiler.compile(Compiler.java:145)
> 	at org.stringtemplate.v4.STGroup.compile(STGroup.java:387)
> 	at org.stringtemplate.v4.STGroup.defineTemplate(STGroup.java:282)
> 	at org.stringtemplate.v4.STGroup.defineTemplateOrRegion(STGroup.java:340)
> 	at org.stringtemplate.v4.compiler.GroupParser.templateDef(GroupParser.java:520)
> 	at org.stringtemplate.v4.compiler.GroupParser.def(GroupParser.java:324)
> 	at org.stringtemplate.v4.compiler.GroupParser.group(GroupParser.java:185)
> 	at org.stringtemplate.v4.STGroup.loadGroupFile(STGroup.java:460)
> 	at org.stringtemplate.v4.STGroupFile.load(STGroupFile.java:118)
> 	at org.stringtemplate.v4.STGroupFile.load(STGroupFile.java:109)
> 	at org.stringtemplate.v4.STGroup.lookupTemplate(STGroup.java:202)
> 	at org.stringtemplate.v4.STGroup.getInstanceOf(STGroup.java:145)
> 
> Udo
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list