Open stanislaw opened 2 years ago
1) Download strictdoc:
git clone https://github.com/strictdoc-project/strictdoc
2) Generate language file from strictdoc grammar in the main folder of strictdoc:
invoke dump-grammar strictdoc.tx
3) Download the textX language server (textX-LS)
git clone https://github.com/textX/textX-LS
4) Go into the main folder of textX-LS
cd text-LS
cd example
mkdir strictdoc
cd strictdoc
copy strictdoc.tx
replace all '\n' with /\n/ in strictdoc.tx why? - see https://github.com/textX/textX/issues/323
5) Register language:
mkdir tx_strictdoc //generate folder for language definition file (*.tx)
mv strictdoc.tx tx_strictdoc //move language definition file
6) edit init.py in the tx_strictdoc folder with the following content:
from os.path import dirname, join
from textx import language, metamodel_from_file, metamodel_from_str
from tx_strictdoc.grammar import STRICTDOC_GRAMMAR
from tx_strictdoc.type_system import (
STRICTDOC_BASIC_TYPE_SYSTEM,
)
@language("Strictdoc", "*.sdoc")
def strictdoc():
"A language for writing technical specifications."
return metamodel_from_file(join(dirname(__file__), "strictdoc.tx")) #use this line preferably
#return metamodel_from_str(STRICTDOC_GRAMMAR + STRICTDOC_BASIC_TYPE_SYSTEM) #use this line if you are going to use the py grammar definition files diretly (not recommended)
The advantage of using the strict.tx file instead of the py grammar definition files is that it is possible to generate the textmate files necessary for syntax highlightning.
7) cd ..
into the main folder, edit a setup.py
file with the following content:
import codecs
import os
from setuptools import find_packages, setup
PACKAGE_NAME = "tx-strictdoc"
VERSION = "0.1.0"
AUTHOR = "Michael Naderhirn"
AUTHOR_EMAIL = "m.naderhirn@gmail.com"
DESCRIPTION = "The strictdoc language for writing technical specifications"
KEYWORDS = "textX DSL python domain specific languages"
LICENSE = "MIT"
URL = "https://github.com/Strumenta/textx-tutorial"
setup(
name=PACKAGE_NAME,
version=VERSION,
description=DESCRIPTION,
url=URL,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
keywords=KEYWORDS,
license=LICENSE,
packages=find_packages(),
include_package_data=True,
package_data={"": ["*.tx"]},
install_requires=["textx_ls_core"],
entry_points={"textx_languages": ["strictdoc = tx_strictdoc:strictdoc"]},
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
)
Resulting project folder:
<project root>
setup.py
tx_strictdoc
__init__.py
strictdoc.tx
...other files...
pip install . //language is installed now
textx list-languages //check if language is installed
8) Generate graph tree for registered language from a example sdoc file.
textx generate example.sdoc --target=dot –overwrite
dot -Tpng -O turtle.dot
9) Get support for Visual Studio Code
Go to https://tomassetti.me/domain-specific-languages-in-python-with-textx/
See section Integrating with Visual Studio Code
10) Get support for Eclipse
go to https://github.com/eclipse/lsp4e/tree/master/documentation for testing purposes follow the tutorial https://github.com/eclipse/lsp4e/blob/master/documentation/using-language-server-via-configuration-no-code.md
important is step 7 which is used in step 3 of the above documentation the language server needs to run in stdio, no tcp required
pip install -r requirements.txt
cd textX-LS\server
python -m textx_ls_server
optional arguments: -h, --help show this help message and exit --tcp Use TCP server instead of stdio --host HOST Bind to this address --port PORT Bind to this port
This feature is suggested by @mnaderhirn who has created a work proof-of-concept based on https://github.com/textX/textX-LS which is
Language server for domain specific languages based on textX
(the attached comment will contain a short tutorial that was created by him and that is confirmed to work in Eclipse).An alternative option is to use the underlying building block of textX-LS: https://github.com/openlawlibrary/pygls which is a Python library for creating language servers.