Skip to main content

Document-first text pre-processing mini-language loosely inspired by at-expressions in Racket

Project description

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

Document-first text pre-processing mini-language, loosely inspired by at-expressions in Racket.

Warning: This is still a work in progress and a lot stuff are subjected to change.

Installation

This package can be installed from PyPI via pip command (or any other methods of your choice):

$ pip install paxter

Programmatic Usage

The package is intended to be used as a library. Standard transformers are available to be utilized right away without having to write custom parsed tree transformers.

Here is one way to use this library.

from paxter.core import Parser, SimplePythonTransformer

parser = Parser()
transformer = SimplePythonTransformer()

env = {
    'name': "John Smith",
    'age_last_year': 47,
    'strip': lambda token: token.strip(),
    'tag': lambda token, label: f"<{label}>{token}</{label}>",
}

tree = parser.parse('''\
@!##{
def add_one(num):
    return num + 1
}##

Hello, my @strip{  full name   } is @name.
@tag[label="b"]{@name is @{age_last_year + 1} years old.}
@!{age_this_year = age_last_year + 1}

Do you know that 1 + 1 = @{1 + 1}?
''')

updated_env, output_text = transformer.transform(env, tree)
print(f"Age this year: {updated_env['age_this_year']}")
print(output_text)

The above script will print the following text:

Age this year: 48


Hello, my full name is John Smith.
<b>John Smith is 48 years old.</b>


Do you know that 1 + 1 = 2?

Library users could also write their own custom transformers by extending the paxter.core.BaseTransformer class and use it in any way they want. Stay tuned for the tutorial.

CLI Usage

While this feature is not ready, users can try make a call to the following command:

$ python -m paxter  # provide --help for help messages

Documentation

Future Plans

  • Experiment with different kinds of transformers and use it in real life
  • Richer experience with environments and stores (adding standard string functions, etc.)
  • 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.

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

paxter-0.1.3.tar.gz (23.6 kB view hashes)

Uploaded Source

Built Distribution

paxter-0.1.3-py3-none-any.whl (19.4 kB view hashes)

Uploaded Python 3

Supported by

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