[Ometa] odd behaviour
al3xgr at gmail.com
Tue Jul 20 09:40:11 PDT 2010
On Wed, Jul 14, 2010 at 8:00 PM, Alessandro Warth <alexwarth at gmail.com>wrot=
> On Wed, Jul 14, 2010 at 11:21 AM, Alexandros Marinos <al3xgr at gmail.com>wr=
>> Hi Alessandro,
>> Thanks for your reply.
>> It appears the problem with the second pair was that I was putting the
>> number on the tree as an integer instead of as a string. Once I removed
>> parseInt() from the producing grammar, both digit+ and [digit+] worked.
> That doesn't compute :) Could you please send me both grammars, so I can
> figure what's going on?
I've been trying to recreate the behaviour, I can't seem to do it. So I've
either lost the exact state of the code that produced this, or I've been
hallucinating. In any case, never mind.
>> Which brings me to my next question: is there a way to match integers
>> other than anything:x ?
> you should be using instead of "anything" if you know that the object that
> you want is a number. This rule is implemented using the anything rule, a=
> a semantic predicate:
> number =3D :x ?(typeof x =3D=3D=3D "number") -> x
> In other words, consume one object from the input stream, make sure that =
> is a number, and if so, return it. (Note that this is not the same thing =
> matching a bunch of characters that together make up the textual
> representation of a number.)
>> Also, playing around with a way to nicely format trees, I realised that
>> a corollary of what you wrote in your last email is that there is no way=
>> differentiate a string from an array (as strings are arrays in js).
> Here is a rule (very similar to the rule above) that matches a string, but
> not an array/list.
> string =3D :x ?(typeof x =3D=3D=3D "string") -> x
numbers, strings, check. This makes a lot of sense, don't know why I didn't
think of it.
> You may want to match the contents of a string, in which case you'll have
> to use a list pattern -- but if you want to make sure that the object you=
> matching is actually a string (not just any kind of list/array), you can =
> the look-ahead operator and a semantic predicate. For example,
> &(:x ?(typeof x =3D=3D=3D "string")) ['a' 'b'* 'c']
> will match a string that starts with an "a", followed by any number of
> "b"s, and is terminated by a "c".
> (It would probably be a good idea to provide a syntactic sugar for writing
> string-matching expressions like the one above -- I'll think about that.)
Thanks a lot for the answers,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the OMeta