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

World: r3wp

[Parse] Discussion of PARSE dialect

BrianH
1-Jul-2006
[1303]
No, it isn't. You have to yourself. Can you save the macro data in 
REBOL data format?
Graham
1-Jul-2006
[1304x3]
I guess so, but I want to make it easy for the users ...
but that works now :)
Thanks for the help guys
Henrik
9-Jul-2006
[1307x3]
how "local" are variables that are set during a parse? I was looking 
at Geomol's postscript.r and looked at:

coords: [err:
	(pos: none) [set pos pair! | set x number! set y number!] (
		either pos [
			append output compose [(pos/x) " " (pos/y) " lineto^/"]
		][
			append output compose [(x) " " (y) " lineto^/"]
		]
	)
]
but I can't get 'pos set in my own code in the () block after the 
parse block where 'pos is set.
that means it does get set inside the parse block, but it's set to 
none after the parse block again.
Anton
9-Jul-2006
[1310]
Is your code in the second parens actually ever executing ?
Henrik
9-Jul-2006
[1311]
yes, I try to print the variable and it just returns none.
Anton
9-Jul-2006
[1312]
Mmm let me make a few tests.
Henrik
9-Jul-2006
[1313]
actually, there is a difference between my code and this, which may 
be causing it:


I need to loop the block with 'any. I suspect the contents is lost 
after the first run.
Oldes
9-Jul-2006
[1314]
because you set it to none in the first parens
Anton
9-Jul-2006
[1315]
Yes the rule can only fail after the first parens.
Henrik
9-Jul-2006
[1316]
oldes: it makes no difference whether the first parens is left out 
or not
Anton
9-Jul-2006
[1317]
And to answer your question, the variables are just regular rebol 
words, so they are as local as you make them.
Oldes
9-Jul-2006
[1318x2]
and how looks the code you parse?
if the parse is inside function and you set pos in the function as 
a local - it will be local
Henrik
9-Jul-2006
[1320x2]
I'm parsing:

[image "String" image-word [action block]]
where 'image is always first and the remaining items may come in 
random order
Oldes
9-Jul-2006
[1322]
there is no pair and no numbers - the pos must be none
Henrik
9-Jul-2006
[1323]
oldes, my code is different from his. I used his as it's structurally 
similar to mine
Oldes
9-Jul-2006
[1324]
and what exactly do you want?
Henrik
9-Jul-2006
[1325]
I want to assign a variable to each element so I can process them 
later
Oldes
9-Jul-2006
[1326]
so for the block above it would assing what?
Henrik
9-Jul-2006
[1327x3]
the block is stored in 'attr.

parse attr [

  (txt: 123 print txt) 'image any [set txt string! (print txt) | set 
  img word! | set action block!] (print txt) | 'face
]

gives:

123
search
none
== true
argh... forgot to show you attr
attr: [image test-image "Search" [print "test"]]
Oldes
9-Jul-2006
[1330]
Don't you want to use rather:

parse/all attr [(txt: 123 print txt) 'image opt [set txt string! 
(print txt)] opt [ set img word!] opt [ set action block! (print 
txt)] (print txt) | 'face]
Henrik
9-Jul-2006
[1331]
it seems the variable is stored in the last iteration, so it's definitely 
lost after one loop.
Anton
9-Jul-2006
[1332]
Doesn't Henrik want to be able to process the attributes in any order 
?
Henrik
9-Jul-2006
[1333x3]
that's what I want. I'm catching fish :-) or rather information to 
store them safely for processing later.
but let me try Oldes thing to see what it does
it works the exact opposite :-) Only the outer 'txt is set, and I 
can't reach the variable inside the block
Anton
9-Jul-2006
[1336x2]
Henrik, I parse your test attr block successfully:

>> parse [image test-image "Search" [print "action"]] ['image any 
[set txt string! (?? txt) | set img word! | set action block!]]
txt: "Search"
== true
Need more test data to parse.
Henrik
9-Jul-2006
[1338x2]
anton: yes, but what is txt after processing?
I don't want to handle it inside the parse block but after it
Anton
9-Jul-2006
[1340]
it is none.
Henrik
9-Jul-2006
[1341]
right. that's the problem
Anton
9-Jul-2006
[1342x2]
add a block to control the evaluation.
>> parse [image test-image "Search" [print "action"]] ['image any 
[[set txt string! (?? txt)] | set img word! | set action block!]]
txt: "Search"
== true
>> txt
== "Search"
Oldes
9-Jul-2006
[1344]
it always set the variables to none, if it fails to match
Anton
9-Jul-2006
[1345]
You have to be careful in your interpretation of  |
Oldes
9-Jul-2006
[1346]
interesting, this is the solution:

 txt: 123 parse/all attr ['image any [[set txt string! (print txt)] 
 | [set img word!] | [set action block! (print txt)]] (print txt) 
 | 'face]
Henrik
9-Jul-2006
[1347x2]
oldes solution seems to work
the wonders of parse... :-)
Oldes
9-Jul-2006
[1349]
it's just improved anton's solution:-)
Anton
9-Jul-2006
[1350]
I'm trying to figure out a simple example to show why.
Henrik
9-Jul-2006
[1351]
I wonder what the difference is? If it's only for controlling how 
global a variable is, it seems a little backwards to me
Oldes
9-Jul-2006
[1352]
without the extra brackets, the parse set the variables to none if 
it failes