def test_soft_keywords(self) -> None: grammar_source = """ start: expr+ NEWLINE? ENDMARKER expr: "foo" """ grammar = parse_string(grammar_source, GrammarParser) parser_source = generate_c_parser_source(grammar) assert "expect_soft_keyword" in parser_source
def test_extension_name(tmp_path: PurePath) -> None: grammar_source = """ @modulename 'alternative_name' start: expr+ NEWLINE? ENDMARKER expr: x=NAME """ grammar = parse_string(grammar_source, GrammarParser) parser_source = generate_c_parser_source(grammar) assert "PyInit_alternative_name" in parser_source assert '.m_name = "alternative_name"' in parser_source
def test_headers_and_trailer(tmp_path: PurePath) -> None: grammar_source = """ @header 'SOME HEADER' @subheader 'SOME SUBHEADER' @trailer 'SOME TRAILER' start: expr+ NEWLINE? ENDMARKER expr: x=NAME """ grammar = parse_string(grammar_source, GrammarParser) parser_source = generate_c_parser_source(grammar) assert "SOME HEADER" in parser_source assert "SOME SUBHEADER" in parser_source assert "SOME TRAILER" in parser_source