Skip to content

Open source · MIT · Python 3.8+

Grammar in.
Python objects out.

textX is a meta-language for building Domain-Specific Languages in Python. Write one grammar and textX gives you a parser and a meta-model. Your models come back as plain Python objects, with references already resolved.

pip install textX
// A tiny language for describing data entities
Model:
    types*=SimpleType
    entities+=Entity
;

SimpleType:
    'type' name=ID
;

Entity:
    'entity' name=ID '{'
        properties*=Property
    '}'
;

Property:
    name=ID ':' type=[Type]  // a reference
;

Type:
    SimpleType | Entity
;

Comment:
    /\/\/.*$/
;
Open this example in the Playground ↗

How textX works

  1. grammar.tx
    You write the rules
  2. meta-model
    Python classes
  3. parser
    Built for you
  4. model
    Object graph
  5. your code
    Generate, interpret, validate

Why textX

Less parser plumbing, more language design

Inspired by Xtext, built for Python. textX stays a library, not a workbench, so it drops into any project that can pip install.

One grammar, two results

A textX grammar describes the concrete syntax and the meta-model at the same time. You get a parser and Python classes from a single file.

Models are Python objects

Parsing gives you a graph of plain Python objects, with no AST to walk. Register your own classes if you want behaviour on them.

References resolved for you

Cross-references are linked automatically. Scope providers and RREL cover the harder cases, including references across files and languages.

No code generation step

Grammars are interpreted by Arpeggio, a PEG parser. Change the grammar and run again, with no generated sources to keep in sync.

Generators & the textx CLI

Turn models into code, configs or docs with Jinja-based generators. Register languages and generators, then use them from one command.

Visualize & edit

Render grammars and models with GraphViz or PlantUML. textX-LS adds validation, completion and highlighting in VS Code.

Where it fits

Between a parser generator and a language workbench

Parser generators

ANTLR · yacc · bison

You get a parse tree, then write the AST, the linking and the semantics yourself.

textX

pip install textX

A grammar becomes a meta-model, a parser and a linked object graph. It is a Python library, so it works alongside your existing tools.

Language workbenches

Xtext · Spoofax · MPS

Powerful, but they tie you to an IDE platform and a separate toolchain.

Read the full comparison →

Tooling

Your language, in your editor

textX-LS adds Language Server Protocol support to any textX language. That gives you validation, completion and live reload in VS Code. Generators produce syntax highlighting and full extensions straight from your grammar.

  • ✓ VS Code via textX-LS
  • ✓ Vim and Emacs modes for grammar files
  • ✓ In-browser Playground, no install needed
Explore the ecosystem →
VS Code showing a textX-based workflow language with an 'Unknown object' error reported by textX-LS

Build your first language in ten minutes

The Hello World tutorial takes you from an empty file to a working parser. Then try robots, entities and state machines.