[Ometa] odd behaviour

Alexandros Marinos al3xgr at gmail.com
Tue Jul 20 09:40:11 PDT 2010


Hi Alessandro,

On Wed, Jul 14, 2010 at 8:00 PM, Alessandro Warth <alexwarth at gmail.com>wrot=
e:

>
>
> On Wed, Jul 14, 2010 at 11:21 AM, Alexandros Marinos <al3xgr at gmail.com>wr=
ote:
>
>> 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 ?
>>
>
> Javascript doesn't have integers, but OMeta/JS has a rule called "number"
> 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=
nd
> 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 =
it
> is a number, and if so, return it. (Note that this is not the same thing =
as
> 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=
 to
>> 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=
're
> matching is actually a string (not just any kind of list/array), you can =
use
> 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.)
>
> Cheers,
> Alex
>
>
>
Thanks a lot for the answers,
Alexandros
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://vpri.org/pipermail/ometa/attachments/20100720/a215a256/attachme=
nt.htm


More information about the OMeta mailing list