diff --git a/bin/sixtypical b/bin/sixtypical index 96b471d..6b1932d 100755 --- a/bin/sixtypical +++ b/bin/sixtypical @@ -66,32 +66,32 @@ def process_input_files(filenames, options): fa.analyze_program(program) if options.dump_fallthru_info: - fallthru_map = dict(fa.fallthru_map) - sys.stdout.write(json.dumps(fallthru_map, indent=4, sort_keys=True)) - sys.stdout.write("\n") - - fa.find_ancestors() - - if options.debug and options.dump_fallthru_info: - sys.stdout.write("*** ancestors:\n") - sys.stdout.write(json.dumps(fa.ancestor_map, indent=4, sort_keys=True)) + sys.stdout.write(json.dumps(fa.fallthru_map, indent=4, sort_keys=True)) sys.stdout.write("\n") fa.find_cycles() - if fa.cycles_found: + while fa.cycles_found: if options.dump_fallthru_info: + + if options.debug: + sys.stdout.write("*** ancestors:\n") + sys.stdout.write(json.dumps(fa.ancestor_map, indent=4, sort_keys=True)) + sys.stdout.write("\n") + sys.stdout.write("*** cycles found:\n") sys.stdout.write(json.dumps(sorted(fa.cycles_found), indent=4, sort_keys=True)) sys.stdout.write("\n") - fa.break_cycles() + fa.break_cycle() - if options.dump_fallthru_info and fallthru_map != fa.fallthru_map: - sys.stdout.write("*** after breaking cycles:\n") + if options.dump_fallthru_info: + sys.stdout.write("*** after breaking cycle:\n") sys.stdout.write(json.dumps(fa.fallthru_map, indent=4, sort_keys=True)) sys.stdout.write("\n") + fa.find_cycles() + if options.analyze_only: return diff --git a/src/sixtypical/fallthru.py b/src/sixtypical/fallthru.py index 62997f8..f0ca70d 100644 --- a/src/sixtypical/fallthru.py +++ b/src/sixtypical/fallthru.py @@ -24,25 +24,27 @@ class FallthruAnalyzer(object): self.fallthru_map = dict([(k, sorted(v)) for k, v in fallthru_map.iteritems()]) return self.fallthru_map - def find_ancestors(self): + def find_cycles(self): self.ancestor_map = {} for key in self.fallthru_map: ancestors = set() make_transitive_closure(self.fallthru_map, key, ancestors) self.ancestor_map[key] = sorted(ancestors) - return self.ancestor_map - def find_cycles(self): self.cycles_found = set() for key in self.ancestor_map: if key in self.ancestor_map[key]: self.cycles_found.add(key) + return self.cycles_found - def break_cycles(self): + def break_cycle(self): + cycle_to_break = sorted(self.cycles_found)[0] + cycles_to_break = set([cycle_to_break]) + new_fallthru_map = {} for key in self.fallthru_map: - values = set(self.fallthru_map[key]) - self.cycles_found + values = set(self.fallthru_map[key]) - cycles_to_break if values: new_fallthru_map[key] = sorted(values) self.fallthru_map = new_fallthru_map diff --git a/tests/SixtyPical Fallthru.md b/tests/SixtyPical Fallthru.md index 72efa67..7c4662a 100644 --- a/tests/SixtyPical Fallthru.md +++ b/tests/SixtyPical Fallthru.md @@ -139,7 +139,7 @@ fall through to the other. = "bar", = "foo" = ] - = *** after breaking cycles: + = *** after breaking cycle: = { = "bar": [ = "foo"