Ejemplo n.º 1
0
    def test_GIVEN_trying_to_parse_play_WHEN_eof_is_the_only_token_THEN_syntax_error_is_raised(
            self):
        tokens = [Token(TokenTypes.Eof)]
        parser = Parser(t for t in tokens)

        with self.assertRaises(SPLSyntaxError):
            parser.play()
Ejemplo n.º 2
0
    def test_GIVEN_two_characters_on_stage_WHEN_get_character_by_name_THEN_can_get_that_character(
            self):
        tokens = [Token(TokenTypes.Name, "C"), Token(TokenTypes.Eof)]

        parser = Parser(t for t in tokens)

        parser.onstage = ["A", "B"]
        parser.speaking = "A"

        self.assertEqual(parser.character_name(), "C")
Ejemplo n.º 3
0
    def test_GIVEN_two_characters_on_stage_WHEN_one_speaking_THEN_2nd_person_pronoun_gets_not_speaking_character(
            self):
        tokens = [Token(TokenTypes.SecondPronoun), Token(TokenTypes.Eof)]

        parser = Parser(t for t in tokens)

        parser.onstage = ["A", "B"]
        parser.speaking = "A"

        self.assertEqual(parser.character_name(), "B")
Ejemplo n.º 4
0
    def test_GIVEN_trying_to_parse_play_WHEN_minimal_valid_play_THEN_no_errors_raised(
            self):
        tokens = [Token(TokenTypes.EndLine)]  # Have to have an initial line.
        tokens = _add_act(tokens)
        tokens = _add_scene(tokens)
        tokens.append(Token(TokenTypes.Eof))

        parser = Parser(t for t in tokens)

        parser.play()
Ejemplo n.º 5
0
    def test_GIVEN_exeunt_statement_WHEN_parsing_stage_control_THEN_no_parse_error(
            self):
        tokens = [
            Token(TokenTypes.OpenSqBracket),
            Token(TokenTypes.Exeunt),
            Token(TokenTypes.CloseSqBracket),
            Token(TokenTypes.Eof),
        ]

        parser = Parser(t for t in tokens)

        parser.stagecontrol()
Ejemplo n.º 6
0
    def test_GIVEN_enter_statement_with_one_character_WHEN_parsing_stage_control_THEN_no_parse_error(
            self):
        tokens = [
            Token(TokenTypes.OpenSqBracket),
            Token(TokenTypes.Enter),
            Token(TokenTypes.Name, "A"),
            Token(TokenTypes.CloseSqBracket),
            Token(TokenTypes.Eof),
        ]

        parser = Parser(t for t in tokens)

        parser.stagecontrol()
Ejemplo n.º 7
0
    def test_GIVEN_enter_statement_with_no_characters_WHEN_parsing_stage_control_THEN_parse_error(
            self):
        tokens = [
            Token(TokenTypes.OpenSqBracket),
            Token(TokenTypes.Enter),
            Token(TokenTypes.CloseSqBracket),
            Token(TokenTypes.Eof),
        ]

        parser = Parser(t for t in tokens)

        with self.assertRaises(SPLSyntaxError):
            parser.stagecontrol()
Ejemplo n.º 8
0
    def test_GIVEN_variable_does_not_exist_WHEN_declaring_variable_THEN_no_parse_error(
            self):
        tokens = [
            Token(TokenTypes.Name, "A"),
            Token(TokenTypes.Comma),
            Token(TokenTypes.Noun, 1),
            Token(TokenTypes.EndLine, 1),
            Token(TokenTypes.Eof, 1),
        ]

        parser = Parser(t for t in tokens)

        parser.var_assignment()
Ejemplo n.º 9
0
def main(input_file, output_dir, cls_name, cls_maj_version, cls_min_version):
    with open(input_file) as f:
        spl_lexer = Lexer(f.read())

    spl_parser = Parser(spl_lexer.token_generator())

    ast = spl_parser.play()
    asl = flatten_ast(ast)

    cls = Builder(cls_name).asl_dump(asl).build()
    cls.set_version(cls_maj_version, cls_min_version)

    Exporter(cls).export_as_file(output_dir)
Ejemplo n.º 10
0
    def test_GIVEN_a_character_not_on_stage_WHEN_that_character_leaves_THEN_parse_error(
            self):
        tokens = [
            Token(TokenTypes.OpenSqBracket),
            Token(TokenTypes.Exit),
            Token(TokenTypes.Name, "A"),
            Token(TokenTypes.CloseSqBracket),
            Token(TokenTypes.Eof),
        ]

        parser = Parser(t for t in tokens)

        with self.assertRaises(SPLSyntaxError):
            parser.stagecontrol()
Ejemplo n.º 11
0
    def test_GIVEN_a_character_on_stage_WHEN_that_character_leaves_THEN_no_parse_error(
            self):
        tokens = [
            Token(TokenTypes.OpenSqBracket),
            Token(TokenTypes.Exit),
            Token(TokenTypes.Name, "A"),
            Token(TokenTypes.CloseSqBracket),
            Token(TokenTypes.Eof),
        ]

        parser = Parser(t for t in tokens)
        parser.onstage = ["A"]

        parser.stagecontrol()
Ejemplo n.º 12
0
    def test_GIVEN_many_characters_on_stage_WHEN_exeunt_THEN_noone_left_on_stage(
            self):
        tokens = [
            Token(TokenTypes.OpenSqBracket),
            Token(TokenTypes.Exeunt),
            Token(TokenTypes.CloseSqBracket),
            Token(TokenTypes.Eof),
        ]

        parser = Parser(t for t in tokens)

        parser.onstage = ["A", "B", "C", "D"]

        parser.stagecontrol()

        self.assertEqual(parser.onstage, [])
Ejemplo n.º 13
0
    def test_GIVEN_variable_already_exists_WHEN_declaring_variable_THEN_parse_error(
            self):
        tokens = [
            Token(TokenTypes.Name, "A"),
            Token(TokenTypes.Comma),
            Token(TokenTypes.Noun, 1),
            Token(TokenTypes.EndLine, 1),
            Token(TokenTypes.Eof, 1),
        ]

        parser = Parser(t for t in tokens)

        parser.vars_table = ["A"]

        with self.assertRaises(SPLSyntaxError):
            parser.var_assignment()
Ejemplo n.º 14
0
    def test_GIVEN_nonsense_token_WHEN_get_character_by_name_THEN_parse_error(
            self):
        tokens = [Token(TokenTypes.Numeral), Token(TokenTypes.Eof)]

        parser = Parser(t for t in tokens)

        parser.onstage = ["A", "B"]
        parser.speaking = "A"

        with self.assertRaises(SPLSyntaxError):
            parser.character_name()