[Ometa] dictionary matching
Andrey Fedorov
anfedorov at gmail.com
Mon Nov 30 08:42:08 PST 2009
Personally, I'd implement this on top of a typical JS
walk<http://gist.github.com/245541>separate from OMeta.
If you insist, I would implement that in OMeta by defining a bijection
(translation back-and-forth) between:
{ Foo : ["abc", "xyz"], Baz : 123 }
and
[`Foo ["abc" "xyz"] `Baz 123]
(even elements are keys, odd elements are values), and match on that. Still
haven't been able to match on deep list structures, so am leaning towards
impossible, but again, I've not very much experience with OMeta.
Sorry for the slow response, hope this helps!
Cheers,
Andrey
On Mon, Nov 23, 2009 at 12:54 PM, Justin Chase <justin.m.chase at gmail.com>wr=
ote:
> Ok let me try to expand my example there:
>
> Example =3D { Foo =3D [Bar*]:e } -> { Example : e }
> Bar =3D 'a'..'z'+;
>
> Example ( { Foo : ["abc", "xyz"] } ) -> { Example : ["abc", "xyz"] }
> Example ( { Baz : 123 } ) -> FAIL
> Example ( { Foo : [], Baz : 123 } ) -> { Example : [] }
>
> So { } indicates an object (like json) and Field : Value are the various
> fields of the object. I'm wondering about how to match objects with speci=
fic
> fields or what not. What you might see in reality might be more like:
>
> { Type : "MethodInvokeExpression",
> Reference : { Type : "MemberReference",
> Reference : { Type : "MemberReference",
> Name =3D "x" },
> Name : "y" },
> Parameters =3D [{ Type =3D "VariableReference", Name =3D "foo" }, true,=
123] }
>
> So suppose you have some object structure like that and you want to "visi=
t"
> it? Meaning for each object you want to transform it into something else?=
I
> mean it's the same idea as with the nested arrays except here we're talki=
ng
> about nested dictionaries. The ordinal of the field is not necessarily
> guaranteed but they are named. So what is the best way to allow matching =
on
> the left hand side of objects?
>
>
> On Mon, Nov 23, 2009 at 10:53 AM, Andrey Fedorov <anfedorov at gmail.com>wro=
te:
>
>> I've only seen OMeta matching on lists. From some quick playing around
>> with the tutorial <http://www.tinlizzie.org/ometa-js/#OMeta_Tutorial>, I
>> couldn't get match rules with nested lists to work, but I'm pretty new w=
ith
>> OMeta. That said, a rule matching on trees can be translated into a coup=
le
>> of rules matching lists, which might also have the benefit of performance
>> guarantees.
>>
>> I'm not sure if I'm following your example, could you give an example of
>> an object matching your given rule?
>>
>> Cheers,
>> Andrey
>>
>> On Mon, Nov 23, 2009 at 11:18 AM, Justin Chase <justin.m.chase at gmail.com=
>wrote:
>>
>>> Hello,
>>>
>>> I have been reading over some of the OMeta documentation and I have a
>>> question. I understand that OMeta can specifically be used to author a
>>> visitor but a lot of visitors will typically be over an object tree and=
I'm
>>> wondering if there is syntax for this? I'm not really seeing this, all =
that
>>> I see are grammars for visiting arrays. Has there been any thought on t=
his?
>>>
>>> I know javascript has an object notation so this seems like it could be=
a
>>> good fit. I was picturing something like:
>>>
>>> Example =3D { Foo =3D [Bar*]:e } -> { Example : e }
>>>
>>> Which is to say the left hand is matching an object with a field named
>>> Foo with value that matches [Bar*] and is assingned to the parameter e.=
It
>>> is then projected as an object with a field set to the value projected =
into
>>> e. Is there already a notation for this, and if not what is the reason =
not
>>> to have it?
>>>
>>> Thanks!
>>>
>>> --
>>> Justin Chase
>>> http://www.justnbusiness.com
>>>
>>> _______________________________________________
>>> OMeta mailing list
>>> OMeta at vpri.org
>>> http://vpri.org/mailman/listinfo/ometa
>>>
>>>
>>
>
>
> --
> Justin Chase
> http://www.justnbusiness.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://vpri.org/pipermail/ometa/attachments/20091130/4b98c067/attachme=
nt.htm
More information about the OMeta
mailing list