[REBOL] Re: Parse and and recursion local variables?
From: petr:krenzelok:trz:cz at: 17-Mar-2007 18:40
OK Ladislav, here we go. I bet I am doing something incorrectly. Simply
put, once rsp-section recursion is applied for mark-u section, once it
returns back to one level up, rsp-tag-name remains to be set to mark-u,
whereas what I would like to achieve is - parser keeping that variable
local for certain iteration, so once it would return from mark-u section
back to finish parent mark-w section, having it set to mark-w. I tried
to enclose the example in the function and define rsp-tag-name as local
variable as you can see, but to no luck ... but maybe my aproach is
incorrent conceptually anyway :-)
Thanks,
Petr
-----------------------
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-u]-->
finishing mark-w html code
<!--/[mark-w]--></b>
this is the end :-)
}
;parse-test-recursion: func [/local rsp-tag-name][
out: copy ""
rsp-begin: ["<!--[" copy rsp-tag-name to "]-->" "]-->" (print
[rsp-tag-name "start"])]
rsp-end: ["<!--/[" rsp-tag-name "]-->" (print
[rsp-tag-name "end"])]
;rsp-begin: ["<!--[" s: some [e: "]-->" (print copy/part s e) break |
skip]]
;rsp-end: ["<!--/[" s: some [e: "]-->" (print copy/part s e) break |
skip]]
;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
["finished subsection" rsp-tag-name]) | rsp-html]]
rsp-rules: [any [rsp-section | html] end]
parse/all template rsp-rules
;]
;parse-test-recursion
probe out
halt