Browse Source

Added get_terminal() method (Issue #412)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.7.2
Erez Shinan 6 years ago
parent
commit
0d164bd344
2 changed files with 10 additions and 0 deletions
  1. +6
    -0
      lark/lark.py
  2. +4
    -0
      lark/lexer.py

+ 6
- 0
lark/lark.py 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.



+ 4
- 0
lark/lexer.py 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)



Loading…
Cancel
Save