{"id":19369912,"url":"https://github.com/chaosinventor/parse-ebnf","last_synced_at":"2025-06-20T17:05:41.524Z","repository":{"id":186387934,"uuid":"675091592","full_name":"ChaosInventor/parse-ebnf","owner":"ChaosInventor","description":"Parser for EBNF written in python","archived":false,"fork":false,"pushed_at":"2024-08-31T11:30:35.000Z","size":156,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-23T11:38:04.619Z","etag":null,"topics":["ebnf","parser","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChaosInventor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-08-05T18:41:01.000Z","updated_at":"2025-04-10T03:27:25.000Z","dependencies_parsed_at":"2025-04-23T15:42:55.466Z","dependency_job_id":"b7bedfe1-49ff-42d7-ae36-13564b77c259","html_url":"https://github.com/ChaosInventor/parse-ebnf","commit_stats":null,"previous_names":["chaosinventor/parse-ebnf"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ChaosInventor/parse-ebnf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChaosInventor%2Fparse-ebnf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChaosInventor%2Fparse-ebnf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChaosInventor%2Fparse-ebnf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChaosInventor%2Fparse-ebnf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChaosInventor","download_url":"https://codeload.github.com/ChaosInventor/parse-ebnf/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChaosInventor%2Fparse-ebnf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260985060,"owners_count":23092880,"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":["ebnf","parser","python"],"created_at":"2024-11-10T08:13:43.166Z","updated_at":"2025-06-20T17:05:36.477Z","avatar_url":"https://github.com/ChaosInventor.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parse EBNF\n\n[![PyPI - Version](https://img.shields.io/pypi/v/parse-ebnf.svg)](https://pypi.org/project/parse-ebnf)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/parse-ebnf.svg)](https://pypi.org/project/parse-ebnf)\n\n-----\n\n**Table of Contents**\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Quick start](#quickstart)\n- [Documentation](#documentation)\n- [License](#license)\n\n## Introduction\n\nA simple and hacky parser for EBNF as defined by ISO. Give it an EBNF string and\nit'll generate a **parse tree**. Note that this package does not parse the\ndescribed grammar.\n\n## Installation\n\n```console\npip install parse-ebnf\n```\n## Quick start\n\n```python\nfrom parse_ebnf.parsing import ParsingError, parse_file\n\ntry:\n    #Your EBNF file goes here.\n    pt = parse_file(ebnf_path)\n    partial = False\nexcept ParsingError as e:\n    #If an exception occurs, a partial tree is generated. See the docs for\n    #details.\n    pt = e.parser.pt\n    partial = True\n\n#Prints the text that the tree was parsed from.\nprint(str(pt))\n#Prints a debug view of the tree.\nprint(repr(pt))\n\nprint(f'Parsing the file created a tree with {pt.count} nodes.')\nprint(f'The tree has a height of {pt.height}.')\nprint(f'Each node in the tree has at MOST {pt.maxDegree} children.')\n\ndef DepthFirst(node, partial, func):\n    #Partial nodes are in a mostly undefined state.\n    if not partial: func(node)\n    for child in node.children:\n        #If a node is partial, then its last child is partial. All other\n        #children are not partial.\n        if partial and child is node.children[-1]:\n            DepthFirst(child, True, func)\n        else:\n            DepthFirst(child, False, func)\n\n#This will visit each node in the parse tree and print the line where its\n#text begins.\nDepthFirst(pt.root, partial, lambda node: print(node.startLine))\n\nfrom parse_ebnf.nodes import Comment\n\n#Finds each comment in the file and prints its text content.\nfor child in pt.root.children:\n    if isinstance(child, Comment):\n        #A tree being partial means that its root is partial.\n        if partial and child is pt.root.children[-1]: continue\n        print(str(child))\n```\n\n## Documentation\n\nCheck the [github page](https://chaosinventor.github.io/parse-ebnf/) that\nholds the documentation.\n\n## License\n\n`parse-ebnf` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaosinventor%2Fparse-ebnf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaosinventor%2Fparse-ebnf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaosinventor%2Fparse-ebnf/lists"}