Skip to content

Commit

Permalink
Fix for imported templates
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Oct 19, 2021
1 parent c13b56a commit d0d67b8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
'maybe': ['_LBRA expansions _RBRA'],
'range': ['STRING _DOTDOT STRING'],

'template_usage': ['RULE _LBRACE _template_args _RBRACE'],
'template_usage': ['nonterminal _LBRACE _template_args _RBRACE'],
'_template_args': ['value',
'_template_args _COMMA value'],

Expand Down Expand Up @@ -484,8 +484,9 @@ def value(self, c):
return self.__default__('value', c, None)

def template_usage(self, c):
if c[0] in self.names:
return self.__default__('template_usage', [self.names[c[0]].name] + c[1:], None)
name = c[0].name
if name in self.names:
return self.__default__('template_usage', [self.names[name]] + c[1:], None)
return self.__default__('template_usage', c, None)


Expand All @@ -498,7 +499,7 @@ def __init__(self, rule_defs):
self.created_templates = set()

def template_usage(self, c):
name = c[0]
name = c[0].name
args = c[1:]
result_name = "%s{%s}" % (name, ",".join(a.name for a in args))
if result_name not in self.created_templates:
Expand Down Expand Up @@ -1323,7 +1324,7 @@ def validate(self) -> None:
continue

for temp in exp.find_data('template_usage'):
sym = temp.children[0]
sym = temp.children[0].name
args = temp.children[1:]
if sym not in params:
if sym not in self._definitions:
Expand Down

0 comments on commit d0d67b8

Please sign in to comment.