[REBOL] Parse and and recursion local variables?
From: petr::krenzelok::trz::cz at: 17-Mar-2007 12:15
Hi,
not being much skilled in parsing, I tried to do a little parser for my
own rsp-tag system (I know there are few robust systems out there, but I
want to learn via implementing my own). Basically the idea is to use
kind of comment tags, which still allow web designer to display html
content. The most attractive system for me was Gabriele's Temple, but it
is not finished, nor supported, so I want my own one, much simpler :-)
My tags look like:
<!--[section-x]-->
subsection html code
<!--/[section-x]-->
I want to detect particular sections and invoke particular modules/code
for them, submitting it section content. Basically it works, but I also
wanted to try my very primitive parser to do some recursion. And it
seems to me I tracked down, why it does not work - inside of nested
sections, when the recursive rule is applied, I think that
rsp-section-name is not kept local to particular recursion level? Can I
make it local by putting e.g. parse into function body, defining a word
(rsp-tag-nested) as a local variable? Or the issue is more complex and
my rules simply build insufficiently?
Also - if I don't use to [a | b | c], as we don't have any ;-), I have
to skip by one char. That makes stripping out html subsections a bit
difficult (where to put correct markers), as my rsp-html or html rules
simply are "1 skip". But maybe that could be solved by defining what the
proper html charset is?
Sorry if my questions are rather primitive to our parse gurus here :-)
-pekr-
---------------------
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 :-)
}
out: copy ""
;--- uncommend following to get incorrect recursion behavior
;rsp-begin: ["<!--[" copy rsp-tag-name to "]-->" "]-->"]
;rsp-end: ["<!--/[" rsp-tag-name "]-->"]
;--- comment following if enabling above ones ...
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 | rsp-html]
]
rsp-rules: [any [rsp-section | html] end]
parse/all template rsp-rules
probe out
halt