{"id":4796,"library":"tatsu","title":"TatSu: PEG Parser Generator","description":"TatSu is a Python library that takes a grammar defined in a variation of EBNF (Extended Backus–Naur Form) and generates a memoizing PEG (Parsing Expression Grammar) / Packrat parser. It is actively maintained with frequent minor releases, providing a powerful tool for creating custom parsers and Abstract Syntax Trees (ASTs). The current version is 5.18.0.","status":"active","version":"5.18.0","language":"en","source_language":"en","source_url":"https://github.com/neogeny/TatSu","tags":["parser","generator","PEG","EBNF","grammar","AST","parsing-expression-grammar"],"install":[{"cmd":"pip install TatSu","lang":"bash","label":"Install TatSu"}],"dependencies":[{"reason":"TatSu requires Python 3.12 or newer. For older Python versions, consider 'TatSu-LTS'.","package":"Python","optional":false}],"imports":[{"note":"Used to compile a grammar string into a callable parser.","symbol":"compile","correct":"from tatsu import compile"},{"note":"Used to parse input directly with a grammar string, returning an AST.","symbol":"parse","correct":"from tatsu import parse"},{"note":"For advanced configuration of the parser behavior.","symbol":"ParserConfig","correct":"from tatsu.parserconfig import ParserConfig"}],"quickstart":{"code":"from tatsu import parse\n\ngrammar = r'''\n    @@grammar::Calc\n    start: expression $ ;\n    expression: term (('+' | '-') term)* ;\n    term: factor (('*' | '/') factor)* ;\n    factor: NUMBER | '(' expression ')' ;\n    NUMBER: /\\d+/ ;\n'''\n\ninput_text = '1 + 2 * (3 - 4)'\n\ntry:\n    # Parse the input using the grammar\n    ast = parse(grammar, input_text)\n    print(f'Input: {input_text}')\n    print(f'AST: {ast}')\n\n    # Example with a simple calculation (requires a semantics class for evaluation)\n    # For a full calculation example, typically a semantics class is used.\n    # For this quickstart, we just show the parsing to AST.\nexcept Exception as e:\n    print(f'Error parsing: {e}')","lang":"python","description":"This quickstart defines a simple calculator grammar and uses `tatsu.parse` to directly parse an input string, producing an Abstract Syntax Tree (AST). For complex parsing logic or evaluation, a custom 'semantics' class is typically passed to the parse function."},"warnings":[{"fix":"Upgrade to Python 3.12 or newer. For older Python versions, consider using the `TatSu-LTS` fork.","message":"Python 3.10 and 3.11 are no longer officially supported as of v5.16.0. TatSu now requires Python >= 3.12. The GitHub README indicates a preference for Python >= 3.13.","severity":"breaking","affected_versions":">=5.16.0"},{"fix":"Update `ParserConfig` (or grammar directives `@@comments` / `@@eol_comments`) to use `comments` and `eol_comments`. If multi-line matching is required, prepend `(?m)` to your regex pattern (e.g., `comments='(?m)/\\*.*?\\*/'`).","message":"The `comments_re` and `eol_comments_re` attributes were removed from `ParserConfig` in v5.13.0. Use `comments` and `eol_comments` instead. Additionally, `re.MULTILINE` is no longer enabled by default for comment regexes; users must explicitly add `(?m)` if multi-line matching is needed.","severity":"breaking","affected_versions":">=5.13.0"},{"fix":"Remove any `try...except FailedCut` blocks. Review parsing logic that might have implicitly relied on `FailedCut` for control flow.","message":"The `FailedCut` exception and its associated logic were removed in v5.15.0. Code that explicitly catches or relies on this exception will break.","severity":"breaking","affected_versions":">=5.15.0"},{"fix":"It is strongly recommended to regenerate any existing parsers using the latest TatSu version to benefit from improved speed, layout, features, and ensure compatibility.","message":"Generated parsers from older TatSu versions (prior to v5.16.0, and especially prior to v5.0) may not be compatible with newer TatSu runtime libraries. Significant internal refactoring, particularly around `ParserConfig` and AST generation, occurred in recent major versions (e.g., v5.17.0).","severity":"breaking","affected_versions":">=5.0.0, >=5.16.0"},{"fix":"Adjust code that processes the AST to expect `list` instances where `tuple` was previously returned, for example, when iterating over children or checking types.","message":"Rules and closures now return `list` objects instead of `tuple` objects in the generated AST. This changes the structural representation of the AST for rules that produce sequences or repetitions.","severity":"gotcha","affected_versions":">=5.17.0 (implied by major refactoring)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}