textmate-grammar-python 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/PKG-INFO +19 -19
  2. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/README.md +13 -15
  3. textmate_grammar_python-0.4.0/pyproject.toml +95 -0
  4. textmate_grammar_python-0.4.0/src/textmate_grammar/__init__.py +1 -0
  5. textmate_grammar_python-0.4.0/src/textmate_grammar/elements.py +552 -0
  6. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/grammars/markdown/__init__.py +2 -0
  7. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/grammars/matlab/__init__.py +2 -0
  8. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/language.py +70 -25
  9. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/parser.py +59 -10
  10. textmate_grammar_python-0.4.0/src/textmate_grammar/utils/cache.py +163 -0
  11. textmate_grammar_python-0.4.0/src/textmate_grammar/utils/exceptions.py +72 -0
  12. {textmate_grammar_python-0.2.0/src/textmate_grammar → textmate_grammar_python-0.4.0/src/textmate_grammar/utils}/handler.py +83 -16
  13. {textmate_grammar_python-0.2.0/src/textmate_grammar → textmate_grammar_python-0.4.0/src/textmate_grammar/utils}/logger.py +36 -14
  14. textmate_grammar_python-0.2.0/pyproject.toml +0 -58
  15. textmate_grammar_python-0.2.0/src/textmate_grammar/elements.py +0 -366
  16. textmate_grammar_python-0.2.0/src/textmate_grammar/exceptions.py +0 -30
  17. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/LICENSE +0 -0
  18. {textmate_grammar_python-0.2.0/src/textmate_grammar → textmate_grammar_python-0.4.0/src/textmate_grammar/grammars}/__init__.py +0 -0
  19. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/grammars/markdown/LICENSE.txt +0 -0
  20. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/grammars/markdown/grammar.yaml +0 -0
  21. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/grammars/matlab/grammar.yaml +0 -0
  22. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/grammars/matlab/license.txt +0 -0
  23. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.4.0}/src/textmate_grammar/py.typed +0 -0
  24. {textmate_grammar_python-0.2.0/src/textmate_grammar/grammars → textmate_grammar_python-0.4.0/src/textmate_grammar/utils}/__init__.py +0 -0
@@ -1,19 +1,22 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: textmate-grammar-python
3
- Version: 0.2.0
4
- Summary: 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.
3
+ Version: 0.4.0
4
+ Summary: A lexer and tokenizer for grammar files as defined by TextMate and used in VSCode, implemented in Python.
5
5
  Home-page: https://github.com/watermarkhu/textmate-grammar-python
6
6
  License: MIT
7
7
  Keywords: textmate,tokenization
8
8
  Author: Mark Shui Hu
9
9
  Author-email: watermarkhu@gmail.com
10
- Requires-Python: >=3.11,<4.0
10
+ Requires-Python: >=3.9,<4.0
11
11
  Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
13
15
  Classifier: Programming Language :: Python :: 3.11
14
16
  Classifier: Programming Language :: Python :: 3.12
15
17
  Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
16
18
  Requires-Dist: onigurumacffi (>=1.3.0,<2.0.0)
19
+ Project-URL: Documentation, https://textmate-grammar-python.readthedocs.io
17
20
  Project-URL: Repository, https://github.com/watermarkhu/textmate-grammar-python
18
21
  Description-Content-Type: text/markdown
19
22
 
