Hello,

I'd like to extract definitions from free text for further processing by 
another grammar. All I care about are the definition sections. I consider all 
lines containing '::=' as the beginning of a definition. A definition section 
ends at either the end of the line, or if there is an opening bracket on the 
first line, at the outermost closing bracket (and might span multiple lines).

Please find my grammar attempt at the bottom.

My bracketed rule does not work. The {p>0}? conditions always fail, and I don't 
have a clue why. This should be able to track the recursion level, but it does 
not work.

What am I getting wrong here?


Thanks,
  András

--- grammar file start ---

grammar specreader;

options { backtrack = true; }

@members {
    int p;
}

start: {p = 0; System.out.println("@line "+p);} line*;
                
line : singleLineDef | multiLineDef | anyline;

anyline : nonlineends LINEEND ;

singleLineDef : nondefines DEFINE nonlbrackets LINEEND ;

multiLineDef : nondefines DEFINE nonlbrackets bracketed nonlineends LINEEND ;

bracketed :  LBRACKET {++p; System.out.println("@bracketed "+p);}
             nonbrackets
             bracketed* {System.out.println("@bracketed after embedded "+p);}
             {p>0}? => RBRACKET {--p; System.out.println("@bracketed after 
RBRACKET "+p);}
             {p>0}? => nonbrackets ;

nonlbrackets : (~LBRACKET)*;

nonbrackets : (~(LBRACKET|RBRACKET))*;

nonlineends : (~('\n'|'\r'))*;

nondefines : (~DEFINE)*;


DEFINE : '::=';

LINEEND : '\n'|'\r'|EOF;

LBRACKET : '{';

RBRACKET : '}';

ANY : .;

--- grammar file end ---

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to