Spaces Data

Minimal test - lines (344, 382)

path: .spaces[1].spaces[0].metrics.mi.mi_visual_studio
old: 45.13458793850137
new: 44.63585783179738

path: .spaces[1].spaces[0].metrics.mi.mi_original
old: 77.18014537483734
new: 76.32731689237352

path: .spaces[1].spaces[0].metrics.mi.mi_sei
old: 70.5448581048347
new: 71.37272167882625

path: .spaces[1].spaces[0].metrics.loc.cloc
old: 9.0
new: 11.0

path: .spaces[1].spaces[0].metrics.loc.sloc
old: 37.0
new: 39.0

Code

    def __init__(
            self,
            grammar: CanonicalGrammar,
            verbose: bool = False,
            progress: bool = False,
            debug: bool = False
    ) -> None:
        self.actions = []
        self.states = []
        self.state_cache = {}
        self.named_goals = []
        self.terminals = grammar.grammar.terminals
        self.nonterminals = typing.cast(
            typing.List[Nt],
            list(grammar.grammar.nonterminals.keys()))

        # typing.cast() doesn't actually check at run time, so let's do that:
        assert all(isinstance(nt, Nt) for nt in self.nonterminals)

        self.debug_info = debug
        self.exec_modes = grammar.grammar.exec_modes
        self.assume_inconsistent = True
        self.create_lr0_table(grammar, verbose, progress)
        self.fix_inconsistent_table(verbose, progress)
        # TODO: Optimize chains of actions into sequences.
        # Optimize by removing unused states.
        self.remove_all_unreachable_state(verbose, progress)
        # TODO: Statically compute replayed terms. (maybe?)
        # Replace reduce actions by programmatic stack manipulation.
        self.lower_reduce_actions(verbose, progress)
        # Fold Replay followed by Unwind instruction.
        self.fold_replay_unwind(verbose, progress)
        # Fold paths which have the same ending.
        self.fold_identical_endings(verbose, progress)
        # Group state with similar non-terminal edges close-by, to improve the
        # generated Rust code by grouping matched state numbers.
        self.group_nonterminal_states(verbose, progress)
        # Split shift states from epsilon states.
        # self.group_epsilon_states(verbose, progress)