newline with scope block

12 views
Skip to first unread message

Neo

unread,
Mar 26, 2018, 11:18:07 PM3/26/18
to antlr-discussion
Hi all.

I have following grammar:
WS: (' ' | '\t') -> skip;
NEWLINE
: [\n]+;

prog
: instList? EOF;
instList
: (instr NEWLINE+)+;
operator1
: 'op1';
operator2
: 'op2';
blockOperator
: 'block';
instr
: Identifier (operator1 | operator2) Identifier
     
| blockOperator '{' instList? '}'
;


Examples of my language:
a op1 b
c op2 a
block {
    d op2 a
    a op1 b
    ...
}

block {} // also allowed

But Antlr doesn't handle block greedy. It consider that
blockOperator '{' instList? '}'
instList is empty and add missing on '}'.

Any suggestion?


Reply all
Reply to author
Forward
0 new messages