Skip to main content

prototype of a sytaxparser

Project description

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

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 RootTokenBranch.

Visualisation

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

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

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-2.0.1.tar.gz (12.5 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-2.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: syntax_parser_prototype-2.0.1.tar.gz
  • Upload date:
  • Size: 12.5 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-2.0.1.tar.gz
Algorithm Hash digest
SHA256 d1fab4895b0c1103225fc52555b470f775bc098035379232f596413927198b9f
MD5 3ef86fc16c7f5178669152fd859f4721
BLAKE2b-256 1231f6393d1177b47a4ecf446e6ad1a19c40ff4c2241b4e4cda3db5b5c8c9956

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for syntax_parser_prototype-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b93d2ccd523b855a794ccb68c396ae0b2334d21a1a6060c6dbd40143c611c208
MD5 faf1485b147dfe81c3a56857393bca34
BLAKE2b-256 71c29ae5d5c36dd299f4551e35fe4258635803d675f556e346012bdcc4ddf39d

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