All Projects → textX → Textx

textX / Textx

Licence: mit
Domain-Specific Languages and parsers in Python made easy http://textx.github.io/textX/

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Textx

Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (-14.31%)
Mutual labels:  parser
Minigo
minigo🐥is a small Go compiler made from scratch. It can compile itself.
Stars: ✭ 456 (-8.06%)
Mutual labels:  parser
Corexlsx
Excel spreadsheet (XLSX) format parser written in pure Swift
Stars: ✭ 481 (-3.02%)
Mutual labels:  parser
Anystyle
Fast and smart citation reference parsing
Stars: ✭ 438 (-11.69%)
Mutual labels:  parser
Tinyrb
A tiny subset of Ruby with a Lua'esc VM
Stars: ✭ 452 (-8.87%)
Mutual labels:  parser
Stream Json
The micro-library of Node.js stream components for creating custom JSON processing pipelines with a minimal memory footprint. It can parse JSON files far exceeding available memory streaming individual primitives using a SAX-inspired API.
Stars: ✭ 462 (-6.85%)
Mutual labels:  parser
Binary Parser
Blazing-fast declarative parser builder for binary data
Stars: ✭ 422 (-14.92%)
Mutual labels:  parser
Tenko
An 100% spec compliant ES2021 JavaScript parser written in JS
Stars: ✭ 490 (-1.21%)
Mutual labels:  parser
Form
🚂 Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
Stars: ✭ 454 (-8.47%)
Mutual labels:  parser
Html5 Dom Document Php
A better HTML5 parser for PHP.
Stars: ✭ 477 (-3.83%)
Mutual labels:  parser
Mwparserfromhell
A Python parser for MediaWiki wikicode
Stars: ✭ 440 (-11.29%)
Mutual labels:  parser
Exifr
📷 The fastest and most versatile JS EXIF reading library.
Stars: ✭ 448 (-9.68%)
Mutual labels:  parser
Rsql Parser
Parser for RSQL / FIQL – query language for RESTful APIs
Stars: ✭ 463 (-6.65%)
Mutual labels:  parser
Picofeed
PHP library to parse and write RSS/Atom feeds
Stars: ✭ 439 (-11.49%)
Mutual labels:  parser
Sweet Core
Sweeten your JavaScript.
Stars: ✭ 4,501 (+807.46%)
Mutual labels:  parser
Seafox
A blazing fast 100% spec compliant, self-hosted javascript parser written in Typescript
Stars: ✭ 425 (-14.31%)
Mutual labels:  parser
Compiler
The Hoa\Compiler library.
Stars: ✭ 458 (-7.66%)
Mutual labels:  parser
Globalize
A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
Stars: ✭ 4,612 (+829.84%)
Mutual labels:  parser
Kong
Kong is a command-line parser for Go
Stars: ✭ 481 (-3.02%)
Mutual labels:  parser
Deta parser
快速中文分词分析word segmentation
Stars: ✭ 476 (-4.03%)
Mutual labels:  parser

PyPI Version Build status Code test coverage 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

Here is a complete example that shows the definition of a simple DSL for drawing. We also show how to define a custom class, interpret models and search for instances of a particular type.

from textx import metamodel_from_str, get_children_of_type

grammar = """
Model: commands*=DrawCommand;
DrawCommand: MoveCommand | ShapeCommand;
ShapeCommand: LineTo | Circle;
MoveCommand: MoveTo | MoveBy;
MoveTo: 'move' 'to' position=Point;
MoveBy: 'move' 'by' vector=Point;
Circle: 'circle' radius=INT;
LineTo: 'line' 'to' point=Point;
Point: x=INT ',' y=INT;
"""

# We will provide our class for Point.
# Classes for other rules will be dynamically generated.
class Point(object):
    def __init__(self, parent, x, y):
        self.parent = parent
        self.x = x
        self.y = y

    def __str__(self):
        return "{},{}".format(self.x, self.y)

    def __add__(self, other):
        return Point(self.parent, self.x + other.x, self.y + other.y)

# Create meta-model from the grammar. Provide `Point` class to be used for
# the rule `Point` from the grammar.
mm = metamodel_from_str(grammar, classes=[Point])

model_str = """
    move to 5, 10
    line to 10, 10
    line to 20, 20
    move by 5, -7
    circle 10
    line to 10, 10
"""

# Meta-model knows how to parse and instantiate models.
model = mm.model_from_str(model_str)

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

def cname(o):
    return o.__class__.__name__

# Let's interpret the model
position = Point(None, 0, 0)
for command in model.commands:
    if cname(command) == 'MoveTo':
        print('Moving to position', command.position)
        position = command.position
    elif cname(command) == 'MoveBy':
        position = position + command.vector
        print('Moving by', command.vector, 'to a new position', position)
    elif cname(command) == 'Circle':
        print('Drawing circle at', position, 'with radius', command.radius)
    else:
        print('Drawing line from', position, 'to', command.point)
        position = command.point
print('End position is', position)

# Output:
# Moving to position 5,10
# Drawing line from 5,10 to 10,10
# Drawing line from 10,10 to 20,20
# Moving by 5,-7 to a new position 25,13
# Drawing circle at 25,13 with radius 10
# Drawing line from 25,13 to 10,10

# 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: 5,10
# Point: 10,10
# Point: 20,20
# Point: 5,-7
# Point: 10,10

Video tutorials

Introduction to textX

Introduction to textX

Implementing Martin Fowler's State Machine DSL in textX

Implementing State Machine DSL

Docs and tutorials

The full documentation with tutorials is available at http://textx.github.io/textX/stable/

Support in IDE/editors

Projects that are currently in progress are:

  • textX-LS - support for Language Server Protocol and VS Code for any textX based language. This project is about to supersede the following projects:
  • viewX - creating visualizers for textX languages

If you are a vim editor user check out support for vim.

For emacs there is textx-mode which is also available in MELPA.

You can also check out textX-ninja project. It is currently unmaintained.

Discussion and help

For general questions and help please use StackOverflow. Just make sure to tag your question with the textx tag.

For issues, suggestions and feature request please use GitHub issue tracker.

Citing textX

If you are using textX in your research project we would be very grateful if you cite our paper:

Dejanović I., Vaderna R., Milosavljević G., Vuković Ž. (2017). TextX: A Python tool for Domain-Specific Languages implementation. Knowledge-Based Systems, 115, 1-4.

License

MIT

Python versions

Tested for 2.7, 3.4+

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].