[REBOL] Re: Big parse rules
From: AJMartin:orcon at: 19-Jul-2003 22:02
Volker wrote:
> would like pathes in parserules.
So would I! :)
> without it, you could put everything in a context and export only 'Table^
with 'set. or do
> table^: ctx-table/table^
> parse string [..]
> context[
> Table_Printable^: exclude Printable charset #"|"
> ;..
> set 'Table^[
> ; ..
> ]
> ]
Thanks, Volker! That would work, except that I wanted it to eventually be
recursive. With an object, I can't yet see how this could be done (perhaps
copying to a stack/block?).
Here's what I eventually ended up with:
set 'Table^ function [
Markup [block!] eText [string!]
] [Printable^ Cell! Cell^ Cell Row^ Row Header Rows Index] [
Printable^: exclude Printable charset #"|"
Cell!: 'th
Cell^: [
#"|" copy Cell any Printable^
(Cell: reduce [Cell! any [Cell #" "]])
]
Row^: [
(Row: copy [])
some [Cell^ (insert tail Row Cell)] opt #"|" LWS? Line_End
(Row: reduce ['tr Row])
]
all [
parse/all eText [
Row^ (
Header: Row
Cell!: 'td
Rows: copy []
)
some [Row^ (insert tail Rows Row)] (
insert tail Markup compose/deep [
table [
thead [(Header)]
tbody [(Rows)]
]
]
) Index: to end
end
]
Index
]
]
And in a separate function:
Fail^: [to end skip] ; Always fails rule.
Succeed^: [] ; Always succeeds rule.
Switch^: none
parse/all Dialect [
some [
Blank_Lines [
List
| Block_Quote
| [
Mark: (
Switch^: Fail^
if Result: Table^ Markup Mark [
Mark: Result
Switch^: Succeed^
]
) Switch^ :Mark
]
| Divider
| Bullet_Divider
| Centre
| Heading
]
| Paragraph
| Initial_Paragraph
| skip
]
end
]
Though it's still only about 90% I feel.
Andrew J Martin
ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/