Hi.
I have an outlining program which can export a simply formatted text
file using tabs and + and - chars to define the outline.
Here's an example:
+ node 1 heading
this is the content of node 1
+ sub-node a heading
this is the content of sub-node a. Note that
the content is not tabbed, whereas the heading
is, in order to describe its nesting level.
- sub-node b (with no content)
+ sub-node c
+ sub-node d heading
this is the content for sub-node d
Anyway, I hope you get the idea. I want to parse this so that I can
xml-, html- and rebol block-ize it.
In the past, I've used parse for some very simple tasks but I'm having
trouble making the leap to understand what's going on in the more
complex uses.
In the hopes of appealing to your collective pity, here's an example of
my truly dismal understanding of parse. I wanted to start off with
returning a block containing all of the node headings from a file
coupled with their "level". Here's (rather embarrassingly) what I came
up with:
rule: [
some [thru "^-" (level: level + 1)]
thru "+ " | thru "- "
copy heading to newline (
append o-block reduce[level heading]
level: 0
)
]
This returns me only one heading (not the first, or the last) with a
count of every tab it's encounted to that point. I've played around
with it with varying degrees of success, but have yet to get even this
right. I'm sure the OR line is not right, and the some probably isn't
being used properly, but I just don't get it.
Parse questions are probably annoying, but has anybody got some pointers
(I've read the users guide, yes) or suggestions on how I might proceed
to handle this nested structure - or just understand parse better?
Thanks in advance,
chris palu