An interpreter for grammar files as defined by TextMate and used in VSCode, implemented in Python. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON, PLIST, or YAML format.
Project description
textmate-grammar-python
An interpreter for grammar files as defined by TextMate and used in VSCode, implemented in Python. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON, PLIST, or YAML format.
>>> from textmate_grammar.language import LanguageParser
>>> from textmate_grammar.grammars import matlab
>>> parser = LanguageParser(matlab.GRAMMAR)
>>> element = parser.parse_string("value = num2str(10);")
>>> element.print()
{'token': 'source.matlab',
'children': [{'token': 'meta.assignment.variable.single.matlab',
'children': [{'token': 'variable.other.readwrite.matlab', 'content': 'value'}]},
{'token': 'keyword.operator.assignment.matlab', 'content': '='},
{'token': 'meta.function-call.parens.matlab',
'begin': [{'token': 'entity.name.function.matlab', 'content': 'num2str'},
{'token': 'punctuation.section.parens.begin.matlab', 'content': '('}],
'end': [{'token': 'punctuation.section.parens.end.matlab', 'content': ')'}],
'children': [{'token': 'constant.numeric.decimal.matlab', 'content': '10'}]},
{'token': 'punctuation.terminator.semicolon.matlab', 'content': ';'}]}
>>> element.print(flatten=True)
[[(0, 0), 'value', ['source.matlab', 'meta.assignment.variable.single.matlab', 'variable.other.readwrite.matlab']],
[(0, 5), ' ', ['source.matlab']],
[(0, 6), '=', ['source.matlab', 'keyword.operator.assignment.matlab']],
[(0, 7), ' ', ['source.matlab']],
[(0, 8), 'num2str', ['source.matlab', 'meta.function-call.parens.matlab', 'entity.name.function.matlab']],
[(0, 15), '(', ['source.matlab', 'meta.function-call.parens.matlab', 'punctuation.section.parens.begin.matlab']],
[(0, 16), '10', ['source.matlab', 'meta.function-call.parens.matlab', 'constant.numeric.decimal.matlab']],
[(0, 18), ')', ['source.matlab', 'meta.function-call.parens.matlab', 'punctuation.section.parens.end.matlab']],
[(0, 19), ';', ['source.matlab', 'punctuation.terminator.semicolon.matlab']]]
Sources
TODO
- Use yaml in stead of json
- Grammar initialization with repository at any level
- Proper line-by-line parsing
-
\Ganchoring - Option to disable a grammar
- Option to applyEndPatternLast
- Implement injections
- Implement Begin/While pattern
Supported Languages
TextMate 2 features that are not used
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file textmate_grammar_python-0.1.0.tar.gz.
File metadata
- Download URL: textmate_grammar_python-0.1.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea5827ff186d6c4958bded467eafdd7b0e58e920617badb8005b4ff970169eec
|
|
| MD5 |
72c8b73dcb67bef70e2ecb805e707448
|
|
| BLAKE2b-256 |
edc103c36bed9ce03d2fe757404e3b8c6577f31d212656802ba712c9a564b61d
|
File details
Details for the file textmate_grammar_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: textmate_grammar_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9853aae952b91d765486757a71583ea5564296605ac49fb4ae514cfee1a7f0a1
|
|
| MD5 |
b6deaa7532385e668af566d8dcde1ded
|
|
| BLAKE2b-256 |
454d24ff9434fe8af499d898aecfab9f00285c433cccd4c119bf32bff49a6b5c
|