[REBOL] Re: Parse and and recursion local variables?
From: lmecir:mbox:vol:cz at: 18-Mar-2007 17:37
Petr Krenzelok napsal(a):
> Volker Nitsch wrote:
>
>> My typicall way to do that is my own stack.
>> stack: copy[]
>> parse rule[
>> (insert/only stack reduce[local1 local2])
>> rule ;recursion
>> (set[local local2] first stack remove stack)
>> ]
>>
>>
>>
> Guys, got to go to have few beers tonight with my friends, but - that
> kinda sucks ;-) I can guarantee you, that most novices, like me, will
> swear like mad when developing and touching first recursion. I think,
> that rebol's aproach of implicit global nature of words, even those
> inside functions, is the main hell for novices :-)
>
> One quick question - how is that with function recursion? Can I have
> "local" function value to one level of recursion call? And then shared
> one? I know I can build my own stack, but ... :-) And if it is possible
> with functions, parser should explicitly behave like that, even if it
> breaks rebol rules :-) Will try with recursive function or stack later ...
>
> -pekr-
>
here are the results obtained:
mark-x start
mark-x end
mark-y start
mark-y end
mark-z start
mark-z end
mark-w start
mark-u start
mark-u end
finished subsection mark-w
mark-w end
...and here is the code:
include http://www.fm.vslib.cz/~ladislav/rebol/parseen.r
template: {
this is the beginning of html:-)
<b><!--[mark-x]-->Hello x!<!--/[mark-x]--></b>
<b><!--[mark-y]-->Hello y!<!--/[mark-y]--></b>
<b><!--[mark-z]-->Hello z!<!--/[mark-z]--></b>
<b><!--[mark-w]-->Hello w!
another html code
<!--[mark-u]-->
subsection html code
<!--/[mark-u]-->
finishing mark-w html code
<!--/[mark-w]--></b>
this is the end :-)
}
out: copy ""
;just to distinguish for eventual debugging ...
html: [copy char skip (append out char)]
rsp-html: [copy char skip (append out char)]
rsp-section: [
use [rsp-begin rsp-end rsp-tag-name] copy/deep [
rsp-begin: ["<!--[" copy rsp-tag-name to "]-->" "]-->" (print
[rsp-tag-name "start"])]
rsp-end: ["<!--/[" rsp-tag-name "]-->" (print
[rsp-tag-name "end"])]
[rsp-begin any [rsp-end break | do rsp-section (print ["finished
subsection" rsp-tag-name]) | rsp-html]]
]
]
parseen/all template [any [do rsp-section | html] end]
probe out
-L