[Ometa] Case-insensitive seq?

Frank Shearar frank.shearar at angband.za.org
Fri Dec 19 03:44:32 PST 2008


"Frank Shearar" <frank.shearar at angband.za.org> writes:

> I've been writing an Ometa parser for the Delphi language.
>
> Up to now, I've been using a copy of the OSqueakParser>>token production
> (token :xs ::= <spaces> <seq xs>). Delphi is, however, a case insensitive
> kind've language. Thus, when I write <token 'integer'> in a production,
what
> I really want is to accept "Integer" or "INTEGER" or any other permutation
> of case.
>
> I've tried a number of things but haven't found anything that works:
> * hacked a seqNoCase starting from a duplicate of Ometa>>seq
> * using something like <spaces> <char>+:s ?[(String withAll: s)
asLowercase
> = (String withAll: xs) asLowercase] => [String withAll: s]
>
> I've run out of steam trying to figure out this problem, so I thought I'd
> try here :) Any ideas on how to accept a sequence that matches some input
> (of character), without regard to case?

Here's an ugly solution:

exactlyNoCase :want ::=
    <anything>:got ?[want asLowercase = got asLowercase] => [want]

seqNoCase
    | xs |
    ^ self oAnd: {
        [xs := self apply: #anything].
        [xs do: [:x |
            (self apply: #exactlyNoCase withArguments: {x}) = Fail
                ifTrue: [^ Fail]]].
        [xs]
    }

If anyone has a better solution, I'm all ears!

frank




More information about the OMeta mailing list