Make it so Configuration() is constructed fewer places

This will make it so that I can add fields to Configuration to support
additional parser generators without breaking any individual
generator.
This commit is contained in:
John Doty 2016-12-09 06:37:57 -08:00
parent 169ec4ff08
commit cf10891c19

View file

@ -23,6 +23,9 @@ class Configuration(
def at_symbol(self, symbol):
return self.next == symbol
def replace(self, **kwargs):
return self._replace(**kwargs)
def __str__(self):
return "{name} -> {bits}".format(
name=self.name,
@ -136,11 +139,7 @@ class GenerateLR0(object):
the symbol.
"""
seeds = [
Configuration(
name=config.name,
symbols=config.symbols,
position=config.position + 1,
)
config.replace(position=config.position + 1)
for config in config_set
if config.at_symbol(symbol)
]
@ -380,6 +379,7 @@ class GenerateSLR1(GenerateLR0):
return follow
def parse(table, input, trace=False):
"""Parse the input with the generated parsing table and return the
concrete syntax tree.