This project is read-only.

Ignore-case Grammar

Nov 14, 2012 at 12:24 PM


My grammar must ignore-case symbols.

Can I do this? Which options are used for this?


Nov 14, 2012 at 12:38 PM


I'm afraid there is no easy way for this at this time.

I understand you mean that the keywords of your language must be case insensitive. One way to work around the limitation is to add the following lexical rules in the "terminals" section of your grammar:

A->[aA]; B->[bB]; ... Z->[zZ];

These rules define case-insensitive symbols for each of the 26 letters.

Then, in the same "terminals" section, instead of writing the following for the definition of your keywords

MYKEYWORD -> 'keyword';

you would write:


I admit this is not an elegant solution to your problem but it should work.

I hope this helps.


Nov 14, 2012 at 12:46 PM

Laurent, thanks for your quick reply

Yes, this is not good solution )

Can I hope that in not far future you will add a new option for control case-sensitivity in the grammar ? 


Nov 14, 2012 at 12:58 PM

Would you prefer to write something like

MYKEYWORD -> ~'keyword';

where the ~ symbol would be used to specify that the following string is case-insensitive ?

An option for the whole grammar would be good also.

Nov 14, 2012 at 2:04 PM

This feature will then probably be included in the next release. In the meantime, you can still download and build the sources in the "Casing" branch, which implements the specification of case-insensitive strings in both lexical and syntactic rules. So you can write:

{ MYWEYWORD -> ~'keyword'; }
{ stuff -> ~'another-stuff'; }
You shouldn't have particular problems building the sources using VS or any other environment.

Nov 14, 2012 at 5:33 PM


I think what the best solution is the case when a global option (for grammar) are added.

For example

options {
	CaseSensitive = "False";

The first case when case sensitive is controlled for each terminal to lead to clutter of the text.

Nov 14, 2012 at 6:17 PM
Edited Nov 14, 2012 at 6:22 PM

This is now implemented as you example above. The feature has been integrated into the default branch so you can just checkout this one

EDIT: note that the case sensitiveness only applies to strings (note 'mystring') and not to character classes (noted [a-zA-Z]), unicode classes, etc. The rationale is that character classes already allow you to specify both the lower and upper cases, and the other constructions are character spans that would lose their semantics.

Nov 15, 2012 at 7:07 AM

Hi, Laurent!

Now I tried to write my grammar with the CaseSensitive = "false" option. It doesn't work :-) 

So, for example, when I try parse For or FOr or foR etc.  I get an parser exceptions.


Nov 16, 2012 at 5:43 AM

Hi, I'd like to help you; but without the exception it is difficult :-)

The unit tests I have written for this feature works, so if possible, could you send me your grammar so I can test it on my end and see what could be wrong?