inspirer / textmapper

Lexer and Parser generator
http://textmapper.org
MIT License
108 stars 25 forks source link

Report error (or warning) when grammar contains two rules with the same name #15

Open mewmew opened 6 years ago

mewmew commented 6 years ago

I noticed today that the grammar I was writing contained a typo where two different rules had the same name.

From https://github.com/mewmew/l-tm/commit/27348902c0b25e99209f9b78cb7f3f41f74c82af

Prior to this commit AlignStack was defined both as

AlignStack -> AlignStack : 'alignstack' ;

and

AlignStack -> AlignStack : 'alignstack' '=' N=UintLit ;

However, no warning was emitted by Textmapper. This seems like a bug?

What surprised me was that Textmapper did not report any error or warning for this grammar, so it may have gone unnoticed for much longer.

I would like to suggest that Textmapper reports an error or outputs a warning when a grammar contains two rules of the same name. It is quite possible that a valid grammar may contain two rules with the same name for some of the more advanced use cases of Textmapper. Of this, I'm not yet aware. However, in the context of a simple grammar, a warning would be helpful.

Cheers, Robin

inspirer commented 6 years ago

Yes, I agree and will fix this. Originally, I wanted to support the following style of writing productions but in practice it turned out to be very confusing.

a := rule1 ;
a := rule2 ;
mewmew commented 6 years ago

Yes, I agree and will fix this. Originally, I wanted to support the following style of writing productions but in practice it turned out to be very confusing.

Ok, then I understand the background for this. Glad that it will be fixed! It's caused me a bit of confusion thus far.