[antlr-interest] ANTLR4 options ignored in imported grammar

cd.barth at t-online.de cd.barth at t-online.de
Fri Oct 26 15:57:25 PDT 2012


(this time with cc - sorry) 

Hi Ter
indeed i'm using some actions in my LexerExtension for different lexer
grammars (not combining multiple lexers at moment)
sample:
public boolean isCharInRange(final int _StartPos, final int _EndPos) {
		int _CharPos = getCharPositionInLine();
		if ((_CharPos >= _StartPos) && (_CharPos <= _EndPos)) {
return true; }
		return false;
	}
Therefore some synpred bulk is hidden and the grammar is easier to read.
I see that alternative @lexer::members is a good place for actions and I
also can call actions from imported utility classes there.
But the solution with LexerExtension looks more fashionable for me.  
  
I hoped that it would be possible to define options @lexer::options and
@parser::options in the matter of @members and @headers by fixing Java.stg.
  
Your next question: 
   why import anyway if already separate mmh.. yes this seems the better way
for me.

Claus-Dieter



-----Ursprüngliche Nachricht-----
Von: Terence Parr [mailto:parrt at cs.usfca.edu]
Gesendet: Freitag, 26. Oktober 2012 19:20
An: <cd.barth at t-online.de>
Cc: antlr-interest at antlr.org
Betreff: Re: [antlr-interest] ANTLR4 options ignored in imported grammar

hm
 good question. options don't generally make sense to import. that one is
more of an action.

i don't see a good solution here.  why import anyway if already separate?
are you combining multiple lexers?

Ter
On Oct 26, 2012, at 3:50 AM, <cd.barth at t-online.de> <cd.barth at t-online.de>
wrote:

> ANTLR4 (v 4.0b2) works fine when I'm using separated lexer and parser 
> grammars
> 
> 
> 
> lexer grammar CommonLexerRules;;
> 
> options {   superClass=LexerExtension; } .
> 
> 
> 
> parser grammar PLiParser;
> 
> options {   superClass=ParserExtension; }.
> 
> 
> 
> and generates accurate the lines
> 
> .public class PLiLexer extends LexerExtension {.
> 
> .public class PLiParser extends ParserExtension {.
> 
> 
> 
> But when I'm using the new cool feature for importing grammars like
> 
> 
> 
> grammar CombindedPLiGrammar;
> 
> import PLiLexer;
> 
> .
> 
> 
> 
> I get the warning : options ignored in imported grammar
> 
> 
> 
> The generated java file contains
> 
> .public class PLiLexer extends Lexer {.      instead of : extends
> LexerExtension
> 
> 
> 
> My questions: 
> 
> Is there any way to set an LexerExtension in an imported grammar?
> 
> Any idea to fix Java.stg ?
> 
> 
> 
> Claus-Dieter
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list