@@ -108,19 +108,19 @@ class SemanticActionExecutor(amb: (Set[Any], Int, Int) => Any,
108
108
109
109
def visit (node : SPPFNode ): Any = node match {
110
110
111
- case t : TerminalNode => if (t.leftExtent == t.rightExtent) ()
112
- else tn(t.leftExtent, t.rightExtent)
111
+ case t : TerminalNode => if (t.leftExtent == t.rightExtent) ()
112
+ else tn(t.leftExtent, t.rightExtent)
113
113
114
- case t : LayoutTerminalNode => if (t .leftExtent == t .rightExtent) ()
115
- else tn(t .leftExtent, t .rightExtent)
116
-
117
- case n : NonterminalNode => if (n isAmbiguous) ambiguity(n)
118
- else nonterminal(n.first, n.leftExtent, n.rightExtent)
114
+ case l : LayoutTerminalNode => if (l .leftExtent == l .rightExtent) ()
115
+ else tn(l .leftExtent, l .rightExtent)
116
+
117
+ case n : NonterminalNode => if (n isAmbiguous) ambiguity(n)
118
+ else nonterminal(n.first, n.leftExtent, n.rightExtent)
119
119
120
- case i : IntermediateNode => if (i isAmbiguous) ambiguity(i)
121
- else intermediate(i.first, visit(i.first.leftChild), visit(i.first.rightChild))
120
+ case i : IntermediateNode => if (i isAmbiguous) ambiguity(i)
121
+ else intermediate(i.first, visit(i.first.leftChild), visit(i.first.rightChild))
122
122
123
- case p : PackedNode => throw new RuntimeException (" Should not traverse a packed node!" )
123
+ case p : PackedNode => throw new RuntimeException (" Should not traverse a packed node!" )
124
124
}
125
125
126
126
}
@@ -185,9 +185,17 @@ object TreeBuilder {
185
185
186
186
def t (input : Input )(l : Int , r : Int ): Tree = org.meerkat.tree.TerminalNode (input.substring(l, r))
187
187
188
+ def l (input : Input )(l: Int , r : Int ): Tree = LayoutNode (t(input)(l, r))
189
+
188
190
def int (input : Input )(t : Rule , v : Any ) = v
189
191
190
- def nt (input : Input )(t : Rule , v : Any , l : Int , r : Int ) = RuleNode (Rule (t.head, flatten(t.body)), flatten(v).asInstanceOf [Seq [Tree ]])
192
+ def nt (input : Input )(t : Rule , v : Any , l : Int , r : Int ) = {
193
+ val node = RuleNode (Rule (t.head, flatten(t.body)), flatten(v).asInstanceOf [Seq [Tree ]])
194
+ t.head match {
195
+ case Layout (_) => LayoutNode (node)
196
+ case _ => node
197
+ }
198
+ }
191
199
192
200
def build (node : NonPackedNode , memoized : Boolean = true )(implicit input : Input ): Tree = {
193
201
val executer = if (memoized) new SemanticActionExecutor (amb(input), t(input), int(input), nt(input)) with Memoization
0 commit comments