[antlr-interest] [CSharp3] @namespace and composite grammars

Ranco Marcus ranco.marcus at epirion.nl
Thu Mar 24 03:55:20 PDT 2011


To maximize reuse of our grammars we generally create separate lexer and parser grammars which are target agnostic (i.e. contain no target specific code). We then combine them into a composite grammar in which the target language and other implementation specific details are specified (header,members,namespace,etc.). This way, grammars can be used for multiple targets and we have maximum freedom to combine multiple lexers/parsers into larger ones.

If a composite grammar C imports a parser grammar P and a lexer grammar L, the tool generates CParser, CLexer, C_P and C_L.

Adding @namespace { <X> } to the composite grammar should IMHO put all four recognizers in namespace <X>. Currently, at least with the CSharp3 target, only CParser is put into the specified namespace.

Specifying @lexer::namespace { <X> } to the composite grammar causes only the outermost lexer CLexer to be added to the specified namespace, not the imported lexer C_L. The same holds for @parser::namespace.

Btw, if I'm not mistaken, there's no way to put recognizers in packages with the Java target. Is that correct?

Best regards,

Ranco Marcus
Epirion Knowledge Solutions B.V.



More information about the antlr-interest mailing list