Skip to main content

Paxter

Docs Documentation Status
Tests
Travis-CI Build Status Requirements Status Coverage Status Codacy Code Quality Status
Package
PyPI Package latest release PyPI Wheel Supported versions Supported implementations

Paxter is a document-first, text pre-processing mini-language toolchain, loosely inspired by @-expressions in Racket.

  • The Paxter library package defines the syntax for Paxter language and provides a toolchain for parsing input texts written in Paxter language into an intermediate parsed tree.
  • However, the semantics of Paxter language is left unspecified, meaning that users of the library have all the freedom to do whatever they like to render or transform the intermediate parsed tree into a final output they wish to achieve.
  • Alternatively, instead of implementing an interpreter for intermediate parsed tree by themselves, users may opt-in to utilize a preset parsed tree renderers, also provided by this library package.

Example

Suppose that we have a text document written in Paxter language as shown below.

@python##"
    import statistics
    from datetime import datetime

    _symbols_ = {
        '@': '@',
        '.': ' ',
        ',': ' ',
    }
    name = "Ashley"
    birth_year = 1987
    age = datetime.now().year - birth_year
"##\
My name is @name and I am @age years old.
My email is ashley@@example.com.
My shop opens Monday@,-@,Friday.

@python##"
    from itertools import count
    counter = count(start=1)
"##\
Counting is as easy as @|next(counter)|, @|next(counter)|, @|next(counter)|.
Arithmetic? Not a problem: 7 * 11 * 13 = @|7 * 11 * 13|.

@python##"
    def tag(text, name='span'):
        return f'<{name}>{flatten(text)}</{name}>'
"##\
This is a very @tag["b"]{important @tag["i"]{feature}}:
@@-expressions are allowed to be nested within the main argument
using fragment list syntax (section surrounded by a pair of curly braces).

