X-Git-Url: http://nitlanguage.org diff --git a/src/parser_util.nit b/src/parser_util.nit index ff06f0e..cd4f205 100644 --- a/src/parser_util.nit +++ b/src/parser_util.nit @@ -30,7 +30,7 @@ redef class ToolContext var eof = tree.n_eof if eof isa AError then - self.fatal_error(null, "Fatal Error: {eof.message}") + self.fatal_error(null, "Fatal Error: {eof.message}.") abort end return tree.n_base.as(not null) @@ -43,7 +43,7 @@ redef class ToolContext var nmodule = parse_module(string) var nclassdefs = nmodule.n_classdefs if nclassdefs.length != 1 then - self.fatal_error(null, "Fatal Error: not a classdef") + self.fatal_error(null, "Fatal Error: not a classdef.") abort end return nclassdefs.first @@ -57,7 +57,7 @@ redef class ToolContext var nclassdef = parse_classdef(mod_string) var npropdefs = nclassdef.n_propdefs if npropdefs.length != 1 then - self.fatal_error(null, "Fatal Error: not a propdef") + self.fatal_error(null, "Fatal Error: not a propdef.") abort end return npropdefs.first @@ -85,13 +85,13 @@ redef class ToolContext # Parse a super class declaration # Fatal error if the `string` is not a syntactically correct super class declaration - fun parse_superclass(string: String): ASuperclass + fun parse_superclass(string: String): APropdef do var mod_string = "class Dummy\nsuper {string}\nend" var nclassdef = parse_classdef(mod_string).as(AStdClassdef) - var nsuperclasses = nclassdef.n_superclasses + var nsuperclasses = nclassdef.n_propdefs if nsuperclasses.length != 1 then - self.fatal_error(null, "Fatal Error: not a super class declaration") + self.fatal_error(null, "Fatal Error: not a super class declaration.") abort end return nsuperclasses.first @@ -251,44 +251,3 @@ class InjectedLexer return tok end end - -redef class ANode - # Do a deep search and return an array of tokens that match a given text - fun collect_tokens_by_text(text: String): Array[Token] - do - var v = new CollectTokensByTextVisitor(text) - v.enter_visit(self) - return v.result - end - - # Do a deep search and return an array of node that are annotated - # The attached node can be retrieved by two invocation of parent - fun collect_annotations_by_name(name: String): Array[AAnnotation] - do - var v = new CollectAnnotationsByNameVisitor(name) - v.enter_visit(self) - return v.result - end -end - -private class CollectTokensByTextVisitor - super Visitor - var text: String - var result = new Array[Token] - redef fun visit(node) - do - node.visit_all(self) - if node isa Token and node.text == text then result.add(node) - end -end - -private class CollectAnnotationsByNameVisitor - super Visitor - var name: String - var result = new Array[AAnnotation] - redef fun visit(node) - do - node.visit_all(self) - if node isa AAnnotation and node.n_atid.n_id.text == name then result.add(node) - end -end