[Vimoutliner] Parsing outlines with awk?

Steve Litt slitt at troubleshooters.com
Sun Apr 1 10:43:34 EDT 2007


On Saturday 31 March 2007 13:12, Ned Konz wrote:
> Steve Litt wrote:
> > Has anyone used awk to parse outlines? How did it work for you? I just
> > learned awk, and implemented stacks in awk (I don't think awk has stacks
> > natively, but it's trivial to make). Theoretically, armed with stacks one
> > could parse and translate outlines, although the lack of complex
> > variables (C structures, Ruby classes, etc) makes it a little harder.
>
> Hi Steve,
>
> Sorry, I haven't used Awk for parsing outlines for a while. I looked
> around for my last version of that and couldn't find it. As I recall,
> though, I used a state machine approach (Awk's pattern/block structure
> maps well to FSMs).
>
> Attached is my Ruby parser for my own (TVO) outline structure. You'd
> need to change some of the regular expressions for your text additions,
> etc. but it may be helpful.
>
> It actually contains the parser class as well as a few formatters.


Hi Ned,

I couldn't understand most of your code, at least at a short sitting, but what 
I found interesting was your Item class, which superficially resembles the 
Node class in my Node.pm (and Node.py and Node.rb). However, my Node objects 
have five pointers (parent, prevsibling, nextsibling, firstchild, lastchild). 
Your Item objects do the same thing differently, using a parent pointer and a 
pointer to an array of children.

So with Node, you recurse through by going to the first child if you can, 
otherwise going to the next sibling, otherwise going up to the parent again 
and then to the parent's nextsibling.

With Item, I'd guess you recurse by going to children[0], and if you can't go 
to parent.children[current+1], and if you can't then go to 
parent.parent.children[current+1] using Ruby's whatever.each{} construct.

It's interesting how two different approaches turn out to be pretty much the 
same thing. I got my pointer ideas from the DOM specification.

Anyway, if you want to see how it works with my five pointers instead of a 
children array, here's Node.rb:

http://www.troubleshooters.com/projects/Node.rb/index.htm

Be aware I'd only been using Ruby a week or so when I wrote Node.rb, so if it 
looks like it's written with a C accent, that's because it is :-) Also, I 
wanted the code to look as much like Node.pm as possible.

Thanks

SteveT

-- 
Steve Litt
Author: Universal Troubleshooting Process books and courseware
http://www.troubleshooters.com/

(Legal Disclaimer) Follow these suggestions at your own risk.


More information about the VimOutliner mailing list