Skip to main content

prototype of a sytaxparser

Project description

python3 -m pip install syntax-parser-prototype
python3 -m pip install syntax-parser-prototype[visualisation]

syntax-parser-prototype

Basic objects for the specific implementation of a syntax parser.

Object categories

[.*]Token

(Parsing result) single token

[.*]Branch

(Parsing result) container for tokens

Root[.*]

objects for the top level (not intended for modification)

Phrase

configuration object whose behavior is to be implemented by modifying the class.

The main behavior is implemented by the more detailed definition of the start and end methods. Additional predetermined interfaces are also declared in the corresponding docstrings.

Nesting, branches, and suffixes are defined by passing additional phrase derivatives to a instace.

Parsing

The top-level object RootPhrase provides the entry points for the parsing process. The result will be a RootBranch.

Visualisation

The visualization module provides some support for debugging. All necessary packages can be installed separately.

python3 -m pip install syntax-parser-prototype[visualisation]

Overview

visualisation.start_structure_graph_app(root)
https://raw.githubusercontent.com/srccircumflex/syntax-parser-prototype/master/docs/phrase-graph-app.png
visualisation.html_on_server(result)
https://raw.githubusercontent.com/srccircumflex/syntax-parser-prototype/master/docs/html-app.png
print(visualisation.pretty_xml_result(result))
<?xml version="1.0" ?>
<RB phrase="#root">
    <RN coord="0:0:0">''</RN>
    <B phrase="consoleline">
        <N coord="0:0:3">'&gt;&gt;&gt;'</N>
        <T coord="0:3:4">' '</T>
        <B phrase="function">
            <N coord="0:4:16">'prettyprint('</N>
            <B phrase="string">
                <N coord="0:16:17">"'"</N>
                <T coord="0:17:66">'( (a * b / (c + a)) * (b / (c  a) * b) / c ) + a'</T>
                <N coord="0:66:67">"'"</N>
            </B>
            <N coord="0:67:68">')'</N>
        </B>
        <N coord="0:68:68">''</N>
    </B>
    <RT coord="0:68:69">'\n'</RT>
    <B phrase="bracket">
        <N coord="1:0:1">'('</N>
        <T coord="1:1:2">'\n'</T>
        <T coord="2:0:3">'   '</T>
        <B phrase="bracket">
            <N coord="2:3:4">'('</N>
            <T coord="2:4:5">'\n'</T>
            <T coord="3:0:7">'       '</T>
            <T coord="3:7:8">'a'</T>
            <T coord="3:8:9">' '</T>
            <T coord="3:9:10">'*'</T>
            <T coord="3:10:11">' '</T>
            <T coord="3:11:12">'b'</T>
            <T coord="3:12:13">' '</T>
            <T coord="3:13:14">'/'</T>
            <T coord="3:14:15">' '</T>
            <B phrase="bracket">
                <N coord="3:15:16">'('</N>
                <T coord="3:16:17">'c'</T>
                <T coord="3:17:18">' '</T>
                <T coord="3:18:19">'+'</T>
                <T coord="3:19:20">' '</T>
                <T coord="3:20:21">'a'</T>
                <N coord="3:21:22">')'</N>
            </B>
            <T coord="3:22:23">'\n'</T>
            <T coord="4:0:3">'   '</T>
            <N coord="4:3:4">')'</N>
        </B>
        <T coord="4:4:5">' '</T>
        <T coord="4:5:6">'*'</T>
        <T coord="4:6:7">' '</T>
        <B phrase="bracket">
            <N coord="4:7:8">'('</N>
            <T coord="4:8:9">'\n'</T>
            <T coord="5:0:7">'       '</T>
            <T coord="5:7:8">'b'</T>
            <T coord="5:8:9">' '</T>
            <T coord="5:9:10">'/'</T>
            <T coord="5:10:11">' '</T>
            <B phrase="bracket">
                <N coord="5:11:12">'('</N>
                <T coord="5:12:13">'c'</T>
                <T coord="5:13:16">'  '</T>
                <T coord="5:16:17">'a'</T>
                <N coord="5:17:18">')'</N>
            </B>
            <T coord="5:18:19">' '</T>
            <T coord="5:19:20">'*'</T>
            <T coord="5:20:21">' '</T>
            <T coord="5:21:22">'b'</T>
            <T coord="5:22:23">'\n'</T>
            <T coord="6:0:3">'   '</T>
            <N coord="6:3:4">')'</N>
        </B>
        <T coord="6:4:5">' '</T>
        <T coord="6:5:6">'/'</T>
        <T coord="6:6:7">' '</T>
        <T coord="6:7:8">'c'</T>
        <T coord="6:8:10">' \n'</T>
        <N coord="7:0:1">')'</N>
    </B>
    <RT coord="7:1:2">' '</RT>
    <T coord="7:2:3">'+'</T>
    <RT coord="7:3:4">' '</RT>
    <T coord="7:4:5">'a'</T>
    <RT coord="7:5:6">'\n'</RT>
    <RT coord="8:0:1">'\n'</RT>
    <B phrase="consoleline">
        <N coord="9:0:3">'&gt;&gt;&gt;'</N>
        <T coord="9:3:4">' '</T>
        <B phrase="function">
            <N coord="9:4:8">'int('</N>
            <B phrase="string">
                <N coord="9:8:9">'"'</N>
                <T coord="9:9:11">'42'</T>
                <N coord="9:11:12">'"'</N>
                <B phrase="angular brackets">
                    <N coord="9:12:13">'['</N>
                    <T coord="9:13:16">'1:3'</T>
                    <N coord="9:16:17">']'</N>
                </B>
            </B>
            <T coord="9:17:18">' '</T>
            <T coord="9:18:19">'+'</T>
            <T coord="9:19:20">' '</T>
            <B phrase="string">
                <N coord="9:20:21">'"'</N>
                <T coord="9:21:22">'3'</T>
                <N coord="9:22:23">'"'</N>
            </B>
            <N coord="9:23:24">')'</N>
        </B>
        <T coord="9:24:25">' '</T>
        <T coord="9:25:26">'+'</T>
        <T coord="9:26:27">' '</T>
        <T coord="9:27:29">'19'</T>
        <N coord="9:29:29">''</N>
    </B>
    <RT coord="9:29:30">'\n'</RT>
    <T coord="10:0:2">'42'</T>
    <RT coord="10:2:3">'\n'</RT>
    <RN coord="10:3:3">''</RN>
</RB>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

syntax_parser_prototype-1.1.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

syntax_parser_prototype-1.1.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file syntax_parser_prototype-1.1.1.tar.gz.

File metadata

  • Download URL: syntax_parser_prototype-1.1.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for syntax_parser_prototype-1.1.1.tar.gz
Algorithm Hash digest
SHA256 8efcc2ae3086c9a5d7fadb70671018765a26357ba320d39d5a61cf81827b5102
MD5 805107ce897243baef8209d4e5f94c4e
BLAKE2b-256 1955afe448c8660dde417639e8ec8ffb7247a22ba89b1ac1c766b8626344f193

See more details on using hashes here.

File details

Details for the file syntax_parser_prototype-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for syntax_parser_prototype-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd8be0041bd1768f4537ea2c2d908ab612a06a3f31d9055665029c6228f049e
MD5 4fcdfe5eddeb118169c57dab3f6e2be7
BLAKE2b-256 0c2a05de06f1f5b829d4d486e8aa144bca4542deb73a0314eb59d2e9b4c830d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page