Skip to main content
https://raw.githubusercontent.com/igordejanovic/textX/master/art/textX-logo.png

PyPI Version license build-status Documentation Status

textX is a meta-language for building Domain-Specific Languages (DSLs) in Python. It is inspired by Xtext.

In a nutshell, textX will help you build your textual language in an easy way. You can invent your own language or build a support for already existing textual language or file format.

From a single language description (grammar), textX will build a parser and a meta-model (a.k.a. abstract syntax) for the language. See the docs for the details.

textX follows the syntax and semantics of Xtext but differs in some places and is implemented 100% in Python using Arpeggio PEG parser - no grammar ambiguities, unlimited lookahead, interpreter style of work.

Quick intro

from textx import metamodel_from_str, get_children_of_type

grammar = """
Model: shapes*=Shape;
Shape: Circle | Line;
Circle: 'circle' center=Point '/' radius=INT;
Line: 'line' start=Point '/' end=Point;
Point: x=INT ',' y=INT;
"""

mm = metamodel_from_str(grammar)

# Meta-model knows how to parse and instantiate models.
model = mm.model_from_str("""
    line 10, 10 / 20, 20
    line 14, 78 / 89, 33
    circle 14, 20/10
    line 18, 89 / 78, 65
""")

# At this point model is plain Python object graph with instances of
# dynamically created classes and attributes following the grammar.

def _(p):
    "returns coordinate of the given Point as string"
    return "{},{}".format(p.x, p.y)

for shape in model.shapes:
    if shape.__class__.__name__ == 'Circle':
        print('Circle: center={}, radius={}'
              .format(_(shape.center), shape.radius))
    else:
        print('Line: from={} to={}'.format(_(shape.start), _(shape.end)))

# Output:
# Line: from=10,10 to=20,20
# Line: from=14,78 to=89,33
# Circle: center=14,20, radius=10
# Line: from=18,89 to=78,65

# Collect all points starting from the root of the model
points = get_children_of_type("Point", model)
for point in points:
    print('Point: {}'.format(_(point)))

# Output:
# Point: 10,10
# Point: 20,20
# Point: 14,78
# Point: 89,33
# Point: 14,20
# Point: 18,89
# Point: 78,65

Video tutorials

Introduction to textX

https://img.youtube.com/vi/CN2IVtInapo/0.jpg

Implementing Martin Fowler’s State Machine DSL in textX

https://img.youtube.com/vi/HI14jk0JIR0/0.jpg

Docs and tutorials

The full documentation with tutorials is available at http://igordejanovic.net/textX/

Support in IDE/editors

Discussion and help

For bug report, general discussion and help please use GitHub issue tracker.

License

MIT

Python versions

Tested for 2.7, 3.3+

Metadata

Release files for textX 1.8.0

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

Source distribution (sdist)

Source distribution for textX 1.8.0
File Size Uploaded Provenance Actions
textX-1.8.0.tar.gz 44.3 kB Without provenance Details for textX-1.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for textX 1.8.0
File Interpreter ABI Platform Actions
textX-1.8.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for textX-1.8.0-py2.py3-none-any.whl

Total release size: 95.5 kB

Release files / textX-1.8.0.tar.gz

Download URL textX-1.8.0.tar.gz
Size 44.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a698e84f0a168b254c872aad573e4610af6143ee3a9e5d281efe6b4fce010cee
BLAKE2b-256 checksum
How to use checksums
8bd1209eb0fe146968655c1900af0b7d609b147b7818599ca9ac4261dc0a74f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release files / textX-1.8.0-py2.py3-none-any.whl

Download URL textX-1.8.0-py2.py3-none-any.whl
Size 51.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
77b8efb0be461ed2540af31903a52df0803d75a9497340235d39d159524b987c
BLAKE2b-256 checksum
How to use checksums
ffdf33442dfb9ddfc2a9a84d60915ccf0602a5b04fdc46f523a7e939e588cd59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Security for textX 1.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.8.0 This release

2 release files No provenance

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