Meta-language for DSL implementation inspired by Xtext
Project description
textX
textX is a meta-language for building Domain-Specific Languages (DSLs) inspired by Xtext. From a single language description (grammar) textX will build a parser and a meta-model (a.k.a. abstract syntax) for the language.
textX follows the syntax and semantics of Xtext but differs in some places and is implemented 100% in Python using Arpeggio parser. It is fully dynamic - no code generation at all!
Installation
pip install textX
Quick start
Write a language description in textX (file hello.tx):
HelloWorldModel: 'hello' to_greet+=Who[','] ; Who: name = /[^,]*/ ;
Description consists of a set of parsing rules which at the same time describe Python classes that will be used to instantiate object of your model.
Create meta-model from textX language description:
from textx.metamodel import metamodel_from_file
hello_meta = metamodel_from_file('hello.tx')
Optionally export meta-model to dot (visualize your language abstract syntax):
from textx.export import metamodel_export
metamodel_export(hello_meta, 'hello_meta.dot')
You can see that for each rule from language description an appropriate Python class has been created. A BASETYPE hierarchy is builtin. Each meta-model has it.
Create some content (i.e. model) in your new language (example.hello):
hello World, Solar System, Universe
Your language syntax is also described by language rules from step 1.
Use meta-model to create models from textual description:
example_hello_model = hello_meta.model_from_file('example.hello')
Textual model ‘example.hello’ will be parsed and transformed to a plain Python object graph. Object classes are those defined by the meta-model.
Optionally export model to dot to visualize it:
from textx.export import model_export
model_export(example_hello_model, 'example.dot')
This is an object graph automatically constructed from ‘example.hello’ file.
Use your model: interpret it, generate code … It is a plain Python graph of objects with plain attributes!
Editor support
If you are a vim editor user check out support for vim.
Learn more
textX documentation is available here.
Also, check out examples.
Open-source projects using textX
Discuss, ask questions
Please use discussion forum for general discussions, suggestions etc.
If you have some specific question on textX usage please use stackoverflow.
Just make sure to tag your question with textx
.
Contribute
textX is open for contributions. You can contribute code, documentation, tests, bug reports. If you plan to make a contribution it would be great if you first announce that on the discussion forum.
For bug reports please use github issue tracker.
For code/doc/test contributions do the following:
Fork the project on github.
Clone your fork.
Make a branch for the new feature and switch to it.
Make one or more commits.
Push your branch to github.
Make a pull request. I will look at the changes and if everything is ok I will pull it in.
Note: For code contributions please try to adhere to the PEP-8 guidelines. Although I am not strict in that regard it is useful to have a common ground for coding style. To make things easier use tools for code checking (PyLint, PyFlakes, pep8 etc.).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file textX-0.4.1.tar.gz
.
File metadata
- Download URL: textX-0.4.1.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f23bb9b20b2b9097d574d696d2d3fee1044c00700159625c4386028b16e3f49 |
|
MD5 | 9980dc5788e2aed44d31f181d4d3e712 |
|
BLAKE2b-256 | e61a78bfd74f3cf7e6c373d25d5c9c69bb7f64cb28eabc516045cbf29097d117 |