From cf10891c199a2ea278b3ae1ce4659578dd283cc1 Mon Sep 17 00:00:00 2001 From: John Doty Date: Fri, 9 Dec 2016 06:37:57 -0800 Subject: [PATCH] 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. --- parser.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parser.py b/parser.py index ab60ff4..24d75de 100644 --- a/parser.py +++ b/parser.py @@ -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.