textmate-grammar-python 0.2.0__tar.gz → 0.3.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 (32) hide show
  1. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/PKG-INFO +32 -18
  2. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/README.md +29 -15
  3. textmate_grammar_python-0.3.0/pyproject.toml +95 -0
  4. textmate_grammar_python-0.3.0/src/textmate_grammar/__init__.py +1 -0
  5. textmate_grammar_python-0.3.0/src/textmate_grammar/elements.py +549 -0
  6. textmate_grammar_python-0.3.0/src/textmate_grammar/grammars/__pycache__/__init__.cpython-312.pyc +0 -0
  7. textmate_grammar_python-0.3.0/src/textmate_grammar/grammars/markdown/__pycache__/__init__.cpython-312.pyc +0 -0
  8. textmate_grammar_python-0.3.0/src/textmate_grammar/grammars/matlab/__pycache__/__init__.cpython-312.pyc +0 -0
  9. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/language.py +68 -25
  10. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/parser.py +59 -10
  11. textmate_grammar_python-0.3.0/src/textmate_grammar/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  12. textmate_grammar_python-0.3.0/src/textmate_grammar/utils/__pycache__/cache.cpython-312.pyc +0 -0
  13. textmate_grammar_python-0.3.0/src/textmate_grammar/utils/__pycache__/exceptions.cpython-312.pyc +0 -0
  14. textmate_grammar_python-0.3.0/src/textmate_grammar/utils/__pycache__/handler.cpython-312.pyc +0 -0
  15. textmate_grammar_python-0.3.0/src/textmate_grammar/utils/__pycache__/logger.cpython-312.pyc +0 -0
  16. textmate_grammar_python-0.3.0/src/textmate_grammar/utils/cache.py +160 -0
  17. textmate_grammar_python-0.3.0/src/textmate_grammar/utils/exceptions.py +69 -0
  18. {textmate_grammar_python-0.2.0/src/textmate_grammar → textmate_grammar_python-0.3.0/src/textmate_grammar/utils}/handler.py +81 -16
  19. {textmate_grammar_python-0.2.0/src/textmate_grammar → textmate_grammar_python-0.3.0/src/textmate_grammar/utils}/logger.py +31 -11
  20. textmate_grammar_python-0.2.0/pyproject.toml +0 -58
  21. textmate_grammar_python-0.2.0/src/textmate_grammar/elements.py +0 -366
  22. textmate_grammar_python-0.2.0/src/textmate_grammar/exceptions.py +0 -30
  23. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/LICENSE +0 -0
  24. {textmate_grammar_python-0.2.0/src/textmate_grammar → textmate_grammar_python-0.3.0/src/textmate_grammar/grammars}/__init__.py +0 -0
  25. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/grammars/markdown/LICENSE.txt +0 -0
  26. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/grammars/markdown/__init__.py +0 -0
  27. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/grammars/markdown/grammar.yaml +0 -0
  28. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/grammars/matlab/__init__.py +0 -0
  29. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/grammars/matlab/grammar.yaml +0 -0
  30. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/grammars/matlab/license.txt +0 -0
  31. {textmate_grammar_python-0.2.0 → textmate_grammar_python-0.3.0}/src/textmate_grammar/py.typed +0 -0
  32. {textmate_grammar_python-0.2.0/src/textmate_grammar/grammars → textmate_grammar_python-0.3.0/src/textmate_grammar/utils}/__init__.py +0 -0
@@ -1,7 +1,7 @@
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.3.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
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
16
16
  Requires-Dist: onigurumacffi (>=1.3.0,<2.0.0)
17
+ Project-URL: Documentation, https://textmate-grammar-python.readthedocs.io
17
18
  Project-URL: Repository, https://github.com/watermarkhu/textmate-grammar-python
18
19
  Description-Content-Type: text/markdown
19
20
 
