[antlr-interest] is it a bug, or am I too stupid?

Markus Kuhla bace.spam at gmx.net
Fri Apr 27 23:29:58 PDT 2007


Hi everybody,

Please can you help me with this problem on the following grammar:

- I have a separator **** on a single line (blanks before and after are optinal).
- The * is also used for the bullets, they have to be placed at the beginning of the line, followed by some text.
So I tried to use the backtrack- and lookahead-option, but it won't work. 
I tried to define 4 asterisks as one lexer rule, but when I have only 2 asterisks in the input, he wants to have 2 futher asterisk which won't match (here too, backtrack helps not)

Using this grammar and this input, the parser will match the separator **** only as a nested bullet item.

////////////////////////////////////////////////////////////////
grammar ambg;

ASTERISK          :    '*';
NEWLINE           :    (('\r')? '\n' | '\r');
BLANKS            :    (' ' | '\t')+;
ELSE              :    .;


page              :    (page_element)+;

page_element options {k=6; backtrack=true; memoize=true;}
                  :    (separator | bullet_hierarchie) newline;

separator         :    (BLANKS)? ASTERISK ASTERISK ASTERISK ASTERISK (BLANKS)? NEWLINE;

bullet_hierarchie :    (bullet_item  newline)+;

bullet_item       :    ASTERISK  content;

content           :    ASTERISK  content
                  |    text;

text              :    ~(NEWLINE | ASTERISK)+;
    
newline           :    NEWLINE | EOF;
/////////////////////////////////////////////////////////////////

the input is:
*1
**2
*** 3
****      4
*****       5
******6
**7
*8
****


Strange is (for me) that if I insert a newline before the separator in the last inputline then it works.
If I forgot any important information for you, please let me know, this is really important for me.
Thanks everybody for reading and I hope you can give me a hint (I am searching a solution for some days now :-( )
Markus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070428/f5e1bb83/attachment.html 


More information about the antlr-interest mailing list