skip to navigation
skip to content

textX 0.1.2

Meta-language in Arpeggio inspired by Xtext

Latest Version: 0.4.2

Meta-language in Arpeggio inspired by Xtext

textX follows closely 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!


pip install textX

Quick start

There is no docs at the moment but here is a quick introduction what can be done. For more see examples.

  1. Write a language description in textX (file hello.tx):
  'hello' to_greet+={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.

  1. Create meta-model from textX language description:
from textx.metamodel import metamodel_from_file
hello_meta = metamodel_from_file('hello.tx')
  1. Optionally export meta-model to dot (visualize your language abstract syntax):
from textx.export import metamodel_export
metamodel_export(hello_meta, '')

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.

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

  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.

  1. Optionally export model to dot to visualize it:
from textx.export import model_export
model_export(example_hello_model, '')

This is an object graph automatically constructed from ‘example.hello’ file.

  1. Use your model: interpret it, generate code … It is a plain Python graph of objects with plain attributes!
File Type Py Version Uploaded on Size
textX-0.1.2.tar.gz (md5) Source 2014-08-17 13KB
  • Downloads (All Versions):
  • 13 downloads in the last day
  • 88 downloads in the last week
  • 626 downloads in the last month