From 7d856326406c25baf91497af0e42164144c0eff7 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 16 Oct 2014 22:43:25 -0400 Subject: [PATCH] parser: generalise Prod::collect_text Signed-off-by: Jean Privat --- src/modelize/modelize_property.nit | 22 ---------------------- src/parser/parser_work.nit | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index 941d4ee..74e4932 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -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 diff --git a/src/parser/parser_work.nit b/src/parser/parser_work.nit index 7daee0f..2a83ee0 100644 --- a/src/parser/parser_work.nit +++ b/src/parser/parser_work.nit @@ -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 -- 1.7.9.5