To escape right curly braces literal characters with the fragment list main argument,
simply enclose the main argument with as many #...# as you like
(@tag##{such as {this}!}##).

@python##"
    def is_odd(value):
        return value % 2 == 1
"##\
Odd digits are@flatten{@for[i in @|range(10)|]{@if[@|is_odd(i)|]{ @i}}}.
Expected outcome for rolling a die is @|statistics.mean|[@|range(1, 7)|].

Using the parser in Paxter library package to process this document, we obtain the following result.

Click Here To Expand
FragmentList(
    start_pos=0,
    end_pos=1263,
    children=[
        Command(
            start_pos=1,
            end_pos=248,
            starter="python",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=Text(
                start_pos=10,
                end_pos=245,
                inner="\n    import statistics\n    from datetime import datetime\n\n    _symbols_ = {\n        '@': '@',\n        '.': '&hairsp;',\n        ',': '&thinsp;',\n    }\n    name = \"Ashley\"\n    birth_year = 1987\n    age = datetime.now().year - birth_year\n",
                enclosing=EnclosingPattern(left='##"', right='"##'),
            ),
        ),
        Text(
            start_pos=248,
            end_pos=261,
            inner="\\\nMy name is ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=262,
            end_pos=266,
            starter="name",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=None,
        ),
        Text(
            start_pos=266,
            end_pos=276,
            inner=" and I am ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=277,
            end_pos=280,
            starter="age",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=None,
        ),
        Text(
            start_pos=280,
            end_pos=310,
            inner=" years old.\nMy email is ashley",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        SymbolCommand(start_pos=311, end_pos=312, symbol="@"),
        Text(
            start_pos=312,
            end_pos=345,
            inner="example.com.\nMy shop opens Monday",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        SymbolCommand(start_pos=346, end_pos=347, symbol=","),
        Text(
            start_pos=347,
            end_pos=348,
            inner="-",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        SymbolCommand(start_pos=349, end_pos=350, symbol=","),
        Text(
            start_pos=350,
            end_pos=359,
            inner="Friday.\n\n",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=360,
            end_pos=434,
            starter="python",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=Text(
                start_pos=369,
                end_pos=431,
                inner="\n    from itertools import count\n    counter = count(start=1)\n",
                enclosing=EnclosingPattern(left='##"', right='"##'),
            ),
        ),
        Text(
            start_pos=434,
            end_pos=459,
            inner="\\\nCounting is as easy as ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=460,
            end_pos=475,
            starter="next(counter)",
            starter_enclosing=EnclosingPattern(left="|", right="|"),
            option=None,
            main_arg=None,
        ),
        Text(
            start_pos=475,
            end_pos=477,
            inner=", ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=478,
            end_pos=493,
            starter="next(counter)",
            starter_enclosing=EnclosingPattern(left="|", right="|"),
            option=None,
            main_arg=None,
        ),
        Text(
            start_pos=493,
            end_pos=495,
            inner=", ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=496,
            end_pos=511,
            starter="next(counter)",
            starter_enclosing=EnclosingPattern(left="|", right="|"),
            option=None,
            main_arg=None,
        ),
        Text(
            start_pos=511,
            end_pos=554,
            inner=".\nArithmetic? Not a problem: 7 * 11 * 13 = ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=555,
            end_pos=568,
            starter="7 * 11 * 13",
            starter_enclosing=EnclosingPattern(left="|", right="|"),
            option=None,
            main_arg=None,
        ),
        Text(
            start_pos=568,
            end_pos=571,
            inner=".\n\n",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=572,
            end_pos=668,
            starter="python",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=Text(
                start_pos=581,
                end_pos=665,
                inner="\n    def tag(text, name='span'):\n        return f'<{name}>{flatten(text)}</{name}>'\n",
                enclosing=EnclosingPattern(left='##"', right='"##'),
            ),
        ),
        Text(
            start_pos=668,
            end_pos=685,
            inner="\\\nThis is a very ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=686,
            end_pos=724,
            starter="tag",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=TokenList(
                start_pos=690,
                end_pos=693,
                children=[
                    Text(
                        start_pos=691,
                        end_pos=692,
                        inner="b",
                        enclosing=EnclosingPattern(left='"', right='"'),
                    )
                ],
            ),
            main_arg=FragmentList(
                start_pos=695,
                end_pos=723,
                children=[
                    Text(
                        start_pos=695,
                        end_pos=705,
                        inner="important ",
                        enclosing=EnclosingPattern(left="", right=""),
                    ),
                    Command(
                        start_pos=706,
                        end_pos=723,
                        starter="tag",
                        starter_enclosing=EnclosingPattern(left="", right=""),
                        option=TokenList(
                            start_pos=710,
                            end_pos=713,
                            children=[
                                Text(
                                    start_pos=711,
                                    end_pos=712,
                                    inner="i",
                                    enclosing=EnclosingPattern(left='"', right='"'),
                                )
                            ],
                        ),
                        main_arg=FragmentList(
                            start_pos=715,
                            end_pos=722,
                            children=[
                                Text(
                                    start_pos=715,
                                    end_pos=722,
                                    inner="feature",
                                    enclosing=EnclosingPattern(left="", right=""),
                                )
                            ],
                            enclosing=EnclosingPattern(left="{", right="}"),
                        ),
                    ),
                ],
                enclosing=EnclosingPattern(left="{", right="}"),
            ),
        ),
        Text(
            start_pos=724,
            end_pos=726,
            inner=":\n",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        SymbolCommand(start_pos=727, end_pos=728, symbol="@"),
        Text(
            start_pos=728,
            end_pos=1018,
            inner="-expressions are allowed to be nested within the main argument\nusing fragment list syntax (section surrounded by a pair of curly braces).\n\nTo escape right curly braces literal characters with the fragment list main argument,\nsimply enclose the main argument with as many #...# as you like\n(",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=1019,
            end_pos=1043,
            starter="tag",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=FragmentList(
                start_pos=1025,
                end_pos=1040,
                children=[
                    Text(
                        start_pos=1025,
                        end_pos=1040,
                        inner="such as {this}!",
                        enclosing=EnclosingPattern(left="", right=""),
                    )
                ],
                enclosing=EnclosingPattern(left="##{", right="}##"),
            ),
        ),
        Text(
            start_pos=1043,
            end_pos=1047,
            inner=").\n\n",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=1048,
            end_pos=1114,
            starter="python",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=Text(
                start_pos=1057,
                end_pos=1111,
                inner="\n    def is_odd(value):\n        return value % 2 == 1\n",
                enclosing=EnclosingPattern(left='##"', right='"##'),
            ),
        ),
        Text(
            start_pos=1114,
            end_pos=1130,
            inner="\\\nOdd digits are",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=1131,
            end_pos=1187,
            starter="flatten",
            starter_enclosing=EnclosingPattern(left="", right=""),
            option=None,
            main_arg=FragmentList(
                start_pos=1139,
                end_pos=1186,
                children=[
                    Command(
                        start_pos=1140,
                        end_pos=1186,
                        starter="for",
                        starter_enclosing=EnclosingPattern(left="", right=""),
                        option=TokenList(
                            start_pos=1144,
                            end_pos=1161,
                            children=[
                                Identifier(start_pos=1144, end_pos=1145, name="i"),
                                Identifier(start_pos=1146, end_pos=1148, name="in"),
                                Command(
                                    start_pos=1150,
                                    end_pos=1161,
                                    starter="range(10)",
                                    starter_enclosing=EnclosingPattern(
                                        left="|", right="|"
                                    ),
                                    option=None,
                                    main_arg=None,
                                ),
                            ],
                        ),
                        main_arg=FragmentList(
                            start_pos=1163,
                            end_pos=1185,
                            children=[
                                Command(
                                    start_pos=1164,
                                    end_pos=1185,
                                    starter="if",
                                    starter_enclosing=EnclosingPattern(left="", right=""),
                                    option=TokenList(
                                        start_pos=1167,
                                        end_pos=1179,
                                        children=[
                                            Command(
                                                start_pos=1168,
                                                end_pos=1179,
                                                starter="is_odd(i)",
                                                starter_enclosing=EnclosingPattern(
                                                    left="|", right="|"
                                                ),
                                                option=None,
                                                main_arg=None,
                                            )
                                        ],
                                    ),
                                    main_arg=FragmentList(
                                        start_pos=1181,
                                        end_pos=1184,
                                        children=[
                                            Text(
                                                start_pos=1181,
                                                end_pos=1182,
                                                inner=" ",
                                                enclosing=EnclosingPattern(
                                                    left="", right=""
                                                ),
                                            ),
                                            Command(
                                                start_pos=1183,
                                                end_pos=1184,
                                                starter="i",
                                                starter_enclosing=EnclosingPattern(
                                                    left="", right=""
                                                ),
                                                option=None,
                                                main_arg=None,
                                            ),
                                        ],
                                        enclosing=EnclosingPattern(left="{", right="}"),
                                    ),
                                )
                            ],
                            enclosing=EnclosingPattern(left="{", right="}"),
                        ),
                    )
                ],
                enclosing=EnclosingPattern(left="{", right="}"),
            ),
        ),
        Text(
            start_pos=1187,
            end_pos=1227,
            inner=".\nExpected outcome for rolling a die is ",
            enclosing=EnclosingPattern(left="", right=""),
        ),
        Command(
            start_pos=1228,
            end_pos=1261,
            starter="statistics.mean",
            starter_enclosing=EnclosingPattern(left="|", right="|"),
            option=TokenList(
                start_pos=1246,
                end_pos=1260,
                children=[
                    Command(
                        start_pos=1247,
                        end_pos=1260,
                        starter="range(1, 7)",
                        starter_enclosing=EnclosingPattern(left="|", right="|"),
                        option=None,
                        main_arg=None,
                    )
                ],
            ),
            main_arg=None,
        ),
        Text(
            start_pos=1261,
            end_pos=1263,
            inner=".\n",
            enclosing=EnclosingPattern(left="", right=""),
        ),
    ],
    enclosing=GlobalEnclosingPattern(),
)

If we are using the Python authoring mode (a renderer extension provided by Paxter library package) to process the intermediate parsed tree result from above, then the following output result would be returned.

My name is Ashley and I am 33 years old.
My email is ashley@example.com.
My shop opens Monday&thinsp;-&thinsp;Friday.

Counting is as easy as 1, 2, 3.
Arithmetic? Not a problem: 7 * 11 * 13 = 1001.

This is a very <b>important <i>feature</i></b>:
@-expressions are allowed to be nested within the main argument
using fragment list syntax (section surrounded by a pair of curly braces).

To escape right curly braces literal characters with the fragment list main argument,
simply enclose the main argument with as many #...# as you like
(<span>such as {this}!</span>).

Odd digits are 1 3 5 7 9.
Expected outcome for rolling a die is 3.5.

Documentation

Learn more about Paxter via the following links from ReadTheDocs documentation website:

Future Plans

  • Experiment with different kinds of transformers and use it in real life
  • Re-implementing lexers and parsers in Rust for better performance and portability to other environments (such as WASM).
  • And more!

Development

Makefile contains a lot of utility scripts.
See help command by simply running make or make help.

Metadata

Release files for paxter 0.6.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for paxter 0.6.11
File Size Uploaded
paxter-0.6.11.tar.gz 763.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for paxter 0.6.11
File Interpreter ABI Platform
paxter-0.6.11-py3-none-any.whl Python 3 none any Details

Total release size: 794.3 kB

Release files / paxter-0.6.11.tar.gz

Download URL paxter-0.6.11.tar.gz
Size 763.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d24aa1092af43a26c8d65c14b0272a5276fe30d73c55fe22a8a3dc627ccb5e0b
BLAKE2b-256 checksum
How to use checksums
33b5a13e552d6622225911be804c95b82aec0065c39bb46da3149d5e1064a27a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / paxter-0.6.11-py3-none-any.whl

Download URL paxter-0.6.11-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
173f17108fe645bea90fbbb8c01b4a100b109640729ca29c20282d4b993eb243
BLAKE2b-256 checksum
How to use checksums
68cb92a8526edc8b38846ba6ec65d5d9d9910f32a7e59151950fb59716e0093a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.6.11 This release

2 release files

0.6.10

2 release files

0.6.9

2 release files

0.6.8

2 release files

0.6.7

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page