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

Udo Borkowski ub at abego-software.de
Sun Jan 23 15:12:59 PST 2011


(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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110124/9e934c19/attachment.html 


More information about the stringtemplate-interest mailing list