[Sbp-users] Indentation (tree) parsing

Yang Zhang yanghatespam at gmail.com
Wed Mar 17 14:56:49 EDT 2010


Hi, I'm interested in parsing this text:

xxx
|xxx
|xxx
||xxx
||xxx
|xxx
xxx

into this tree:

Branch {
  Branch {
    Leaf
    Branch {
      Leaf
      Leaf
    }
    Leaf
  }
  Leaf
}

I was borrowing the technique outlined in the LDTA06 paper, but I
can't seem to really hack it. Here's my current grammar:

s = Tree [\n ]!*
Tree = Tree::(Branch | Leaf)+
Leaf = Leaf::"|"**! "xxx" "\n" &~ BranchR "|"
BranchR = "|" BranchR "|" | [~|]++! "\n"
Branch = Branch::"|"**! "xxx" "\n" Tree &~ LeafR
LeafR = "|" LeafR "|" | "|" [~|]++! "\n"

It seems that Branch should be wrapped, but I don't know how to not
consume the subsequent nodes in the tree as part of the Branch itself
(i.e. not sure how to get the "lookahead" behavior). Any hints? Thanks
in advance.
-- 
Yang Zhang
http://www.mit.edu/~y_z/



More information about the Sbp-users mailing list