diff --git a/lark/lark.py b/lark/lark.py index 5c43fa8..ae71d56 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -205,6 +205,8 @@ class Lark(Serialize): # Compile the EBNF grammar into BNF self.terminals, self.rules, self.ignore_tokens = self.grammar.compile(self.options.start) + self._terminals_dict = {t.name:t for t in self.terminals} + # If the user asked to invert the priorities, negate them all here. # This replaces the old 'resolve__antiscore_sum' option. if self.options.priority == 'invert': @@ -290,6 +292,10 @@ class Lark(Serialize): return self.options.postlex.process(stream) return stream + def get_terminal(self, name): + "Get information about a terminal" + return self._terminals_dict[name] + def parse(self, text, start=None): """Parse the given text, according to the options provided. diff --git a/lark/lexer.py b/lark/lexer.py index 898ee04..4a8b422 100644 --- a/lark/lexer.py +++ b/lark/lexer.py @@ -41,6 +41,8 @@ class Pattern(Serialize): class PatternStr(Pattern): + type = "str" + def to_regexp(self): return self._get_flags(re.escape(self.value)) @@ -50,6 +52,8 @@ class PatternStr(Pattern): max_width = min_width class PatternRE(Pattern): + type = "re" + def to_regexp(self): return self._get_flags(self.value)