Name | python-textmate JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | TextMate grammar parser for python |
upload_time | 2024-10-07 12:07:08 |
maintainer | None |
docs_url | None |
author | Marcel Alexandru Nitan |
requires_python | <4.0,>=3.8 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# TextMate grammar parser for python
## Install
`pip install python-textmate`
## Usage
The parser can parse one line, to parse multiple lines iterate over each line and call parse()
```python
>>> from textmate import TextMateGrammar, TextMateGrammarRepository
>>> import json
>>>
>>> def load_json(file_path):
... with open(file_path, "r") as f:
... return json.load(f)
...
>>> # Initialize the grammar repository
>>> repository = TextMateGrammarRepository([
... load_json("MagicPython.tmLanguage.json"),
... load_json("MagicRegExp.tmLanguage.json")
... ])
>>>
>>> # Get the Python grammar
>>> python_grammar = repository.get_grammar_by_language("python")
>>>
>>> if python_grammar:
... # Initiatee the grammar parser
... grammar = TextMateGrammar(python_grammar, repository)
... 3 Parse one line of code
... code = "print(True) # the parser only parses one line."
... result = grammar.parse(code)
... print(result)
...
[('punctuation.definition.comment.python', (12, 13)),
('comment.line.number-sign.python', (12, 46)),
('constant.language.python', (6, 10)),
('punctuation.parenthesis.begin.python', (5, 6)),
('punctuation.parenthesis.end.python', (10, 11)),
('constant.language.python', (6, 10)),
('punctuation.definition.arguments.end.python', (10, 11)),
('meta.function-call.python', (0, 11)),
('keyword.illegal.name.python', (6, 10)),
('support.function.builtin.python', (0, 5)),
('meta.function-call.generic.python', (0, 5)),
('meta.function-call.generic.python', (6, 10)),
('meta.function-call.arguments.python', (6, 10)),
('constant.language.python', (6, 10)),
('support.function.builtin.python', (0, 5)),
('punctuation.separator.period.python', (45, 46)),
('meta.member.access.python', (45, 46))]
```
Raw data
{
"_id": null,
"home_page": null,
"name": "python-textmate",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Marcel Alexandru Nitan",
"author_email": "nitan.marcel@protonmail.com",
"download_url": "https://files.pythonhosted.org/packages/36/89/ac5e7e75f99116c1a1b687d73eb60c6a2415ec1871c122efda3a8238d118/python_textmate-0.2.0.tar.gz",
"platform": null,
"description": "# TextMate grammar parser for python\n\n## Install\n\n`pip install python-textmate`\n\n## Usage\n\nThe parser can parse one line, to parse multiple lines iterate over each line and call parse()\n\n```python\n>>> from textmate import TextMateGrammar, TextMateGrammarRepository\n>>> import json\n>>> \n>>> def load_json(file_path):\n... with open(file_path, \"r\") as f:\n... return json.load(f)\n... \n>>> # Initialize the grammar repository\n>>> repository = TextMateGrammarRepository([\n... load_json(\"MagicPython.tmLanguage.json\"),\n... load_json(\"MagicRegExp.tmLanguage.json\")\n... ])\n>>> \n>>> # Get the Python grammar\n>>> python_grammar = repository.get_grammar_by_language(\"python\")\n>>> \n>>> if python_grammar:\n... # Initiatee the grammar parser\n... grammar = TextMateGrammar(python_grammar, repository)\n... 3 Parse one line of code\n... code = \"print(True) # the parser only parses one line.\"\n... result = grammar.parse(code)\n... print(result)\n... \n[('punctuation.definition.comment.python', (12, 13)),\n ('comment.line.number-sign.python', (12, 46)),\n ('constant.language.python', (6, 10)),\n ('punctuation.parenthesis.begin.python', (5, 6)),\n ('punctuation.parenthesis.end.python', (10, 11)),\n ('constant.language.python', (6, 10)),\n ('punctuation.definition.arguments.end.python', (10, 11)),\n ('meta.function-call.python', (0, 11)),\n ('keyword.illegal.name.python', (6, 10)),\n ('support.function.builtin.python', (0, 5)),\n ('meta.function-call.generic.python', (0, 5)),\n ('meta.function-call.generic.python', (6, 10)),\n ('meta.function-call.arguments.python', (6, 10)),\n ('constant.language.python', (6, 10)),\n ('support.function.builtin.python', (0, 5)),\n ('punctuation.separator.period.python', (45, 46)),\n ('meta.member.access.python', (45, 46))]\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "TextMate grammar parser for python",
"version": "0.2.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "aac5130c9a7bc50a94466608d839e7eccb551a3bcfbf2233edfc6b308814d27b",
"md5": "499c609a03c6e29d4f3cdbd0b9bdf634",
"sha256": "b98678769583339589e04d27b9b482ba9830a951a910e0909a015cb8a81e8a2a"
},
"downloads": -1,
"filename": "python_textmate-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "499c609a03c6e29d4f3cdbd0b9bdf634",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 7610,
"upload_time": "2024-10-07T12:07:06",
"upload_time_iso_8601": "2024-10-07T12:07:06.945552Z",
"url": "https://files.pythonhosted.org/packages/aa/c5/130c9a7bc50a94466608d839e7eccb551a3bcfbf2233edfc6b308814d27b/python_textmate-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3689ac5e7e75f99116c1a1b687d73eb60c6a2415ec1871c122efda3a8238d118",
"md5": "21c2c8c48bbcdfc4cb70ca83875dd2de",
"sha256": "620417891826cc79a3c16ff15ca04b033b63bc4470f66fd92e96041a2009a1a6"
},
"downloads": -1,
"filename": "python_textmate-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "21c2c8c48bbcdfc4cb70ca83875dd2de",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 6207,
"upload_time": "2024-10-07T12:07:08",
"upload_time_iso_8601": "2024-10-07T12:07:08.397724Z",
"url": "https://files.pythonhosted.org/packages/36/89/ac5e7e75f99116c1a1b687d73eb60c6a2415ec1871c122efda3a8238d118/python_textmate-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-07 12:07:08",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "python-textmate"
}