From misodle at yahoo.com Mon Oct 24 14:26:59 2011 From: misodle at yahoo.com (Paul Odle) Date: Mon Oct 24 14:26:22 2011 Subject: [Ometa] newb question - Super Send Message-ID: <1319491619.8947.YahooMailNeo@web161506.mail.bf1.yahoo.com> SW4gdGhlIGV4YW1wbGUgYmVsb3csIEkgYW0gaGF2aW5nIGEgaGFyZCB0aW1lIHVuZGVyc3RhbmRp bmcKdGhlIHN1cGVyIHNlbmQgc3ludGF4CsKgCl5kaWdpdDpkCsKgCldoeSBpcyB0aGUgXiBuZWNl c3Nhcnk/CklzIGRpZ2l0IHNvbWUgYnVpbHQgaW4gd2hpY2ggY29uZmxpY3RzIHdpdGggdGhlIGRp Z2l0IHJ1bGU/CsKgClNvcnJ5IGZvciB0aGUgcXVlc3Rpb24sIGJ1dCBJIHNlYXJjaCB0aGUgbGlz dCBidXQgY291bGRu4oCZdApmaW5kIGFueXRoaW5nIHdoaWNoIHBvaW50ZWQgb3V0IHRoZSBzb2x1 dGlvbiB0byB0aGlzIHF1ZXJ5LgrCoApJIGFtIHRlc3Rpbmcgd2l0aCB0aGUgb25saW5lIE9tZXRh L0pTIGRlbW8gc2l0ZSBhdCBodHRwOi8vd3d3LnRpbmxpenppZS5vcmcvb21ldGEtanMvI09NZXRh X1R1dG9yaWFsCsKgCk1vc3Qgb2YgdGhlIGJlbG93IG1ha2VzIHNlbnNlIHRvIG1lIChpbiByZWxh dGlvbiB0byBzYXkgQU5UTFIgb3IgR29sZFBhcnNlciksIGJ1dCB0aGUgXiBoYXMgbWUgc3R5bWll ZC4gSSBoYXZlIHJlYWQgdGhlIE9tZXRhIFBhcGVyIGFuZAp3aGF0IGRvY3VtZW50YXRpb24gSSBj b3VsZCBmaW5kLCBidXQgaXQgaXNu4oCZdCBtYWtpbmcgYW55IHNlbnNlIHRvIG1lLgrCoApJZiBh bnlvbmUgY291bGQgcHJvdmlkZSBhbnkgaGVscCBJIHdvdWxkIGJlIGdyYXRlZnVsLgrCoApUaGFu a3MsClBhd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tIG5leHQgcGFydCAtLS0tLS0tLS0tLS0tLQpBbiBIVE1MIGF0dGFjaG1lbnQgd2Fz IHNjcnViYmVkLi4uClVSTDogaHR0cDovL3Zwcmkub3JnL3BpcGVybWFpbC9vbWV0YS9hdHRhY2ht ZW50cy8yMDExMTAyNC80ZDY0ZWI1Zi9hdHRhY2htZW50LTAwMDEuaHRtCg== From yoshiki at vpri.org Mon Oct 24 14:52:12 2011 From: yoshiki at vpri.org (Yoshiki Ohshima) Date: Mon Oct 24 14:51:35 2011 Subject: [Ometa] newb question - Super Send In-Reply-To: <1319491619.8947.YahooMailNeo@web161506.mail.bf1.yahoo.com> References: <1319491619.8947.YahooMailNeo@web161506.mail.bf1.yahoo.com> Message-ID: At Mon, 24 Oct 2011 14:26:59 -0700 (PDT), Paul Odle wrote: > > In the example below, I am having a hard time understanding the super send syntax > > ^digit:d > > Why is the ^ necessary? It is subtle but the author's intention must be that he wants to get numbers from the 'digit' rule and the 'number' rule. The super version returns string so this one trys to convert it to number by calling digitValue(). But it is true that in the expression 'n * 10 + d', 'n' and 'd' can be either string or number and the result is always number because of the JavaScript coersion. In that sense, the super rule here is not strictly necessary, but it is still nice to align the types involed in a parser. -- Yoshiki From misodle at yahoo.com Mon Oct 24 15:22:14 2011 From: misodle at yahoo.com (Paul Odle) Date: Mon Oct 24 15:21:36 2011 Subject: [Ometa] newb question - Super Send In-Reply-To: References: <1319491619.8947.YahooMailNeo@web161506.mail.bf1.yahoo.com> Message-ID: <1319494934.85270.YahooMailNeo@web161516.mail.bf1.yahoo.com> Yoshiki, Thanks for the response! This is one of the shipped examples for the site. I copied it into my own s= cript and it runs fine. http://www.tinlizzie.org/ometa-js/#hsarcog02 My confusion is that if I remove the ^ then I get an error message=A0 **************** * =A0Oops! =A0 =A0 =A0 =A0 =A0 =A0 =A0* =A0 =A0 =A0 =A0 =A0 =A0 <=3D=3D=3D = pop up * =A0match failed =A0 =A0 =A0* **************** so it appears to be required in this implementation. Why escapes me. The sc= ript looks very straight forward. It is very comparable to other BNF form g= rammar's I have seen in the past. I will keep working on this. Regards, Paul Odle -------------- next part -------------- An HTML attachment was scrubbed... URL: http://vpri.org/pipermail/ometa/attachments/20111024/1b07d4b2/attachme= nt.htm From yoshiki at vpri.org Mon Oct 24 15:27:59 2011 From: yoshiki at vpri.org (Yoshiki Ohshima) Date: Mon Oct 24 15:27:26 2011 Subject: [Ometa] newb question - Super Send In-Reply-To: <1319494934.85270.YahooMailNeo@web161516.mail.bf1.yahoo.com> References: <1319491619.8947.YahooMailNeo@web161506.mail.bf1.yahoo.com> <1319494934.85270.YahooMailNeo@web161516.mail.bf1.yahoo.com> Message-ID: At Mon, 24 Oct 2011 15:22:14 -0700 (PDT), Paul Odle wrote: > > Yoshiki, > > Thanks for the response! > > This is one of the shipped examples for the site. I copied it into my own script and it runs fine. > > http://www.tinlizzie.org/ometa-js/#hsarcog02 > > My confusion is that if I remove the ^ then I get an error message > > **************** > * Oops! * <=== pop up > * match failed * > **************** > > so it appears to be required in this implementation. Why escapes me. The script looks very straight forward. It is very comparable to other BNF form grammar's I have seen > in the past. > > I will keep working on this. A rule such as: digit = digit:d -> d.digitValue(), cannot work as it has "no way out" (i.e., the base case for left-recursion). 'digit' on the right hand refers to itself, so 'apply' detects that it is making no progress while it is applying the same rule again. -- Yoshiki From l at loup-vaillant.fr Tue Oct 25 05:46:18 2011 From: l at loup-vaillant.fr (Loup Vaillant) Date: Tue Oct 25 05:47:30 2011 Subject: [Ometa] Array concatenation in OMeta/JS Message-ID: <4EA6AF9A.4010406@loup-vaillant.fr> (sorry if there is a duplicate, I originally sent it from a wrong address) Hello, I am currently learning OMeta. While doing it, I am I am trying to make a JSON parser: http://www.tinlizzie.org/ometa-js/#JSON At the bottom of the source, you will see that I hit a snag: when I try to print an array, I get [true][[num, 42], [str, foo]] instead of [[true], [num, 42], [str, foo]] Apparently, the culprit is the 'listOf' rule: listOf :p = apply(p):e ("," apply(p))*:r -> ([e] + r) My (weak) understanding of JavaScript tells me that the '+' operator is supposed to concatenate the two arrays. Apparently, OMeta/JS does something different. So my questions are: - What does the '+' operator actually return when I apply it to two arrays? - Whow can I make an array out of an element and an array? - (bonus) I will have similar problems with the object rule. I don't want an array of key:value pairs, I want a JavaScript object, as JSON was originally intended (so I can claim I have implemented a full JSON parser). Thanks, Loup. From pjgazzard at googlemail.com Tue Oct 25 06:31:16 2011 From: pjgazzard at googlemail.com (Page) Date: Tue Oct 25 06:30:58 2011 Subject: [Ometa] Array concatenation in OMeta/JS In-Reply-To: <4EA6AF9A.4010406@loup-vaillant.fr> References: <4EA6AF9A.4010406@loup-vaillant.fr> Message-ID: When you do + on two arrays it seems to convert them both to strings and then concatenate those strings, so "[true][[num, 42], [str, foo]]" as a string rather than an array, to do concatenation you would want to do [e].concat(r), in this case you could also do {r.unshift(e); r} to add e to the start of the array (returns new length) then return r afterwards for ometa. There is also the option to do [e, r] to put them into an array, but the second element would just be the r array (but I don't think that's what you want?) For the javascript object you can use: key_value =3D "str":s ":" value:v -> {obj =3D {}; obj[s[1]] =3D v[1]; obj= }, This creates obj as a javascript object, then it assigns the value to the key and then returns the object, we can't do it in one as you cannot have dynamic keys in a static object initialisation. I use the braces {} as it allows you to put multiple javascript statements and it will just use the return value of the final one. I hope this is helpful, Pagan On 25 October 2011 13:46, Loup Vaillant wrote: > (sorry if there is a duplicate, I originally sent it from a wrong address) > > Hello, > > I am currently learning OMeta. While doing it, I am I am trying to > make a JSON parser: http://www.tinlizzie.org/**ometa-js/#JSON > > At the bottom of the source, you will see that I hit a snag: when I > try to print an array, I get > > [true][[num, 42], [str, foo]] > > instead of > > [[true], [num, 42], [str, foo]] > > Apparently, the culprit is the 'listOf' rule: > > listOf :p =3D apply(p):e ("," apply(p))*:r -> ([e] + r) > > My (weak) understanding of JavaScript tells me that the '+' operator is > supposed to concatenate the two arrays. Apparently, OMeta/JS does > something different. > > So my questions are: > > - What does the '+' operator actually return when I apply it to two > arrays? > > - Whow can I make an array out of an element and an array? > > - (bonus) I will have similar problems with the object rule. I don't > want an array of key:value pairs, I want a JavaScript object, as > JSON was originally intended (so I can claim I have implemented a > full JSON parser). > > Thanks, > Loup. > > ______________________________**_________________ > OMeta mailing list > OMeta@vpri.org > http://vpri.org/mailman/**listinfo/ometa > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://vpri.org/pipermail/ometa/attachments/20111025/9aa33f3f/attachme= nt.htm From l at loup-vaillant.fr Tue Oct 25 08:35:17 2011 From: l at loup-vaillant.fr (Loup Vaillant) Date: Tue Oct 25 08:36:35 2011 Subject: [Ometa] Array concatenation in OMeta/JS In-Reply-To: References: <4EA6AF9A.4010406@loup-vaillant.fr> Message-ID: <4EA6D735.2050104@loup-vaillant.fr> It Works! Thank you very much, that was most helpful. I think the JSON parser is finished, I left it here: http://www.tinlizzie.org/ometa-js/#JSON I didn't think about the string conversion, that really confused me. I have chosen [e].concat(r) over {r.unshift(e); r} because of its more functional feel (efficiency be dammed). Thanks for telling me about both, though. I followed your advice for object creation, but in the 'object' rule instead of the 'key_value' rule. I note that I cannot use the for_each style loop ("for (var i in array)") without looping over the methods of the array themselves. It looks like arrays are just objects. Hmm, I can see where Lua tables come from, now. Thanks again, Loup. From: Page > When you do + on two arrays it seems to convert them both to strings and > then concatenate those strings, so "[true][[num, 42], [str, foo]]" as a > string rather than an array, to do concatenation you would want to do > [e].concat(r), in this case you could also do {r.unshift(e); r} to add e > to the start of the array (returns new length) then return r afterwards > for ometa. > There is also the option to do [e, r] to put them into an array, but the > second element would just be the r array (but I don't think that's what > you want?) > For the javascript object you can use: > key_value = "str":s ":" value:v -> {obj = {}; obj[s[1]] = v[1]; obj}, > This creates obj as a javascript object, then it assigns the value to > the key and then returns the object, we can't do it in one as you cannot > have dynamic keys in a static object initialisation. I use the braces > {} as it allows you to put multiple javascript statements and it will > just use the return value of the final one. > > I hope this is helpful, > Pagan > > On 25 October 2011 13:46, Loup Vaillant > wrote: > > (sorry if there is a duplicate, I originally sent it from a wrong > address) > > Hello, > > I am currently learning OMeta. While doing it, I am I am trying to > make a JSON parser: http://www.tinlizzie.org/__ometa-js/#JSON > > > At the bottom of the source, you will see that I hit a snag: when I > try to print an array, I get > > [true][[num, 42], [str, foo]] > > instead of > > [[true], [num, 42], [str, foo]] > > Apparently, the culprit is the 'listOf' rule: > > listOf :p = apply(p):e ("," apply(p))*:r -> ([e] + r) > > My (weak) understanding of JavaScript tells me that the '+' operator is > supposed to concatenate the two arrays. Apparently, OMeta/JS does > something different. > > So my questions are: > > - What does the '+' operator actually return when I apply it to two > arrays? > > - Whow can I make an array out of an element and an array? > > - (bonus) I will have similar problems with the object rule. I don't > want an array of key:value pairs, I want a JavaScript object, as > JSON was originally intended (so I can claim I have implemented a > full JSON parser). > > Thanks, > Loup.