Commit 3da3e9d8 authored by di68kap's avatar di68kap
Browse files

ts2dataclass extended

parent 543ad82b
......@@ -2832,7 +2832,7 @@ class EBNFCompiler(Compiler):
return value
def gen_search_rule(self, node: Node, nd: Node, kind: str) -> ReprType:
def make_search_rule(self, node: Node, nd: Node, kind: str) -> ReprType:
"""Generates a search rule, which can be either a string for simple
string search or a regular expression from the node's content. Returns
an empty string in case the node is neither regexp nor literal.
......@@ -2873,6 +2873,7 @@ class EBNFCompiler(Compiler):
defn = self.compile(nd)
assert defn.find("(") >= 0 # synonyms impossible here
self.definitions[rule] = defn
self.referred_by_directive.add(rule)
return unrepr(rule)
......@@ -3487,7 +3488,7 @@ class EBNFCompiler(Compiler):
if len(node.children) == 2:
error_msgs.append(('', unrepr(node[1].content)))
elif len(node.children) == 3:
rule = self.gen_search_rule(symbol, node[1], 'error')
rule = self.make_search_rule(symbol, node[1], 'error')
error_msgs.append((rule if rule else unrepr(node[1].content),
unrepr(node[2].content)))
else:
......@@ -3499,12 +3500,12 @@ class EBNFCompiler(Compiler):
# if symbol in self.rules:
# self.tree.new_error(node, 'Skip list for resuming in series for symbol "{}"'
# ' must be defined before the symbol!'.format(symbol))
self.directives.skip[symbol] = [self.gen_search_rule(symbol, nd, 'skip')
self.directives.skip[symbol] = [self.make_search_rule(symbol, nd, 'skip')
for nd in node[1:]]
elif key.endswith('_resume'):
symbol = key[:-7]
self.directives.resume[symbol] = [self.gen_search_rule(symbol, nd, 'resume')
self.directives.resume[symbol] = [self.make_search_rule(symbol, nd, 'resume')
for nd in node[1:]]
else:
......
......@@ -2914,7 +2914,7 @@ class EBNFCompiler(Compiler):
return value
def gen_search_rule(self, nd: Node) -> ReprType:
def make_search_rule(self, nd: Node) -> ReprType:
"""Generates a search rule, which can be either a string for simple
string search or a regular expression from the node's content. Returns
an empty string in case the node is neither regexp nor literal.
......@@ -3146,7 +3146,7 @@ class EBNFCompiler(Compiler):
if isinstance(rule, unrepr) and rule.s.isidentifier():
try:
nd = self.rules[rule.s][0].children[1]
refined = self.gen_search_rule(nd)
refined = self.make_search_rule(nd)
if not refined: refined = unrepr(rule.s)
except IndexError:
nd = self.tree # TODO: Allow arbitrary parsers, here
......@@ -3178,7 +3178,7 @@ class EBNFCompiler(Compiler):
if isinstance(search, unrepr) and search.s.isidentifier():
try:
nd = self.rules[search.s][0].children[1]
search = self.gen_search_rule(nd)
search = self.make_search_rule(nd)
except IndexError:
search = ''
except KeyError:
......@@ -3218,7 +3218,7 @@ class EBNFCompiler(Compiler):
if isinstance(search, unrepr) and search.s.isidentifier():
try:
nd = self.rules[search.s][0].children[1]
search = self.gen_search_rule(nd)
search = self.make_search_rule(nd)
except IndexError:
search = ''
except KeyError:
......@@ -3598,7 +3598,7 @@ class EBNFCompiler(Compiler):
if len(node.children) == 2:
error_msgs.append(('', unrepr(node[1].content)))
elif len(node.children) == 3:
rule = self.gen_search_rule(node[1])
rule = self.make_search_rule(node[1])
error_msgs.append((rule if rule else unrepr(node[1].content),
unrepr(node[2].content)))
else:
......@@ -3610,11 +3610,11 @@ class EBNFCompiler(Compiler):
# if symbol in self.rules:
# self.tree.new_error(node, 'Skip list for resuming in series for symbol "{}"'
# ' must be defined before the symbol!'.format(symbol))
self.directives.skip[symbol] = [self.gen_search_rule(nd) for nd in node[1:]]
self.directives.skip[symbol] = [self.make_search_rule(nd) for nd in node[1:]]
elif key.endswith('_resume'):
symbol = key[:-7]
self.directives.resume[symbol] = [self.gen_search_rule(nd) for nd in node[1:]]
self.directives.resume[symbol] = [self.make_search_rule(nd) for nd in node[1:]]
else:
if any(key.startswith(directive) for directive in ('skip', 'error', 'resume')):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment