parse-ebnf


Nameparse-ebnf JSON
Version 1.0.2 PyPI version JSON
download
home_page
SummaryA parse tree generator for extended Backus-Naur form.
upload_time2023-08-11 17:43:58
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords ebnf extended backus-naur form parse tree parser
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Parse EBNF

[![PyPI - Version](https://img.shields.io/pypi/v/parse-ebnf.svg)](https://pypi.org/project/parse-ebnf)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/parse-ebnf.svg)](https://pypi.org/project/parse-ebnf)

-----

**Table of Contents**

- [Introduction](#introduction)
- [Installation](#installation)
- [Quick start](#quickstart)
- [Documentation](#documentation)
- [License](#license)

## Introduction

A simple and hacky parser for EBNF as defined by ISO. Give it an EBNF string and
it'll generate a **parse tree**. Note that this package does not parse the
described grammar.

## Installation

```console
pip install parse-ebnf
```
## Quick start

```python
from parse_ebnf import AST

#Your EBNF file goes here
ebnf = open('grammar.ebnf', 'r')

ast = AST()

try:
    #Will raise SyntaxError on error with an error message describing what went wrong
    ast.parse(ebnf.read) #You need to pass in a function that returns n characters where n is given as the first parameter.
finally:
    #Even after an error a partial tree will be generated.
    #str gives a text version of the parse tree(meant for debugging), while repr gives the text that it was produced from.
    print(str(ast))

print(f'Parsed the file creating a tree with {ast.count} nodes, height of {ast.height}. Each node has at MOST {ast.maxDegree} children.')

def DepthFirst(node, func):
    func(node)
    for child in node.children:
        DepthFirst(child, func)

#This will visit each node in the parse tree and print the line where its text begins
DepthFirst(ast.root, lambda node: print(node.startLine))

from parse_ebnf import ASTCommentNode

#Finds each comment in the file and prints its text content
for child in ast.root.children:
    if isinstance(child, ASTCommentNode):
        print(child.data)
```

## Documentation

Check the [github page](https://chaosinventor.github.io/parse-ebnf/) that
holds the documentation.

## License

`parse-ebnf` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "parse-ebnf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "EBNF,Extended Backus-Naur Form,Parse tree,Parser",
    "author": "",
    "author_email": "ChaosInventor <chaosinventor@yandex.com>",
    "download_url": "https://files.pythonhosted.org/packages/8d/74/2e5c6d92e94188dfa7bd4b0faedf1a0eae90634d9c235a406731cc68991b/parse_ebnf-1.0.2.tar.gz",
    "platform": null,
    "description": "# 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 import AST\n\n#Your EBNF file goes here\nebnf = open('grammar.ebnf', 'r')\n\nast = AST()\n\ntry:\n    #Will raise SyntaxError on error with an error message describing what went wrong\n    ast.parse(ebnf.read) #You need to pass in a function that returns n characters where n is given as the first parameter.\nfinally:\n    #Even after an error a partial tree will be generated.\n    #str gives a text version of the parse tree(meant for debugging), while repr gives the text that it was produced from.\n    print(str(ast))\n\nprint(f'Parsed the file creating a tree with {ast.count} nodes, height of {ast.height}. Each node has at MOST {ast.maxDegree} children.')\n\ndef DepthFirst(node, func):\n    func(node)\n    for child in node.children:\n        DepthFirst(child, func)\n\n#This will visit each node in the parse tree and print the line where its text begins\nDepthFirst(ast.root, lambda node: print(node.startLine))\n\nfrom parse_ebnf import ASTCommentNode\n\n#Finds each comment in the file and prints its text content\nfor child in ast.root.children:\n    if isinstance(child, ASTCommentNode):\n        print(child.data)\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",
    "bugtrack_url": null,
    "license": "",
    "summary": "A parse tree generator for extended Backus-Naur form.",
    "version": "1.0.2",
    "project_urls": {
        "Documentation": "https://github.com/ChaosInventor/parse-ebnf#readme",
        "Issues": "https://github.com/ChaosInventor/parse-ebnf/issues",
        "Source": "https://github.com/ChaosInventor/parse-ebnf"
    },
    "split_keywords": [
        "ebnf",
        "extended backus-naur form",
        "parse tree",
        "parser"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d4b1b970af8ed70c1f105f9a43ae30036137e61b3dd3a5edf0bd8d03b230d8d7",
                "md5": "9bd4c903c1f49ae49b728a1b1c37d982",
                "sha256": "9f95d18b57bd4dbe7125bdfa31a7de6951da58da49a4527dc0c6da3b1c9bf998"
            },
            "downloads": -1,
            "filename": "parse_ebnf-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9bd4c903c1f49ae49b728a1b1c37d982",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10970,
            "upload_time": "2023-08-11T17:43:56",
            "upload_time_iso_8601": "2023-08-11T17:43:56.748246Z",
            "url": "https://files.pythonhosted.org/packages/d4/b1/b970af8ed70c1f105f9a43ae30036137e61b3dd3a5edf0bd8d03b230d8d7/parse_ebnf-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8d742e5c6d92e94188dfa7bd4b0faedf1a0eae90634d9c235a406731cc68991b",
                "md5": "a07d630c560bd6e111f9300661f4b111",
                "sha256": "038874950091d603b3debb9c807b92efb98b18e7c132e0e7024fa78ba15aa66d"
            },
            "downloads": -1,
            "filename": "parse_ebnf-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a07d630c560bd6e111f9300661f4b111",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 20145,
            "upload_time": "2023-08-11T17:43:58",
            "upload_time_iso_8601": "2023-08-11T17:43:58.350099Z",
            "url": "https://files.pythonhosted.org/packages/8d/74/2e5c6d92e94188dfa7bd4b0faedf1a0eae90634d9c235a406731cc68991b/parse_ebnf-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-11 17:43:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ChaosInventor",
    "github_project": "parse-ebnf#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "parse-ebnf"
}
        
Elapsed time: 0.10205s