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

World: r3wp

[Parse] Discussion of PARSE dialect

Henrik
9-Jul-2006
[1353]
the brackets would make it a "real" rule, wouldn't it? it would be 
possible to replace the rule with a variable and have the rule block 
placed elsewhere in your code
Anton
9-Jul-2006
[1354]
You have to think of a rule like this:
	[ integer! | ]
as equivalent to
	[ integer! | none ]
or
	opt [ integer! ]
Oldes
9-Jul-2006
[1355]
I don;t know how much complex will be the source to parse, but I 
would use the OPT settings as used above
Anton
9-Jul-2006
[1356x2]
But Henrick wants it in any order, like LAYOUT code. (Thus, it's 
worth to look how LAYOUT works. :)
>> parse ["hi"] [[set num integer! | ] string!]   ?? num
num: none
Oldes
9-Jul-2006
[1358x2]
I just think he can end with endless loop easily, as he will never 
be able to catch the second 'image
>> parse ["hi"] [[set num [integer! | string!]] ] ?? num
num: "hi"
Anton
9-Jul-2006
[1360]
Note the | .     "set NUM to an integer or NONE, then... oh. it's 
the end of this block..."  but in Henrick's rule above he continues 
to set other variables, which is of no concern to parse, it still 
has successfully set NUM to NONE.
Henrik
9-Jul-2006
[1361]
there is only one 'image in the block fortunately
Oldes
9-Jul-2006
[1362]
ok, so you will not catch the 'face word:-) as it end up in the img 
variable:-)
Anton
9-Jul-2006
[1363]
I think he might be using 'test-image in place of a real image! for 
this example ?
Henrik
9-Jul-2006
[1364x2]
oldes, nope, because I have many different blocks. they either start 
with 'face or with 'image
never both
Anton
9-Jul-2006
[1366x2]
That's good.
So you can use ANY in an unlimited fashion.
Henrik
9-Jul-2006
[1368x2]
and it makes the parse scalable, so I can add options later
thanks for your help, everyone :-)
Anton
9-Jul-2006
[1370]
cool :)
Henrik
9-Jul-2006
[1371]
It's also a good thing with these discussions. I've never really 
grown 100% comfortable with parse.
DideC
10-Jul-2006
[1372]
About Layout : parse handles only the layout words (origin, space, 
at...), see source layout.

The face description is handled by a loop, not by parse. See system/view/vid/grow-facets
Pekr
19-Jul-2006
[1373x5]
Hi, need a bit of help ....
I tried doing myself small template "engine", which will simply look-up 
for some marks, and replace values accordingly. I decided to look 
for the end of the marks and my friend suggested me, that I should 
name even ending marks, to be clear there is not an error. My parse 
looks like this:
REBOL []

template: {

<b><!--[mark-x]-->Hello x!<!--/[mark-y]--></b>
<b><!--[mark-y]-->Hello y!<!--/[mark-y]--></b>
<b><!--[mark-z]-->Hello z!<!--/[mark-z]--></b>
<b><!--[mark-w]-->Hello w!<!--/[mark-w]--></b>

}

parse/all template [
   some [
         thru "<!--["
         copy mark to "]-->"
         "]-->" 
         start:
         copy text to "<!--/["
         end:
         "<!--/[" mark "]-->"
         (print text)
         |
         skip
    ]
]           
         
halt
I now can create simply a func, which will accept mark name, and 
do some code-block accordingly - sql query, simple replace of value, 
whatever (well, it will not work for cases like img tags, so it is 
not as flexible as full html parser in temple for e.g., but hey, 
it is meant being simple)
... but should not be simpler, so I wonder - so far, as you can see, 
mark-x is not finished, so it is ignored. How to catch this case 
properly and eventually generate error, send email, write to log, 
whatever?
Anton
19-Jul-2006
[1378x2]
I did that recently for COMLib. Look for  build-comlib-website.r 
 in the files section of the COMLib website.
(my end tags are simpler though)
Pekr
19-Jul-2006
[1380x2]
ok, will look into. Is that much complicated than mine is? :-)
this one works better for me:

parse/all template [
   some [
         thru "<!--["
         copy mark to "]-->"
         "]-->" 
         start:
         copy text to "<!--/["
         end:
         "<!--/[" 

         [mark "]-->" (print text) | (print ["not found end of: " mark]) :start]
         |
         skip
    ]
]
Maarten
19-Jul-2006
[1382]
Petr.... you just reinvented erebol, rsp, .... build-markup?
Volker
19-Jul-2006
[1383]
But it does the job, as far as i read.
Pekr
19-Jul-2006
[1384x5]
Maarten - not reinvented - rsp, iirc, mixes code of rebol with html, 
which I don't want to allow
template has to be displayable as gfx man does it, with temporary 
text, images, whatever .... I am just supposed to get correct data 
in there ....
Maarten - now looking into build-markup - sorry, it is just strange 
was of doing things .... noone will place rebol code into template, 
that will not work ... btw - the code is 'done? What happens if someone 
uploads template with its own code? I want presentation and code 
separation.
I looked into rsp some time ago, and I liked it, especially as it 
was complete, with session support etc., but later on I found shlik.org 
being unavailable ...
Maarten  - is RSP still available anywhere for download? erebol.com 
nor shlik.org do work ....
Chris
19-Jul-2006
[1389]
Petr, I have a copy with some notes here:
http://www.ross-gill.com/techniques/rsp/
Ladislav
31-Aug-2006
[1390]
I think, that Tim Peters knew what he wrote here: http://mail.python.org/pipermail/python-dev/1999-December/001770.html
JaimeVargas
31-Aug-2006
[1391]
Very nice comments. But comparing a parser with a regex is a bit 
unfair ;-)
BrianH
31-Aug-2006
[1392x2]
Yeah, for either :)


Still, Peters seems to think that REBOL parse rule blocks are closures, 
for various reasons that are clear from context.
They aren't, though something like parse closures has been suggested 
during the latest round of enhancement proposals.
Volker
31-Aug-2006
[1394]
They are quite like smalltalk-closures. Without locals, but locals 
are not his point. (he may miss them for recursion).
BrianH
31-Aug-2006
[1395]
Hey, locals and arguments (practically the same thing in REBOL) are 
the most important difference between closures and plain blocks. 
The difference is significant but Peters' background with Smalltalk 
made him miss it - Smalltalk "blocks" look like REBOL blocks but 
act like functions.
Volker
31-Aug-2006
[1396x4]
No, the main point is, easy definitions of code and referencing the 
original context. Rebol-blocks do that.
You can  have closures without any arguments.
The highlights he mentions is: lexically-scoped, code and data,  
freely mix computations in
That scoping is the difference between a closure and doing a "string" 
here.
BrianH
31-Aug-2006
[1400]
REBOL blocks don't reference a context, but they may contain words 
that reference a context. Still, this distinction makes no difference 
to the argument that Peters was making - REBOL text processing is 
more powerful than regex and easier to use. It would be easier to 
replicate REBOL-style parsing in Python using closures and generators 
anyway (Peters' real subject), since that is the closest Python gets 
to Icon-style backtracking.
Volker
31-Aug-2006
[1401x2]
its not important what references the context, but that a variable 
can find one.
result := a > b
    ifTrue:[ 'greater' ]
    ifFalse:[ 'less' ]