[Cuis-dev] Regarding Ometa2

Phil B pbpublist at gmail.com
Fri Jul 5 02:49:01 PDT 2019


On Fri, Jul 5, 2019 at 3:48 AM Philip Bernhart via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Hi,
> I don't understand the way OMeta2 matches this rule:
> scheme =
>   letter (letter | digit | $+ | $- | $. )*)
> when used in this way:
>   UriParser matchAll: 'http' with: #scheme => anOrderedCollection($t $t
>   $p)
> why does it forget the $h?
By default, an OMeta rule (method) will return the last match.  In your
example it will be the parenthesized expression so the first letter will
appear to be ignored when if fact it wasn't: you didn't tell OMeta to do
anything with it so it just matched it and moved on.  To use the contents
that were matched, you want to use the 'consumed by' operator which is just
to enclose the expression you're interested in with angled brackets like so:

scheme =
 <letter (letter | digit | $+ | $- | $. )*)>

or you could save the consumed contents to a variable for use in a semantic
predicate or action later:

scheme =
 <letter (letter | digit | $+ | $- | $. )*)>:foundScheme

(Note: there's also an 'index consumed by' variant which uses @<...> syntax
and you can nest them to get both)

> Also why does OMeta2 sometimes cause an endless loop within the
> image with showing an hourglass as cursor without being able
> to quit that with ALT-. / CMD-. ?

That's almost always due to a 'bad' parser specification.  In practice,
it's usually a * or ? in your source code that results in zero occurrences,
as a result the overall rule succeeds and then gets stuck in a recursive
loop matching that same rule until you OOM.  An easy way to detect this
type of problem (and not hang your image) is to load the OMeta2Extensions
package and have your parser be a subclass of OMeta2Debug while you are
developing.  Once everything is working, then change the parent class back
to OMeta2 which should be otherwise transparent as far as your parser code
is concerned.

> When building parsers which package should be used PetitParser or
> OMeta?
> What do you think?

I use OMeta almost exclusively so obviously would recommend it.  As far as
which is right for you, it depends on what you're trying to do / looking
for.   If you are just going to be munging data files, Petit will probably
be easier to use and offer better runtime performance.  If you're looking
for leverage in developing DSLs, have larger (in scope) projects and/or
have lots of permutations of your parsers, I'd say OMeta is the way to go.
My thumbnail comparison would be that Petit is more conventional and easier
to use while OMeta is more powerful and general.

> Thanks,
> Philip
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20190705/943931fe/attachment.htm>

More information about the Cuis-dev mailing list