[Ometa] matching parameter values as literals

Mark J. Nelson mnelson at cc.gatech.edu
Wed Aug 4 22:14:10 PDT 2010


Excellent, thanks! In retrospect both cases make perfect sense. Somehow =

I had gotten confused into thinking 'exactly' meant "succeed only if the =

entire remaining input is equal to 'x'". And in the second case I did =

indeed mix up matching on strings versus on a sequence of chars.

-Mark


On 08/04/2010 07:26 PM, Alessandro Warth wrote:
> Hi Mark,
>
>     Is there a way for a rule to take a parameter and match its value
>     against the input stream? I know apply(param) will take the
>     parameter and match the rule *named* param, but how do I match the
>     actual value of param as if it were a literal?
>
>
> Yep, that's what the "exactly" rule is for. For example, exactly(5) =

> will succeed if the next object on the input stream is a 5, and fail =

> otherwise.
>
>     For example, take the following contrived rule schema:
>     num42toA =3D 42 -> 'A'
>     num43toB =3D 43 -> 'B'
>
>     If some function literal(x) existed, one might generalize a
>     higher-order rule:
>     num integer:x char:result =3D literal(x) -> result
>
>
> That's just right, except you should use "exactly" instead of "literal".
>
>     Of course, this particular example could be rewritten in more of a
>     generate-and-test style, with a match against integer:y followed
>     by ?(y =3D=3D x), but I'm wondering if there's a way to do it
>     directly. The built-in 'token' function looks like it must do this
>     for strings, but alas, it's hand-coded in Javascript in parser.js,
>     not in OMeta syntax.
>
>     If my literal() function existed, I'd imagine 'token' would be
>     defined as:
>     token string:t =3D spaces* literal(t) -> t
>
>
> Not quite. This would match a string on the input stream, but what you =

> want in this case is to match a sequence of characters, So "token" is =

> actually implemented like this:
>
>     token :x =3D spaces seq(x)
>
>
> (BTW, "spaces" is already equivalent to space*, so it shouldn't be =

> followed by a Kleene-*)
>
> Cheers,
> Alex
>
>     Does such a function exist and I'm just missing it? Or am I on the
>     wrong track here?
>
>     Thanks,
>     Mark
>
>     P.S. - Apart from still working out all the details, and
>     attempting to get somewhat proficient at debugging grammars (i.e.
>     more proficient than not at all), I'm quite liking OMeta so far.
>
>     -- =

>     Mark J. Nelson | http://www.cc.gatech.edu/~mnelson/
>     <http://www.cc.gatech.edu/%7Emnelson/>
>     Researcher, Expressive Intelligence Studio, UC Santa Cruz
>     PhD student, School of Interactive Computing, Georgia Tech
>
>
>     _______________________________________________
>     OMeta mailing list
>     OMeta at vpri.org <mailto:OMeta at vpri.org>
>     http://vpri.org/mailman/listinfo/ometa
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://vpri.org/pipermail/ometa/attachments/20100804/3a345000/attachme=
nt.htm


More information about the OMeta mailing list