{"id":13468870,"url":"https://github.com/textX/textX","last_synced_at":"2025-03-26T05:31:24.552Z","repository":{"id":19589111,"uuid":"22839391","full_name":"textX/textX","owner":"textX","description":"Domain-Specific Languages and parsers in Python made easy http://textx.github.io/textX/","archived":false,"fork":false,"pushed_at":"2024-10-26T13:17:39.000Z","size":17858,"stargazers_count":776,"open_issues_count":56,"forks_count":76,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-10-29T22:56:47.320Z","etag":null,"topics":["domain-specific-language","parser","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/textX.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-08-11T13:10:27.000Z","updated_at":"2024-10-26T18:38:38.000Z","dependencies_parsed_at":"2023-01-13T20:28:14.525Z","dependency_job_id":"f25ae9cb-41ff-4700-8edb-5d93a358137d","html_url":"https://github.com/textX/textX","commit_stats":{"total_commits":1225,"total_committers":24,"mean_commits":"51.041666666666664","dds":"0.21061224489795916","last_synced_commit":"073b65bdac6a0ae978de78dc9e77a05ff4017938"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textX%2FtextX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textX%2FtextX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textX%2FtextX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textX%2FtextX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/textX","download_url":"https://codeload.github.com/textX/textX/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245597333,"owners_count":20641865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-specific-language","parser","python"],"created_at":"2024-07-31T15:01:20.879Z","updated_at":"2025-03-26T05:31:22.437Z","avatar_url":"https://github.com/textX.png","language":"Python","readme":"![](https://raw.githubusercontent.com/textX/textX/master/art/textX-logo.png)\n\n[![PyPI Version](https://img.shields.io/pypi/v/textX.svg)](https://pypi.python.org/pypi/textX)\n![](https://img.shields.io/pypi/l/textX.svg)\n[![Build status](https://github.com/textx/textx/actions/workflows/tests.yml/badge.svg)](https://github.com/textx/textx/actions)\n[![Code test coverage](https://coveralls.io/repos/github/textX/textX/badge.svg?branch=master)](https://coveralls.io/github/textX/textX?branch=master)\n[![Documentation Status](https://img.shields.io/badge/docs-latest-green.svg)](https://textx.github.io/textX/)\n\n\ntextX is a meta-language for building Domain-Specific Languages (DSLs) in\nPython. It is inspired by [Xtext].\n\nIn a nutshell, textX will help you build your textual language in an easy way.\nYou can invent your own language or build a support for already existing textual\nlanguage or file format.\n\nFrom a single language description (grammar), textX will build a parser and a\nmeta-model (a.k.a. abstract syntax) for the language. See the docs for the\ndetails.\n\ntextX follows the syntax and semantics of Xtext but [differs in some\nplaces](http://textx.github.io/textX/about/comparison.html) and is\nimplemented 100% in Python using [Arpeggio] PEG parser - no grammar ambiguities,\nunlimited lookahead, interpreter style of work.\n\n\n## Quick intro\n\nHere is a complete example that shows the definition of a simple DSL for\ndrawing. We also show how to define a custom class, interpret models and search\nfor instances of a particular type.\n\n```python\nfrom textx import metamodel_from_str, get_children_of_type\n\ngrammar = \"\"\"\nModel: commands*=DrawCommand;\nDrawCommand: MoveCommand | ShapeCommand;\nShapeCommand: LineTo | Circle;\nMoveCommand: MoveTo | MoveBy;\nMoveTo: 'move' 'to' position=Point;\nMoveBy: 'move' 'by' vector=Point;\nCircle: 'circle' radius=INT;\nLineTo: 'line' 'to' point=Point;\nPoint: x=INT ',' y=INT;\n\"\"\"\n\n# We will provide our class for Point.\n# Classes for other rules will be dynamically generated.\nclass Point:\n    def __init__(self, parent, x, y):\n        self.parent = parent\n        self.x = x\n        self.y = y\n\n    def __str__(self):\n        return \"{},{}\".format(self.x, self.y)\n\n    def __add__(self, other):\n        return Point(self.parent, self.x + other.x, self.y + other.y)\n\n# Create meta-model from the grammar. Provide `Point` class to be used for\n# the rule `Point` from the grammar.\nmm = metamodel_from_str(grammar, classes=[Point])\n\nmodel_str = \"\"\"\n    move to 5, 10\n    line to 10, 10\n    line to 20, 20\n    move by 5, -7\n    circle 10\n    line to 10, 10\n\"\"\"\n\n# Meta-model knows how to parse and instantiate models.\nmodel = mm.model_from_str(model_str)\n\n# At this point model is a plain Python object graph with instances of\n# dynamically created classes and attributes following the grammar.\n\ndef cname(o):\n    return o.__class__.__name__\n\n# Let's interpret the model\nposition = Point(None, 0, 0)\nfor command in model.commands:\n    if cname(command) == 'MoveTo':\n        print('Moving to position', command.position)\n        position = command.position\n    elif cname(command) == 'MoveBy':\n        position = position + command.vector\n        print('Moving by', command.vector, 'to a new position', position)\n    elif cname(command) == 'Circle':\n        print('Drawing circle at', position, 'with radius', command.radius)\n    else:\n        print('Drawing line from', position, 'to', command.point)\n        position = command.point\nprint('End position is', position)\n\n# Output:\n# Moving to position 5,10\n# Drawing line from 5,10 to 10,10\n# Drawing line from 10,10 to 20,20\n# Moving by 5,-7 to a new position 25,13\n# Drawing circle at 25,13 with radius 10\n# Drawing line from 25,13 to 10,10\n\n# Collect all points starting from the root of the model\npoints = get_children_of_type(\"Point\", model)\nfor point in points:\n    print('Point: {}'.format(point))\n\n# Output:\n# Point: 5,10\n# Point: 10,10\n# Point: 20,20\n# Point: 5,-7\n# Point: 10,10\n```\n\n\n## Video tutorials\n\n\n### Introduction to textX\n\n\n[![Introduction to\ntextX](https://img.youtube.com/vi/CN2IVtInapo/0.jpg)](https://www.youtube.com/watch?v=CN2IVtInapo)\n\n\n### Implementing Martin Fowler's State Machine DSL in textX\n\n[![Implementing State Machine\nDSL](https://img.youtube.com/vi/HI14jk0JIR0/0.jpg)](https://www.youtube.com/watch?v=HI14jk0JIR0)\n\n\n## Docs and tutorials\n\nThe full documentation with tutorials is available at\nhttp://textx.github.io/textX/stable/\n\nYou can also try textX in [our\nplayground](https://textx.github.io/textx-playground/). There is a dropdown with\nseveral examples to get you started.\n\n\n# Support in IDE/editors\n\nProjects that are currently in progress are:\n\n- [textX-LS](https://github.com/textX/textX-LS) - support for Language Server\n  Protocol and VS Code for any textX based language. This project is about to\n  supersede the following projects:\n  - [textX-languageserver](https://github.com/textX/textX-languageserver) -\n    Language Server Protocol support for textX languages\n  - [textX-extensions](https://github.com/textX/textX-extensions) - syntax\n    highlighting, code outline\n- [viewX](https://github.com/danielkupco/viewX-vscode) - creating visualizers\n  for textX languages\n  \nIf you are a vim editor user check\nout [support for vim](https://github.com/textX/textx.vim/).\n\nFor emacs there is [textx-mode](https://github.com/textX/textx-mode) which is\nalso available in [MELPA](https://melpa.org/#/textx-mode).\n\nYou can also check\nout [textX-ninja project](https://github.com/textX/textX-ninja). It is\ncurrently unmaintained.\n\n\n## Discussion and help\n\nFor general questions, suggestions, and feature requests please use [GitHub\nDiscussions](https://github.com/textX/textX/discussions).\n\n\nFor issues please use [GitHub issue\ntracker](https://github.com/textX/textX/issues).\n\n\n## Citing textX\n\nIf you are using textX in your research project we would be very grateful if you\ncite our paper:\n\nDejanović I., Vaderna R., Milosavljević G., Vuković Ž. (2017). [TextX: A Python\ntool for Domain-Specific Languages\nimplementation](https://www.doi.org/10.1016/j.knosys.2016.10.023).\nKnowledge-Based Systems, 115, 1-4.\n\n\n## License\n\nMIT\n\n## Python versions\n\nTested for 3.8+\n\n\n[Arpeggio]: https://github.com/textX/Arpeggio\n[Xtext]: http://www.eclipse.org/Xtext/\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtextX%2FtextX","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FtextX%2FtextX","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtextX%2FtextX/lists"}