Stupid Parse Tricks
[1/3] from: john:schuhr at: 6-Jun-2001 13:50
Greetings list,
Since playing with the eRebol utility by Maarten Koopmans, I've become
interested in writing a full-featured markup language similar to Allaire's
(Macromedia) Cold Fusion. Theoretically (with the right dialect), it would
be able to process CF templates, but would be much more extensible.
Unfortunately, the nuances of the 'parse dialect are still a bit mysterious
to me. I'm still hunting for lots of documentation and examples. But one
of the fundamental things I am curious to know up-front, is can it be done
with one rule or will I need to create lots of little rules and loop
through the template, matching rules as I go? A template might look like
the following:
<html><body>
Login Report<br>
<!--- logins in with mysql://127.0.0.1/logindb for example --->
<!--- and stores the result set for future use --->
<rebquery datasource="127.0.0.1" dbname="logindb" name="qryLogins">
select * from tblLogin
</rebquery>
<table>
<tr>
<td>User Name</td>
<td>Time Logged In</td>
</tr>
<rebout query="qryLogins">
<tr>
<td>#LoginName#</td>
<td>#LoginTime#</td>
</tr>
</rebout>
</table>
<br>
The current time is:
<rebscript>
print now/time
</rebscript>
<br>
The current date is:
<rebout>
#now/date#
</rebout>
</body></html>
Just look'n for insight :) Thanks.
--John
[2/3] from: gjones05:mail:orion at: 6-Jun-2001 15:44
From: "John Schuhr"
> Greetings list,
> Since playing with the eRebol utility by
<<quoted lines omitted: 12>>
> loop through the template, matching rules as
> I go? A template might look like the following:
...
> Just look'n for insight :) Thanks.
Hi, John.
Just one as far as I can tell. Here is a template that you can use.
Watch for wrapping lines.
Happy ereboling.
--Scott Jones
;========================
REBOL [comment: "prelim erebol extender"]
data: {
<html><body>
Login Report<br>
<!--- logins in with mysql://127.0.0.1/logindb for example --->
<!--- and stores the result set for future use --->
<rebquery datasource="127.0.0.1" dbname="logindb" name="qryLogins">
select * from tblLogin
</rebquery>
<table>
<tr>
<td>User Name</td>
<td>Time Logged In</td>
</tr>
<rebout query="qryLogins">
<tr>
<td>#LoginName#</td>
<td>#LoginTime#</td>
</tr>
</rebout>
</table>
<br>
The current time is:
<rebscript>
print now/time
</rebscript>
<br>
The current date is:
<rebout>
#now/date#
</rebout>
</body></html>
}
reb-querys: copy []
rebout-vars: copy []
reb-scripts: copy []
rule: [
any [
thru "<rebquery"
copy reb-query
to </rebquery>
(temp: copy parse/all reb-query ">"
foreach p parse temp/1 none [append reb-querys p]
temp: copy rejoin [{sql-query="} trim/lines temp/2 {"}]
append reb-querys temp
)
]
any [
thru <rebscript>
copy reb-script
to </rebscript>
(append reb-scripts trim/lines reb-script)
]
any [
thru "<rebout"
copy rebout-mod
to ">"
any
[thru "#"
copy rebout-var
to "#" skip
(append rebout-vars rebout-var)
]
to </rebout>
]
to end
]
parse data rule
print "Rebout Variable/Parameters"
foreach r rebout-vars [print r]
print ""
print "In-Line REBOL Script stuff"
foreach r reb-scripts [print r]
print ""
print "DB REBOL Query stuff"
foreach r reb-querys [print r]
print ""
print "Goodbye"
[3/3] from: john::schuhr::com at: 6-Jun-2001 21:43
Hi Scott,
Thanks for the spiffy code.. it'll go a long way in helping me to get
this going. I neglected to mention that all of the rebtags need to be
processed in the order that they occur on the page. But the parsing stuff
you whipped up only needs a bit of tinkering to do just that. For anyone
interested, I've setup a project page with documentation (ha!) and downloads.
http://schuhr.com/rbml/index.html
--JohnSchuhr
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted