r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

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
[5239x2]
it stop at ":" !!!
2.7.7.4.2
Steeve
20-Sep-2010
[5241]
Much easier with R3.
assuming, 
>> src: {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}

then, 


>> construct parse copy src [return while[and[some #" " #":"] remove[some 
#" "]| skip]]
== make object! [
    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"
]
Claude
20-Sep-2010
[5242x2]
thank you steeve but i need it for a production server  to parse 
log file for nagios
i would prefer to use rebol 2
Maxim
20-Sep-2010
[5244]
claude it might be because of copy/pasting... you are on linux.. 
did you just copy the code and paste it into the console?