Ignore-case Grammar

Nov 14, 2012 at 11:24 AM

Hi,

My grammar must ignore-case symbols.

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

Thanks

Coordinator
Nov 14, 2012 at 11:38 AM

Hi,

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:

MYKEYWORD -> K E Y W O R D ;

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

I hope this helps.

Laurent

Nov 14, 2012 at 11:46 AM

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 ? 

Thanks!

Coordinator
Nov 14, 2012 at 11:58 AM

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.

Coordinator
Nov 14, 2012 at 1: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:

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

Nov 14, 2012 at 4:33 PM

Hi,

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.

Coordinator
Nov 14, 2012 at 5:17 PM
Edited Nov 14, 2012 at 5: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 6: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.

 

Coordinator
Nov 16, 2012 at 4: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?