cenotelie / hime

Apache License 2.0
27 stars 4 forks source link

Case insensitive keywords #73

Closed ythri closed 3 years ago

ythri commented 3 years ago

Hey, I wanted to test Hime to write a small parser. However, the language I need to parse is case insensitive: Variable names e.g. do not depend on casing (var, VAR and vAr all refer to the same variable), and same for keywords.

Currently, the way I write my terminals is like this:

FUNCTION -> [fF][uU][nN][cC][tT][iI][oO][nN];

While this should work (I haven't tested my grammar yet), it looks of course ugly. Maybe Hime could introduce a new special syntax for case insensitive keywords? Something like i'function' or similar might work. I assume this would not only clean up my grammar, but could potentially help for other parsers as well. If Hime provides this functionality already, then my apologies, but I couldn't find anything in the reference.

woutersl commented 3 years ago

Hi, yes there is a feature for this use case that works exactly like you mentioned:

FUNCTION -> ~'function';

would work all right. You can see an example in action here.

ythri commented 3 years ago

Perfect, that's exactly what I need. Thanks for the answer and for hime :)