Search code examples
regexcase-insensitivemarpa

Case-insensitive matching in Marpa


Related to my earlier question about case-insensitive keyword matching using regular expressions.

Is it possible to match strings case-insensitively in Marpa? If so, how?

Suppose I have the grammar

:start ::= script
identifier ~ [\w]+
script ::= 'script' identifier code
code ::= command*
command ::= 'run' | 'walk' | 'stop'

How can I make it match any of script, Script, SCRIPT or any other combination of lower and uppercase letters?


Solution

  • There isn't a straightforward way to specify case-insensitivity. Of course, you can string together character classes: [sS] [cC] [rR] [iI] [pP] [tT], but that's pretty awkward.

    Sorry. Case-insensitive strings would be a good feature to add.

    UPDATE: As of 2.076000, the latest indexed release, Marpa::R2 now has an :ic modifier for both strings and character classes, making them case-insensitve. In the docs, see https://metacpan.org/pod/Marpa::R2::Scanless::DSL#Single-quoted-strings and https://metacpan.org/pod/Marpa::R2::Scanless::DSL#Character-classes .