@@ -21,17 +24,22 @@ Description-Content-Type: text/markdown
21
24
  [![PyPI - License](https://img.shields.io/pypi/l/textmate-grammar-python.svg)](https://github.com/watermarkhu/textmate-grammar-python/tree/main?tab=MIT-1-ov-file)
22
25
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
23
26
  [![Checked with mypy](https://img.shields.io/badge/mypy-checked-blue)](http://mypy-lang.org/)
27
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
24
28
  [![Python versions](https://img.shields.io/pypi/pyversions/textmate-grammar-python.svg)](https://pypi.python.org/pypi/textmate-grammar-python)
25
29
  [![CI/CD](https://github.com/watermarkhu/textmate-grammar-python/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/watermarkhu/textmate-grammar-python/blob/main/.github/workflows/ci.yml)
26
-
30
+ [![readthedocs](https://readthedocs.org/projects/textmate-grammar-python/badge/?version=latest)](https://textmate-grammar-python.readthedocs.io)
27
31
 
28
32
  # textmate-grammar-python
29
33
 
30
- 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.
34
+ A lexer and tokenizer for grammar files as defined by TextMate and used in VSCode, implemented in Python.
31
35
 
36
+ Textmate grammars are made for [vscode-texmate](https://github.com/microsoft/vscode-textmate), allowing for syntax highlighting in VSCode after tokenization. This presents textmate-grammar-python with a large list of potentially supported languages.
32
37
 
33
38
  ## Usage
34
- Install the module using `pip install textmate-grammar-python`.
39
+ Install the module with:
40
+ ```bash
41
+ pip install textmate-grammar-python
42
+ ```
35
43
 
36
44
  Before tokenization is possible, a `LanguageParser` needs to be initialized using a loaded grammar.
37
45
 
@@ -41,9 +49,9 @@ from textmate_grammar.grammars import matlab
41
49
  parser = LanguageParser(matlab.GRAMMAR)
42
50
  ```
43
51
 
44
- After this, one can either choose to call `parser.parsing_string` to parse a input string directly, or call `parser.parse_file` with the path to the appropiate source file as the first argument, such as the the example `example.py`.
52
+ After this, one can either choose to call [`parser.parsing_string`](https://textmate-grammar-python.readthedocs.io/en/latest/apidocs/textmate_grammar/textmate_grammar.language.html#textmate_grammar.language.LanguageParser.parse_string) to parse a input string directly, or call [`parser.parse_file`](https://textmate-grammar-python.readthedocs.io/en/latest/apidocs/textmate_grammar/textmate_grammar.language.html#textmate_grammar.language.LanguageParser.parse_file) with the path to the appropiate source file as the first argument, such as in the example [`example.py`](https://github.com/watermarkhu/textmate-grammar-python/blob/main/example.py).
45
53
 
46
- The parsed `element` object can be displayed directly by calling the `print` method. By default the element is printed as an element tree in a dictionary format.
54
+ The parsed `element` object can be displayed directly by calling the [`print`](https://textmate-grammar-python.readthedocs.io/en/latest/apidocs/textmate_grammar/textmate_grammar.elements.html#textmate_grammar.elements.ContentElement.print) method. By default the element is printed as an element tree in a dictionary format.
47
55
 
48
56
  ```python
49
57
  >>> element = parser.parse_string("value = num2str(10);")
@@ -77,15 +85,7 @@ Alternatively, with the keyword argument `flatten` the element is displayed as a
77
85
  [(0, 19), ';', ['source.matlab', 'punctuation.terminator.semicolon.matlab']]]
78
86
  ```
79
87
 
80
- ## Supported Languages
81
- - [MATLAB](https://github.com/mathworks/MATLAB-Language-grammar)
82
-
83
- ## TODO
84
- - Implement Begin/While pattern, required for other grammars.
85
-
86
- ## Sources
87
- - [Textmate guide](https://www.apeth.com/nonblog/stories/textmatebundle.html)
88
- - [VSCode Syntax Highlighting guide](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)
89
- - [vscode-textmate](https://github.com/microsoft/vscode-textmate)
90
- - [Macromates texmate](https://macromates.com/textmate/manual/)
88
+ ## Information
91
89
 
90
+ - For further information, please checkout the [documentation](https://textmate-grammar-python.readthedocs.io/en/latest/).
91
+ - To setup an environment for development, see [CONTRIBUTING.md](https://github.com/watermarkhu/textmate-grammar-python/blob/main/CONTRIBUTING.md)
@@ -2,17 +2,22 @@
2
2
  [![PyPI - License](https://img.shields.io/pypi/l/textmate-grammar-python.svg)](https://github.com/watermarkhu/textmate-grammar-python/tree/main?tab=MIT-1-ov-file)
3
3
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
4
4
  [![Checked with mypy](https://img.shields.io/badge/mypy-checked-blue)](http://mypy-lang.org/)
5
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
5
6
  [![Python versions](https://img.shields.io/pypi/pyversions/textmate-grammar-python.svg)](https://pypi.python.org/pypi/textmate-grammar-python)
6
7
  [![CI/CD](https://github.com/watermarkhu/textmate-grammar-python/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/watermarkhu/textmate-grammar-python/blob/main/.github/workflows/ci.yml)
7
-
8
+ [![readthedocs](https://readthedocs.org/projects/textmate-grammar-python/badge/?version=latest)](https://textmate-grammar-python.readthedocs.io)
8
9
 
9
10
  # textmate-grammar-python
10
11
 
11
- 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.
12
+ A lexer and tokenizer for grammar files as defined by TextMate and used in VSCode, implemented in Python.
12
13
 
14
+ Textmate grammars are made for [vscode-texmate](https://github.com/microsoft/vscode-textmate), allowing for syntax highlighting in VSCode after tokenization. This presents textmate-grammar-python with a large list of potentially supported languages.
13
15
 
14
16
  ## Usage
15
- Install the module using `pip install textmate-grammar-python`.
17
+ Install the module with:
18
+ ```bash
19
+ pip install textmate-grammar-python
20
+ ```
16
21
 
17
22
  Before tokenization is possible, a `LanguageParser` needs to be initialized using a loaded grammar.
18
23
 
@@ -22,9 +27,9 @@ from textmate_grammar.grammars import matlab
22
27
  parser = LanguageParser(matlab.GRAMMAR)
23
28
  ```
24
29
 
25
- After this, one can either choose to call `parser.parsing_string` to parse a input string directly, or call `parser.parse_file` with the path to the appropiate source file as the first argument, such as the the example `example.py`.
30
+ After this, one can either choose to call [`parser.parsing_string`](https://textmate-grammar-python.readthedocs.io/en/latest/apidocs/textmate_grammar/textmate_grammar.language.html#textmate_grammar.language.LanguageParser.parse_string) to parse a input string directly, or call [`parser.parse_file`](https://textmate-grammar-python.readthedocs.io/en/latest/apidocs/textmate_grammar/textmate_grammar.language.html#textmate_grammar.language.LanguageParser.parse_file) with the path to the appropiate source file as the first argument, such as in the example [`example.py`](https://github.com/watermarkhu/textmate-grammar-python/blob/main/example.py).
26
31
 
27
- The parsed `element` object can be displayed directly by calling the `print` method. By default the element is printed as an element tree in a dictionary format.
32
+ The parsed `element` object can be displayed directly by calling the [`print`](https://textmate-grammar-python.readthedocs.io/en/latest/apidocs/textmate_grammar/textmate_grammar.elements.html#textmate_grammar.elements.ContentElement.print) method. By default the element is printed as an element tree in a dictionary format.
28
33
 
29
34
  ```python
30
35
  >>> element = parser.parse_string("value = num2str(10);")
@@ -58,14 +63,7 @@ Alternatively, with the keyword argument `flatten` the element is displayed as a
58
63
  [(0, 19), ';', ['source.matlab', 'punctuation.terminator.semicolon.matlab']]]
59
64
  ```
60
65
 
61
- ## Supported Languages
62
- - [MATLAB](https://github.com/mathworks/MATLAB-Language-grammar)
63
-
64
- ## TODO
65
- - Implement Begin/While pattern, required for other grammars.
66
+ ## Information
66
67
 
67
- ## Sources
68
- - [Textmate guide](https://www.apeth.com/nonblog/stories/textmatebundle.html)
69
- - [VSCode Syntax Highlighting guide](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)
70
- - [vscode-textmate](https://github.com/microsoft/vscode-textmate)
71
- - [Macromates texmate](https://macromates.com/textmate/manual/)
68
+ - For further information, please checkout the [documentation](https://textmate-grammar-python.readthedocs.io/en/latest/).
69
+ - To setup an environment for development, see [CONTRIBUTING.md](https://github.com/watermarkhu/textmate-grammar-python/blob/main/CONTRIBUTING.md)
@@ -0,0 +1,95 @@
1
+ [build-system]
2
+ requires = ["poetry-core"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
5
+ [tool.poetry]
6
+ name = "textmate-grammar-python"
7
+ version = "0.4.0"
8
+ description = "A lexer and tokenizer for grammar files as defined by TextMate and used in VSCode, implemented in Python."
9
+ authors = ["Mark Shui Hu <watermarkhu@gmail.com>"]
10
+ license = "MIT"
11
+ readme = "README.md"
12
+ repository = "https://github.com/watermarkhu/textmate-grammar-python"
13
+ documentation = "https://textmate-grammar-python.readthedocs.io"
14
+ keywords = ["textmate", "tokenization"]
15
+ packages = [{include = "textmate_grammar", from = "src"}]
16
+
17
+ [tool.poetry.dependencies]
18
+ python = "^3.9"
19
+ onigurumacffi = "^1.3.0"
20
+ PyYAML = "^6.0.1"
21
+
22
+ [tool.poetry.group.test.dependencies]
23
+ pytest = ">=7.3.1,<9.0.0"
24
+ pytest-icdiff = ">=0.8,<0.10"
25
+ tox = "^4.11.4"
26
+
27
+ [tool.poetry.group.dev.dependencies]
28
+ pre-commit = "^3.6.0"
29
+ mypy = "^1.8.0"
30
+ ruff = "^0.3.0"
31
+ types-pyyaml = "^6.0.12.12"
32
+ poetry-bumpversion = "^0.3.2"
33
+
34
+ [tool.poetry.group.doc.dependencies]
35
+ sphinx = "^7.2.6"
36
+ sphinx-autodoc2 = "^0.5.0"
37
+ myst-parser = "^2.0.0"
38
+ furo = "^2024.1.29"
39
+ sphinxcontrib-mermaid = "^0.9.2"
40
+
41
+ [tool.poetry_bumpversion.file."src/textmate_grammar/__init__.py"]
42
+
43
+ [tool.poetry_bumpversion.file."docs/conf.py"]
44
+ search = 'version = "{current_version}"'
45
+ replace = 'version = "{new_version}"'
46
+
47
+ [tool.ruff]
48
+ include = ["pyproject.toml", "src/textmate_grammar/**/*.py"]
49
+ exclude = ["src/textmate_grammar/grammars/"]
50
+ line-length = 100
51
+ indent-width = 4
52
+
53
+ [tool.ruff.lint]
54
+ select = ["E", "F", "UP", "B", "SIM", "I"]
55
+ ignore = ["E111", "E114", "E117", "E501", "F401"]
56
+
57
+ [tool.ruff.format]
58
+ quote-style = "double"
59
+ indent-style = "space"
60
+ skip-magic-trailing-comma = false
61
+ line-ending = "auto"
62
+ docstring-code-format = true
63
+ docstring-code-line-length = "dynamic"
64
+
65
+ [tool.mypy]
66
+ ignore_missing_imports = true
67
+ exclude = ["test/*", "docs/*", "example.py"]
68
+
69
+ [tool.tox]
70
+ legacy_tox_ini = """
71
+ [tox]
72
+ isolated_build = true
73
+
74
+ [testenv]
75
+ skip_install = true
76
+ allowlist_externals = poetry
77
+ commands =
78
+ poetry run pytest test/unit
79
+
80
+ [testenv:mypy]
81
+ skip_install = true
82
+ allowlist_externals = mypy
83
+ commands =
84
+ mypy .
85
+
86
+ [testenv:regression]
87
+ skip_install = true
88
+ allowlist_externals = poetry, bash, sudo
89
+ platform = linux
90
+ change_dir = {tox_root}/test/regression
91
+ commands_pre =
92
+ bash install.sh
93
+ commands =
94
+ poetry run pytest .
95
+ """
@@ -0,0 +1 @@
1
+ __version__ = "0.4.0"