@@ -21,17 +22,38 @@ Description-Content-Type: text/markdown
21
22
  [![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
23
  [![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
24
  [![Checked with mypy](https://img.shields.io/badge/mypy-checked-blue)](http://mypy-lang.org/)
25
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
24
26
  [![Python versions](https://img.shields.io/pypi/pyversions/textmate-grammar-python.svg)](https://pypi.python.org/pypi/textmate-grammar-python)
25
27
  [![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
-
28
+ [![readthedocs](https://readthedocs.org/projects/textmate-grammar-python/badge/?version=latest)](https://textmate-grammar-python.readthedocs.io)
27
29
 
28
30
  # textmate-grammar-python
29
31
 
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.
32
+ A lexer and tokenizer for grammar files as defined by TextMate and used in VSCode, implemented in Python.
33
+
34
+ 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.
31
35
 
36
+ ```mermaid
37
+ flowchart TD
38
+ A[grammar file]
39
+ Z[code]
40
+ B("`vscode-textmate **js**`")
41
+ C("`textmate-grammar-**python**`")
42
+ D[tokens]
43
+
44
+ click C "https://github.com/microsoft/vscode-textmate"
45
+
46
+ Z --> B
47
+ Z --> C
48
+ A -.-> B --> D
49
+ A -.-> C --> D
50
+ ```
32
51
 
33
52
  ## Usage
34
- Install the module using `pip install textmate-grammar-python`.
53
+ Install the module with:
54
+ ```bash
55
+ pip install textmate-grammar-python
56
+ ```
35
57
 
36
58
  Before tokenization is possible, a `LanguageParser` needs to be initialized using a loaded grammar.
37
59
 
@@ -41,9 +63,9 @@ from textmate_grammar.grammars import matlab
41
63
  parser = LanguageParser(matlab.GRAMMAR)
42
64
  ```
43
65
 
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`.
66
+ 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
67
 
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.
68
+ 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
69
 
48
70
  ```python
49
71
  >>> element = parser.parse_string("value = num2str(10);")
@@ -77,15 +99,7 @@ Alternatively, with the keyword argument `flatten` the element is displayed as a
77
99
  [(0, 19), ';', ['source.matlab', 'punctuation.terminator.semicolon.matlab']]]
78
100
  ```
79
101
 
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/)
102
+ ## Information
91
103
 
104
+ - For further information, please checkout the [documentation](https://textmate-grammar-python.readthedocs.io/en/latest/).
105
+ - To setup an environment for development, see [CONTRIBUTING.md](https://github.com/watermarkhu/textmate-grammar-python/blob/main/CONTRIBUTING.md)
@@ -2,17 +2,38 @@
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.
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.
15
+
16
+ ```mermaid
17
+ flowchart TD
18
+ A[grammar file]
19
+ Z[code]
20
+ B("`vscode-textmate **js**`")
21
+ C("`textmate-grammar-**python**`")
22
+ D[tokens]
12
23
 
24
+ click C "https://github.com/microsoft/vscode-textmate"
25
+
26
+ Z --> B
27
+ Z --> C
28
+ A -.-> B --> D
29
+ A -.-> C --> D
30
+ ```
13
31
 
14
32
  ## Usage
15
- Install the module using `pip install textmate-grammar-python`.
33
+ Install the module with:
34
+ ```bash
35
+ pip install textmate-grammar-python
36
+ ```
16
37
 
17
38
  Before tokenization is possible, a `LanguageParser` needs to be initialized using a loaded grammar.
18
39
 
@@ -22,9 +43,9 @@ from textmate_grammar.grammars import matlab
22
43
  parser = LanguageParser(matlab.GRAMMAR)
23
44
  ```
24
45
 
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`.
46
+ 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
47
 
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.
48
+ 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
49
 
29
50
  ```python
30
51
  >>> element = parser.parse_string("value = num2str(10);")
@@ -58,14 +79,7 @@ Alternatively, with the keyword argument `flatten` the element is displayed as a
58
79
  [(0, 19), ';', ['source.matlab', 'punctuation.terminator.semicolon.matlab']]]
59
80
  ```
60
81
 
61
- ## Supported Languages
62
- - [MATLAB](https://github.com/mathworks/MATLAB-Language-grammar)
63
-
64
- ## TODO
65
- - Implement Begin/While pattern, required for other grammars.
82
+ ## Information
66
83
 
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/)
84
+ - For further information, please checkout the [documentation](https://textmate-grammar-python.readthedocs.io/en/latest/).
85
+ - 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.3.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.11"
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.3.0"