parser: generalise Prod::collect_text
authorJean Privat <jean@pryen.org>
Fri, 17 Oct 2014 02:43:25 +0000 (22:43 -0400)
committerJean Privat <jean@pryen.org>
Tue, 21 Oct 2014 23:51:01 +0000 (19:51 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/modelize/modelize_property.nit
src/parser/parser_work.nit

index 941d4ee..74e4932 100644 (file)
@@ -300,28 +300,6 @@ redef class MClassDef
        var mprop2npropdef: Map[MProperty, APropdef] = new HashMap[MProperty, APropdef]
 end
 
-redef class Prod
-       # Join the text of all tokens
-       # Used to get the 'real name' of method definitions.
-       fun collect_text: String
-       do
-               var v = new TextCollectorVisitor
-               v.enter_visit(self)
-               assert v.text != ""
-               return v.text
-       end
-end
-
-private class TextCollectorVisitor
-       super Visitor
-       var text: String = ""
-       redef fun visit(n)
-       do
-               if n isa Token then text += n.text
-               n.visit_all(self)
-       end
-end
-
 redef class APropdef
        # The associated main model entity
        type MPROPDEF: MPropDef
index 7daee0f..2a83ee0 100644 (file)
@@ -171,6 +171,15 @@ redef class Prod
        # Location on the first token after the start of a production
        # So outside the production for epsilon production
        var first_location: nullable Location
+
+       # Join the text of all visited tokens
+       fun collect_text: String
+       do
+               var v = new TextCollectorVisitor
+               v.enter_visit(self)
+               assert v.text != ""
+               return v.text
+       end
 end
 
 # Find location of production nodes
@@ -241,6 +250,17 @@ private class ComputeProdLocationVisitor
        init do end
 end
 
+private class TextCollectorVisitor
+       super Visitor
+       var text: String = ""
+       redef fun visit(n)
+       do
+               if n isa Token then text += n.text
+               n.visit_all(self)
+       end
+end
+
+
 # Each reduce action has its own class, this one is the root of the hierarchy.
 private abstract class ReduceAction
        fun action(p: Parser) is abstract