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
-
\G
anchoring - 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
Close
Hashes for textmate_grammar_python-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea5827ff186d6c4958bded467eafdd7b0e58e920617badb8005b4ff970169eec |
|
MD5 | 72c8b73dcb67bef70e2ecb805e707448 |
|
BLAKE2b-256 | edc103c36bed9ce03d2fe757404e3b8c6577f31d212656802ba712c9a564b61d |
Close
Hashes for textmate_grammar_python-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9853aae952b91d765486757a71583ea5564296605ac49fb4ae514cfee1a7f0a1 |
|
MD5 | b6deaa7532385e668af566d8dcde1ded |
|
BLAKE2b-256 | 454d24ff9434fe8af499d898aecfab9f00285c433cccd4c119bf32bff49a6b5c |