{"id":15008843,"url":"https://github.com/neogeny/tatsu","last_synced_at":"2025-04-15T03:50:23.321Z","repository":{"id":20465098,"uuid":"89985463","full_name":"neogeny/TatSu","owner":"neogeny","description":"竜 TatSu generates Python parsers from grammars in a variation of EBNF","archived":false,"fork":false,"pushed_at":"2025-01-19T22:26:08.000Z","size":1275,"stargazers_count":420,"open_issues_count":19,"forks_count":49,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-15T03:49:58.590Z","etag":null,"topics":["ast","ebnf","grammar","parser","parser-generator","parser-library","python","python2","python3","walker"],"latest_commit_sha":null,"homepage":"https://tatsu.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neogeny.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"docs/contributing.rst","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/support.rst","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"custom":null}},"created_at":"2017-05-02T02:58:58.000Z","updated_at":"2025-04-09T05:42:29.000Z","dependencies_parsed_at":"2023-11-06T02:23:27.102Z","dependency_job_id":"f1ec5a8b-03a0-4f45-b5b4-809a70e8d043","html_url":"https://github.com/neogeny/TatSu","commit_stats":{"total_commits":867,"total_committers":32,"mean_commits":27.09375,"dds":0.06689734717416373,"last_synced_commit":"fa2df3889c4ced83d39ea60eacf0d48f17edb699"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neogeny%2FTatSu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neogeny%2FTatSu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neogeny%2FTatSu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neogeny%2FTatSu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neogeny","download_url":"https://codeload.github.com/neogeny/TatSu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003944,"owners_count":21196794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","ebnf","grammar","parser","parser-generator","parser-library","python","python2","python3","walker"],"created_at":"2024-09-24T19:20:55.901Z","updated_at":"2025-04-15T03:50:23.303Z","avatar_url":"https://github.com/neogeny.png","language":"Python","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=P9PV7ZACB669J"],"categories":[],"sub_categories":[],"readme":".. |dragon| unicode:: 0x7ADC .. unicode dragon\n.. |nbsp| unicode:: 0xA0 .. non breakable space\n.. |TatSu| replace:: |dragon|\\ |nbsp|\\ **TatSu**\n.. |TatSu-LTS| replace:: |dragon|\\ |nbsp|\\ **TatSu-LTS**\n.. _RELEASES: https://github.com/neogeny/TatSu/releases\n\n|license| |pyversions| |fury| |downloads| |actions| |docs|\n\n    *At least for the people who send me mail about a new language that\n    they're designing, the general advice is: do it to learn about how\n    to write a compiler. Don't have any expectations that anyone will\n    use it, unless you hook up with some sort of organization in a\n    position to push it hard. It's a lottery, and some can buy a lot of\n    the tickets. There are plenty of beautiful languages (more beautiful\n    than C) that didn't catch on. But someone does win the lottery, and\n    doing a language at least teaches you something.*\n\n    `Dennis Ritchie`_ (1941-2011) Creator of the C_ programming\n    language and of Unix_\n\n\n|TatSu|\n=======\n\n|TatSu| is a tool that takes grammars in a variation of `EBNF`_ as input, and\noutputs `memoizing`_ (`Packrat`_) `PEG`_ parsers in `Python`_.\n\nWhy use a PEG_ parser? Because `regular languages`_ (those parsable with Python's ``re`` package) *\"cannot count\"*. Any language with nested structures or with balancing of demarcations requires more than regular expressions to be parsed.\n\n|TatSu| can compile a grammar stored in a string into a\n``tatsu.grammars.Grammar`` object that can be used to parse any given\ninput, much like the `re`_ module does with regular expressions, or it can generate a Python_ module that implements the parser.\n\n|TatSu| supports `left-recursive`_  rules in PEG_ grammars using the\nalgorithm_ by *Laurent* and *Mens*. The generated AST_ has the expected left associativity.\n\n|TatSu| requires a maintained version of Python (\u003e=3.12 at the moment).  While no code\nin |TatSu| yet depends on new language or standard library features,\nthe authors don't want to be constrained by Python version compatibility considerations\nwhen developing features that will be part of future releases.\n\n*If you need support for previous versions of Python, please consider* `TatSu-LTS`_,\n*a  friendly fork of* |TatSu| *aimed at compatibility with other versions of Python still used by\nmany projects. The developers of both projects work together to promote compatibility\nwith most versions of Python.*\n\n.. _algorithm: http://norswap.com/pubs/sle2016.pdf\n.. _TatSu-LTS: https://pypi.org/project/TatSu-LTS/\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    $ pip install TatSu\n\n\nUsing the Tool\n--------------\n\n|TatSu| can be used as a library, much like `Python`_'s ``re``, by embedding grammars as strings and generating grammar models instead of generating Python_ code.\n\nThis compiles the grammar and generates an in-memory *parser* that can subsequently be used for parsing input with:\n\n.. code-block:: python\n\n   parser = tatsu.compile(grammar)\n\n\nCompiles the grammar and parses the given input producing an AST_ as result:\n\n.. code-block:: python\n\n    ast = tatsu.parse(grammar, input)\n\nThe result is equivalent to calling:\n\n.. code-block:: python\n\n    parser = compile(grammar)\n    ast = parser.parse(input)\n\nCompiled grammars are cached for efficiency.\n\nThis compiles the grammar to the `Python`_ sourcecode that implements the parser:\n\n.. code-block:: python\n\n    parser_source = tatsu.to_python_sourcecode(grammar)\n\nThis is an example of how to use |TatSu| as a library:\n\n.. code-block:: python\n\n    GRAMMAR = '''\n        @@grammar::CALC\n\n\n        start = expression $ ;\n\n\n        expression\n            =\n            | expression '+' term\n            | expression '-' term\n            | term\n            ;\n\n\n        term\n            =\n            | term '*' factor\n            | term '/' factor\n            | factor\n            ;\n\n\n        factor\n            =\n            | '(' expression ')'\n            | number\n            ;\n\n\n        number = /\\d+/ ;\n    '''\n\n\n    if __name__ == '__main__':\n        import json\n        from tatsu import parse\n        from tatsu.util import asjson\n\n        ast = parse(GRAMMAR, '3 + 5 * ( 10 - 20 )')\n        print(json.dumps(asjson(ast), indent=2))\n..\n\n|TatSu| will use the first rule defined in the grammar as the *start* rule.\n\nThis is the output:\n\n.. code-block:: console\n\n    [\n      \"3\",\n      \"+\",\n      [\n        \"5\",\n        \"*\",\n        [\n          \"10\",\n          \"-\",\n          \"20\"\n        ]\n      ]\n    ]\n\nDocumentation\n-------------\n\nFor a detailed explanation of what |TatSu| is capable of, please see the\ndocumentation_.\n\n.. _documentation: http://tatsu.readthedocs.io/\n\n\nQuestions?\n----------\n\nPlease use the `[tatsu]`_ tag on `StackOverflow`_ for general Q\u0026A, and limit\nGithub issues to bugs, enhancement proposals, and feature requests.\n\n.. _[tatsu]: https://stackoverflow.com/tags/tatsu/info\n\n\nChanges\n-------\n\nSee the `RELEASES`_ for details.\n\n\nLicense\n-------\n\nYou may use |TatSu| under the terms of the `BSD`_-style license\ndescribed in the enclosed `LICENSE.txt`_ file. *If your project\nrequires different licensing* please `email`_.\n\n\n.. _ANTLR: http://www.antlr.org/\n.. _AST: http://en.wikipedia.org/wiki/Abstract_syntax_tree\n.. _Abstract Syntax Tree: http://en.wikipedia.org/wiki/Abstract_syntax_tree\n.. _Algol W: http://en.wikipedia.org/wiki/Algol_W\n.. _Algorithms + Data Structures = Programs: http://www.amazon.com/Algorithms-Structures-Prentice-Hall-Automatic-Computation/dp/0130224189/\n.. _BSD: http://en.wikipedia.org/wiki/BSD_licenses#2-clause_license_.28.22Simplified_BSD_License.22_or_.22FreeBSD_License.22.29\n.. _Basel Shishani: https://bitbucket.org/basel-shishani\n.. _C: http://en.wikipedia.org/wiki/C_language\n.. _CHANGELOG: https://github.com/neogeny/TatSu/releases\n.. _CSAIL at MIT: http://www.csail.mit.edu/\n.. _Cyclomatic complexity: http://en.wikipedia.org/wiki/Cyclomatic_complexity\n.. _David Röthlisberger: https://bitbucket.org/drothlis/\n.. _Dennis Ritchie: http://en.wikipedia.org/wiki/Dennis_Ritchie\n.. _EBNF: http://en.wikipedia.org/wiki/Ebnf\n.. _English: http://en.wikipedia.org/wiki/English_grammar\n.. _Euler: http://en.wikipedia.org/wiki/Euler_programming_language\n.. _Grako: https://bitbucket.org/neogeny/grako/\n.. _Jack: http://en.wikipedia.org/wiki/Javacc\n.. _Japanese: http://en.wikipedia.org/wiki/Japanese_grammar\n.. _KLOC: http://en.wikipedia.org/wiki/KLOC\n.. _Kathryn Long: https://bitbucket.org/starkat\n.. _Keywords: https://en.wikipedia.org/wiki/Reserved_word\n.. _`left-recursive`: https://en.wikipedia.org/wiki/Left_recursion\n.. _LL(1): http://en.wikipedia.org/wiki/LL(1)\n.. _Marcus Brinkmann: http://blog.marcus-brinkmann.de/\n.. _MediaWiki: http://www.mediawiki.org/wiki/MediaWiki\n.. _Modula-2: http://en.wikipedia.org/wiki/Modula-2\n.. _Modula: http://en.wikipedia.org/wiki/Modula\n.. _Oberon-2: http://en.wikipedia.org/wiki/Oberon-2\n.. _Oberon: http://en.wikipedia.org/wiki/Oberon_(programming_language)\n.. _PEG and Packrat parsing mailing list: https://lists.csail.mit.edu/mailman/listinfo/peg\n.. _PEG.js: http://pegjs.majda.cz/\n.. _PEG: http://en.wikipedia.org/wiki/Parsing_expression_grammar\n.. _PL/0: http://en.wikipedia.org/wiki/PL/0\n.. _Packrat: http://bford.info/packrat/\n.. _Pascal: http://en.wikipedia.org/wiki/Pascal_programming_language\n.. _Paul Sargent: https://bitbucket.org/PaulS/\n.. _Perl: http://www.perl.org/\n.. _PyPy team: http://pypy.org/people.html\n.. _PyPy: http://pypy.org/\n.. _Python Weekly: http://www.pythonweekly.com/\n.. _Python: http://python.org\n.. _Reserved Words: https://en.wikipedia.org/wiki/Reserved_word\n.. _Robert Speer: https://bitbucket.org/r_speer\n.. _Ruby: http://www.ruby-lang.org/\n.. _Semantic Graph: http://en.wikipedia.org/wiki/Abstract_semantic_graph\n.. _StackOverflow: http://stackoverflow.com/tags/tatsu/info\n.. _Sublime Text: https://www.sublimetext.com\n.. _TatSu Forum: https://groups.google.com/forum/?fromgroups#!forum/tatsu\n.. _UCAB: http://www.ucab.edu.ve/\n.. _USB: http://www.usb.ve/\n.. _Unix: http://en.wikipedia.org/wiki/Unix\n.. _VIM: http://www.vim.org/\n.. _WTK: http://en.wikipedia.org/wiki/Well-known_text\n.. _Warth et al: http://www.vpri.org/pdf/tr2007002_packrat.pdf\n.. _Well-known text: http://en.wikipedia.org/wiki/Well-known_text\n.. _Wirth: http://en.wikipedia.org/wiki/Niklaus_Wirth\n.. _`LICENSE.txt`: LICENSE.txt\n.. _basel-shishani: https://bitbucket.org/basel-shishani\n.. _blog post: http://dietbuddha.blogspot.com/2012/12/52python-encapsulating-exceptions-with.html\n.. _colorama: https://pypi.python.org/pypi/colorama/\n.. _context managers: http://docs.python.org/2/library/contextlib.html\n.. _declensions: http://en.wikipedia.org/wiki/Declension\n.. _drothlis: https://bitbucket.org/drothlis\n.. _email: mailto:apalala@gmail.com\n.. _exceptions: http://www.jeffknupp.com/blog/2013/02/06/write-cleaner-python-use-exceptions/\n.. _franz\\_g: https://bitbucket.org/franz_g\n.. _gapag: https://bitbucket.org/gapag\n.. _gegenschall: https://bitbucket.org/gegenschall\n.. _gkimbar: https://bitbucket.org/gkimbar\n.. _introduced: http://dl.acm.org/citation.cfm?id=964001.964011\n.. _jimon: https://bitbucket.org/jimon\n.. _keyword: https://en.wikipedia.org/wiki/Reserved_word\n.. _keywords: https://en.wikipedia.org/wiki/Reserved_word\n.. _lambdafu: http://blog.marcus-brinkmann.de/\n.. _leewz: https://bitbucket.org/leewz\n.. _linkdd: https://bitbucket.org/linkdd\n.. _make a donation: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=P9PV7ZACB669J\n.. _memoizing: http://en.wikipedia.org/wiki/Memoization\n.. _nehz: https://bitbucket.org/nehz\n.. _neumond: https://bitbucket.org/neumond\n.. _parsewkt: https://github.com/cleder/parsewkt\n.. _pauls: https://bitbucket.org/pauls\n.. _pgebhard: https://bitbucket.org/pgebhard\n.. _pygraphviz: https://pypi.python.org/pypi/pygraphviz\n.. _r\\_speer: https://bitbucket.org/r_speer\n.. _raw string literal: https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals\n.. _re: https://docs.python.org/3.7/library/re.html\n.. _regular languages: https://en.wikipedia.org/wiki/Regular_language\n.. _regex: https://pypi.python.org/pypi/regex\n.. _siemer: https://bitbucket.org/siemer\n.. _sjbrownBitbucket: https://bitbucket.org/sjbrownBitbucket\n.. _smc.mw: https://github.com/lambdafu/smc.mw\n.. _starkat: https://bitbucket.org/starkat\n.. _tonico\\_strasser: https://bitbucket.org/tonico_strasser\n.. _vinay.sajip: https://bitbucket.org/vinay.sajip\n.. _vmuriart: https://bitbucket.org/vmuriart\n\n.. |fury| image:: https://badge.fury.io/py/TatSu.svg\n   :target: https://badge.fury.io/py/TatSu\n.. |license| image:: https://img.shields.io/badge/license-BSD-blue.svg\n   :target: https://raw.githubusercontent.com/neogeny/tatsu/master/LICENSE.txt\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/tatsu.svg\n   :target: https://pypi.python.org/pypi/tatsu\n.. |actions| image:: https://github.com/neogeny/TatSu/actions/workflows/default.yml/badge.svg\n   :target: https://github.com/neogeny/TatSu/actions/workflows/default.yml\n.. |docs| image:: https://readthedocs.org/projects/tatsu/badge/?version=stable\n   :target: http://tatsu.readthedocs.io/en/stable/\n.. |downloads| image:: https://img.shields.io/pypi/dm/TatSu.svg\n   :target: https://pypistats.org/packages/tatsu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneogeny%2Ftatsu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneogeny%2Ftatsu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneogeny%2Ftatsu/lists"}