Skip to main content

Meta-language in Arpeggio inspired by Xtext

Project description

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

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

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):

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.

  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, 'hello_meta.dot')

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.

  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, 'example.dot')

example.dot

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!

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

textX-0.2.1.tar.gz (15.7 kB view details)

Uploaded Source

File details

Details for the file textX-0.2.1.tar.gz.

File metadata

  • Download URL: textX-0.2.1.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for textX-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2cf1721f3290ac4d5198bcfa8b14af2ac6d8413e18981a18b5cacf96b0f85461
MD5 8dd189fb3ee433060fb690c01c674d95
BLAKE2b-256 b96a244e7ce3f381ff7ad90c62848bfa3adf9ae9ee374b9360becffea92407fa

See more details on using hashes here.

Supported by

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