Added get_terminal() method (Issue #412)

This commit is contained in:
Erez Shinan 2019-07-24 23:00:55 +02:00
parent d952f2a069
commit 0d164bd344
2 changed files with 10 additions and 0 deletions

View File

@ -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.

View File

@ -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)