Discussion:
Diagram does not generate right for alternatives
lin q
2012-12-10 04:26:11 UTC
Permalink
Hi,

I am using ANTLR v3.4, I see the same problem in ANTLRWorks and diagram
generated from command line ( maybe they are the same engine). I have the
following grammar snippet:

my_cmd
: 'start'
'match' ('-index' | '-name' | '-value' | '-element' | '-all' | '--')
;

In the diagram, the alternatives show as {'--'..'-name', '-value'}.

Adding backslash to escape '-' does not help.

I verified that this is on diagram only, grammar is still running as
expected.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
Jim Idle
2012-12-10 04:50:42 UTC
Permalink
I think it is just that it is compressing the labels because otherwise it
would be too wide. Additionally, I recommend that you don;t use 'literals'
directly, but create real lexer rules:

IND_OPT : '-index" ;

Additionally, you can be more flexible:

myCmd: START MATCH (MINUS ID {check validity}) * {check presence};

START: 'start';
MATCH: 'match';
MINUS: '-' ;
ID: ('a'..'z')+;

Which means that you can issue better error messages: "xxx is not a valid
option" "At least one of -X -Y -Z must be specified" and so on.

Please note that this list is about to be deleted and ANTLR discussion has
moved to google.
https://groups.google.com/forum/?hl=en&fromgroups=#!forum/antlr-discussion

Questions are now expected to be posted to StackOverflow.


Hope this helps,

Jim
Post by lin q
Hi,
I am using ANTLR v3.4, I see the same problem in ANTLRWorks and diagram
generated from command line ( maybe they are the same engine). I have the
my_cmd
: 'start'
'match' ('-index' | '-name' | '-value' | '-element' | '-all' | '--')
;
In the diagram, the alternatives show as {'--'..'-name', '-value'}.
Adding backslash to escape '-' does not help.
I verified that this is on diagram only, grammar is still running as
expected.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
lin q
2012-12-11 04:37:04 UTC
Permalink
One more finding on this, hope someone can fix it since for beginners like
me, diagram is really good to validate the grammar is what we want or not.
Back to the issue, the following rule has the right diagram generated:

myCmd : 'start' 'match' ('index' | '-name' | '-value' | '-element' |
'-all' | '--') ;

Basically removing the lead '-' at the first alternative makes the trick!

Thanks for the suggestion about not using literals directly, I tried it, it
works, but if the bug could be fixed, it would be great.

Yes, I will post future question at StackOverflow.
Post by Jim Idle
I think it is just that it is compressing the labels because otherwise it
would be too wide. Additionally, I recommend that you don;t use 'literals'
IND_OPT : '-index" ;
myCmd: START MATCH (MINUS ID {check validity}) * {check presence};
START: 'start';
MATCH: 'match';
MINUS: '-' ;
ID: ('a'..'z')+;
Which means that you can issue better error messages: "xxx is not a valid
option" "At least one of -X -Y -Z must be specified" and so on.
Please note that this list is about to be deleted and ANTLR discussion has
moved to google.
https://groups.google.com/forum/?hl=en&fromgroups=#!forum/antlr-discussion
Questions are now expected to be posted to StackOverflow.
Hope this helps,
Jim
Post by lin q
Hi,
I am using ANTLR v3.4, I see the same problem in ANTLRWorks and diagram
generated from command line ( maybe they are the same engine). I have the
my_cmd
: 'start'
'match' ('-index' | '-name' | '-value' | '-element' | '-all' |
'--')
Post by lin q
;
In the diagram, the alternatives show as {'--'..'-name', '-value'}.
Adding backslash to escape '-' does not help.
I verified that this is on diagram only, grammar is still running as
expected.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
Loading...