[REBOL] Re: Parse and and recursion local variables?
From: petr:krenzelok:trz:cz at: 19-Mar-2007 13:14
Volker Nitsch napsal(a):
> 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)
> ]
>
Volker,
thanks for the idea, with little bit of thinking I might get the final
result ...
-------------------
REBOL []
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-q]-->
subsubsection html code
<!--/[mark-q]-->
<!--/[mark-u]-->
finishing mark-w html code
<!--/[mark-w]--></b>
this is the end :-)
}
stack: context [
add: func [values][insert/only stack reduce values]
remove: func [values][system/words/remove stack if not empty? stack
[set values first stack]]
stack: copy []
probe: does [system/words/probe stack]
]
out: copy ""
rsp-begin: ["<!--[" copy rsp-tag-name to "]-->" "]-->" (print
[rsp-tag-name "start"]) (stack/add [rsp-tag-name])]
rsp-end: ["<!--/[" rsp-tag-name "]-->" (print
[rsp-tag-name "end"]) (stack/remove [rsp-tag-name])]
;just to distinguish for eventual debugging ...
html: [copy char skip (append out char)]
rsp-html: [copy char skip (append out char)]
rsp-section: [rsp-begin any [rsp-end break | rsp-section (print ["back
at section" rsp-tag-name]) | rsp-html]]
rsp-rules: [any [rsp-section | html] end]
parse/all template rsp-rules
probe out
halt