World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Ladislav 15-Sep-2010 [5190x5] | Sorry if you find it nitpicking, but I wanted to point out, that an assumption that "parse variables are safe for recursion rules" should be wrong exactly because there are only variables in REBOL, which the interpreter does not have any reason to make "recursion safe" unless you specifically do something about it. |
Regarding the above "three different variable types" - as far as the interpreter is concerned, there is no difference between the 'start 'end and 'copy variables. You used them in a specific way, but, later, you can very well use another expression, where you write: user: copy start to "whatever" etc. So, you can easily see, that neither the 'start nor the 'user variable has any "variable type" you could infer based upon their usage in one specific expression. | |
err, I meant the 'start 'end and 'user variables | |
if you call 'temp a "rebol level variable" in the above example expression, how would you call it in the expression below? (temp: either 1 > 0 [none] [[end skip]]) temp | |
So, generally speaking, it may be useful for you to use some some variables only as "markers", but that "variable type" is something you impose just to make the things easy for you to handle. The interpreter does not (and should not) make such distinctions. | |
Pekr 15-Sep-2010 [5195] | temp is "rebol level variable", whose value is bound to parse dialect :-) |
Ladislav 15-Sep-2010 [5196x2] | Hmm, what does the "bound" word mean? |
As I said, you can use some variables for specific purposes only, but that is your decision, and is not supported by any interpreter property, and certainly is not useful for all purposes. I may want to use some variables in more "roles" than you want to. | |
Pekr 15-Sep-2010 [5198x2] | hmm, then maybe not. Temp following the paren simply refers to the rule, resulting from previous paren expression evaluation .... |
and hence is probably a regular rebol level word, just used inside the parse dialect? | |
Ladislav 15-Sep-2010 [5200] | In my opinion, all of the above 'start 'end 'user and 'temp words are "regular" REBOL words, while e.g. the 'copy word above is actually a parse dialect keyword |
Pekr 15-Sep-2010 [5201x2] | corret ... |
and - it was not nitpicking on your part - using the correct terminology where possible is important, as it helps to correctly interpret the way in which the language works. It is just lack of knowledge on my part, that I confuse the terms ... exactly because I often don't understand the internals ... | |
Izkata 15-Sep-2010 [5203] | start: :end and temp: would just be called set-words and get-words, either within the Parse dialect or the Do dialect (Do dialect being "rebol level") |
Anton 15-Sep-2010 [5204] | To be even more precise; The 'copy word above is also a "regular" rebol word (it just happens, additionally, to be interpreted by PARSE as a keyword in the PARSE dialect). |
Ladislav 15-Sep-2010 [5205] | Re start: and :start e.g. - they are values of different datatypes, but can be seen as just one variable. |
Ladislav 16-Sep-2010 [5206] | http://www.rebol.org/view-script.r?script=use-rule.rupdated. Changes: now it implements both USE-RULE variants as described in http://www.rebol.net/wiki/Parse_Project . |
Ladislav 18-Sep-2010 [5207x6] | Hi, I rewrote http://www.fm.tul.cz/~ladislav/rebol/evaluate.rto contain slightly more comments and to use the USE-RULE function, so that it now became a more complex example of its usage. |
I hope everyone struggling with local variables in PARSE to find this a much more comfortable way. | |
On the other hand, I expect the %evaluate.r to have a value of its own, since it shows how to handle expressions using PARSE, while being able to respect different priority/associativity rules sets. | |
The funny thing about it is, that just one local variable per parse rule was quite sufficient in this case, although the example isn't trivial in my opinion. | |
http://en.wikibooks.org/wiki/REBOL_Programming/Language_Features/Parse#Local_variables_in_parse_rules , a new subsection in the REBOL Programming wikibook. | |
http://en.wikibooks.org/wiki/REBOL_Programming/Language_Features/Parse#Local_variables_in_parse_rules a new section in the REBOL Programming wikibook | |
Janko 18-Sep-2010 [5213] | wowo, most awesome Ladislav! |
Ladislav 18-Sep-2010 [5214x2] | Pekr, knowing that you were interested in the subject as well, I sincerely hope, that you read the wikibook subsection, run the examples, and let me know what you are missing in the doc and in the functionality. |
thanks, Janko | |
Claude 20-Sep-2010 [5216x4] | hi, i would you to parse a string like this {number: 123456 name: abcd message: i like rebol} |
i would like to use parse to do it | |
something like this way parse mystring ["number:" number: "name:" name: "message:" msg:]] | |
a get number, name and msg . is that possible ? and how ? | |
Maxim 20-Sep-2010 [5220] | is the data guaranteed to be rebol compatible? (you can use 'LOAD on it and it will never return an erro) |
Claude 20-Sep-2010 [5221x3] | but mystring is like this {Number : 10017 Name : Disable Message Partner Application: MXS Severity : Info Type : Alarm Event Date-Time : 20/09/10 12:39:43 GMT : Mon Sep 20 10:39:43 2010} |
i start to use => parse mystring [thru "Number :" number: to end] | |
i would like to do => parse mystring [thru "Number :" number: to "Name :" ] but this don't work !!!!] | |
Maxim 20-Sep-2010 [5224x4] | using 'TO or THRU rules is garanteed to make you life a nightmare for arbitrary string parsing, unless its very linear in content. |
isn't there a rebol string parser on rebol.org which has the basic parsing rules to filter out rebol data? | |
with a few search I didn't zero-in on it, but I seem to recall seeing that before. | |
otherwise, you can just do a line by line parsing, filtering out "keywords" at the start and then loading the data after the ":" | |
Claude 20-Sep-2010 [5228x2] | if i can't use parse i will do this |
but it is very strange. i heard that parse is very powerfull. and now i can't use it because if to difficult !!!! | |
Maxim 20-Sep-2010 [5230] | parse is very powerfull and easy to *use* but *mastering* it isn't. |
Janko 20-Sep-2010 [5231] | [thru "Number :" copy number [ to newline | to end ] ] maybe? |
Maxim 20-Sep-2010 [5232x2] | although it is much more approachable than regexp in certain ways. |
here is an overblown example, with lots of extra prints, so you can see it running... it parses your above example text. -------------------------------- rebol [] data: {Number : 10017 Name : Disable Message Partner Application: MXS Severity : Info Type : Alarm Event Date-Time : 20/09/10 12:39:43 GMT : Mon Sep 20 10:39:43 2010} ; rules token: ["Number" | "Name" | "Severity" | "Type" | "Date-Time" | "GMT" | "Application"] space: charset " ^-" spaces: [any space] content: complement charset "^/" ; all but newlines. contents: [some content] ; used as variables in the rules v-token: none v-content: none parse/all data [ some [ ( print "^/0>" ) copy v-token token ( print "1>" probe v-token ) spaces ; ignore ( print "2>" ) ":" ; end of token ( print "3>" ) spaces ; ignore ( print "4>" ) copy v-content contents ;grab all but newline ( print "5>" probe v-content ) [ ; this is important, it ensures that you've got a whole line. [some "^/"] | end ] ( print "6>" ) ( ; do something with your data here ?? v-token ?? v-content ) ] ] probe "." ask "done" | |
Claude 20-Sep-2010 [5234] | thank you i will test it and try to understand too ;-) |
Maxim 20-Sep-2010 [5235] | I made it easy for you to figure out (at least as easy as can be ;-) |
Claude 20-Sep-2010 [5236x2] | Maxim here the result |
0> 1> Number 2> . done | |
Maxim 20-Sep-2010 [5238] | using which rebol? I did run it through and it worked ok on 2.7.7 |
Claude 20-Sep-2010 [5239] | it stop at ":" !!! |
older newer | first last |