Document hacky customize arg count better.

This commit is contained in:
rocky
2017-09-30 18:02:35 -04:00
parent e7778f83f2
commit 1d7a3c6444
3 changed files with 26 additions and 10 deletions

View File

@@ -44,21 +44,25 @@ class PythonParser(GenericASTBuilder):
else:
return self.ast_first_offset(ast[0])
def add_unique_rule(self, rule, opname, count, customize):
def add_unique_rule(self, rule, opname, arg_count, customize):
"""Add rule to grammar, but only if it hasn't been added previously
opname and count are used in the customize() semantic the actions
to add the semantic action rule. Often, count is not used.
opname and stack_count are used in the customize() semantic
the actions to add the semantic action rule. Stack_count is
used in custom opcodes like MAKE_FUNCTION to indicate how
many arguments it has. Often it is not used.
"""
if rule not in self.new_rules:
# print("XXX ", rule) # debug
self.new_rules.add(rule)
self.addRule(rule, nop_func)
customize[opname] = count
customize[opname] = arg_count
pass
return
def add_unique_rules(self, rules, customize):
"""Add rules (a list of string) to grammar
"""Add rules (a list of string) to grammar. Note that
the rules must not be those that set arg_count in the
custom dictionary.
"""
for rule in rules:
if len(rule) == 0:
@@ -68,7 +72,9 @@ class PythonParser(GenericASTBuilder):
return
def add_unique_doc_rules(self, rules_str, customize):
"""Add rules (a docstring-like list of rules) to grammar
"""Add rules (a docstring-like list of rules) to grammar.
Note that the rules must not be those that set arg_count in the
custom dictionary.
"""
rules = [r.strip() for r in rules_str.split("\n")]
self.add_unique_rules(rules, customize)

View File

@@ -93,12 +93,18 @@ class Scanner2(Scanner):
for instr in bytecode.get_instructions(co):
print(instr._disassemble())
# Container for tokens
# list of tokens/instructions
tokens = []
# "customize" is a dict whose keys are nonterminals
# and the value is the argument stack entries for that
# nonterminal. The count is a little hoaky. It is mostly
# not used, but sometimes it is.
# "customize" is a dict whose keys are nonterminals
customize = {}
if self.is_pypy:
customize['PyPy'] = 1
customize['PyPy'] = 0
Token = self.Token # shortcut

View File

@@ -169,12 +169,16 @@ class Scanner3(Scanner):
for instr in bytecode.get_instructions(co):
print(instr._disassemble())
# Container for tokens
# list of tokens/instructions
tokens = []
# "customize" is a dict whose keys are nonterminals
# and the value is the argument stack entries for that
# nonterminal. The count is a little hoaky. It is mostly
# not used, but sometimes it is.
customize = {}
if self.is_pypy:
customize['PyPy'] = 1
customize['PyPy'] = 0
self.code = array('B', co.co_code)
self.build_lines_data(co)