def test_given_reference_followed_by_reference_then_lookahead_is_first_set( self) -> None: grammar = Grammar(Rule('A', ['B', 'X']), Rule('B', ['x']), Rule('X', ['a']), Rule('X', ['b'])) state = RuleState(0, 0, {'x'}) self.assertEqual({RuleState(1, 0, {'a', 'b'})}, state.follow_states(grammar))
def test_given_last_unprocessed_reference_then_lookaheads_of_parent( self) -> None: grammar = Grammar(Rule('A', ['x', 'B']), Rule('A', ['B', 'x']), Rule('B', ['x'])) state = RuleState(0, 1, {'a'}) self.assertEqual({RuleState(2, 0, {'a'})}, state.follow_states(grammar))
def test_given_reference_followed_by_recursion_then_lookahead_is_first_set( self) -> None: grammar = Grammar(Rule('X', ['a']), Rule('X', ['b', 'X', 'X'])) state = RuleState(1, 1, {'x'}) expected = {RuleState(0, 0, {'a', 'b'}), RuleState(1, 0, {'a', 'b'})} self.assertEqual(expected, state.follow_states(grammar))
def test_given_unprocessed_reference_then_initial_reference_states( self) -> None: grammar = Grammar(Rule('A', ['B']), Rule('B', ['b'])) state = RuleState(0, 0, {'b'}) self.assertEqual({RuleState(1, 0, {'b'})}, state.follow_states(grammar))
def test_given_unprocessed_terminal_then_no_follow_states(self) -> None: grammar = Grammar(Rule('A', ['a'])) state = RuleState(0, 0, {'a'}) self.assertEqual(set(), state.follow_states(grammar))