Case-insensitive matching in Marpa

淺唱寂寞╮ 提交于 2019-12-08 20:29:07

问题


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?


回答1:


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 .



来源:https://stackoverflow.com/questions/17530973/case-insensitive-matching-in-marpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!