parser: factorize the lexer big accept switch
[nit.git] / src / parser / xss / parser.xss
index 08510f7..0103d5f 100644 (file)
@@ -158,8 +158,9 @@ special ParserTable
                                var node = new Start(null, node2)
                                return node
                        end
+                       if false then break # FIXME remove once unreach loop exits are in c_src
                end
-               abort
+               abort # FIXME remove once unreach loop exits are in c_src
        end
 
        var _reduce_table: Array[ReduceAction]
@@ -167,7 +168,7 @@ special ParserTable
        do
                _reduce_table = new Array[ReduceAction].with_items(
 $ foreach {rules/rule}
-                       new ReduceAction@index[-sep ','-]
+                       new ReduceAction@index(@leftside)[-sep ','-]
 $ end foreach
                )
        end
@@ -273,6 +274,12 @@ end
 # Each reduca action has its own class, this one is the root of the hierarchy.
 private abstract class ReduceAction
        fun action(p: Parser) is abstract
+       fun concat(l1, l2 : Array[Object]): Array[Object]
+       do
+               if l1.is_empty then return l2
+               l1.append(l2)
+               return l1
+       end
 end
 
 $ foreach {rules/rule}
@@ -300,13 +307,7 @@ $     when {@cmd='ADDNODE'}
                                        end
 $     end
 $     when {@cmd='ADDLIST'}
-#                                      if ${translate(@fromlist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} != null then
-                                               if ${translate(@tolist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}.is_empty then
-                                                       ${translate(@tolist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} = ${translate(@fromlist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
-                                               else
-                                                       ${translate(@tolist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}.append(${translate(@fromlist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")})
-                                               end
-#                                      end
+                                       ${translate(@tolist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} = concat(${translate(@tolist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}, ${translate(@fromlist,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")})
 $     end
 $     when {@cmd='MAKELIST'}
                                        var ${translate(@result,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} = new Array[Object]
@@ -334,9 +335,10 @@ $     when {@cmd='RETURNLIST'}
 $     end
 $   end choose
 $   end foreach
-                                       p.push(p.go_to(@leftside), node_list)
+                                       p.push(p.go_to(_goto), node_list)
        end
-init do end
+       var _goto: Int
+       init(g: Int) do _goto = g
 end
 $ end foreach
 $ end template