textmate-grammar-python 0.6.0__tar.gz → 0.7.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 (111) hide show
  1. textmate_grammar_python-0.7.0/.github/dependabot.yml +6 -0
  2. textmate_grammar_python-0.7.0/.github/workflows/ci.yml +72 -0
  3. textmate_grammar_python-0.7.0/.github/workflows/docs.yml +42 -0
  4. textmate_grammar_python-0.7.0/.github/workflows/release.yml +31 -0
  5. textmate_grammar_python-0.7.0/.gitignore +171 -0
  6. textmate_grammar_python-0.7.0/.gitmodules +6 -0
  7. textmate_grammar_python-0.7.0/.pre-commit-config.yaml +33 -0
  8. textmate_grammar_python-0.7.0/.vscode/launch.json +16 -0
  9. textmate_grammar_python-0.7.0/.vscode/settings.json +14 -0
  10. textmate_grammar_python-0.7.0/CHANGELOG.md +11 -0
  11. textmate_grammar_python-0.7.0/CONTRIBUTING.md +22 -0
  12. textmate_grammar_python-0.7.0/PKG-INFO +72 -0
  13. textmate_grammar_python-0.7.0/README.md +49 -0
  14. textmate_grammar_python-0.7.0/docs/Makefile +20 -0
  15. textmate_grammar_python-0.7.0/docs/conf.py +54 -0
  16. textmate_grammar_python-0.7.0/docs/index.md +37 -0
  17. textmate_grammar_python-0.7.0/docs/languages.md +12 -0
  18. textmate_grammar_python-0.7.0/docs/make.bat +35 -0
  19. textmate_grammar_python-0.7.0/docs/requirements.txt +720 -0
  20. textmate_grammar_python-0.7.0/docs/started.md +31 -0
  21. textmate_grammar_python-0.7.0/docs/tokenization.md +7 -0
  22. textmate_grammar_python-0.7.0/example.py +7 -0
  23. textmate_grammar_python-0.7.0/pyproject.toml +80 -0
  24. textmate_grammar_python-0.7.0/readthedocs.yaml +16 -0
  25. textmate_grammar_python-0.7.0/renovate.json +6 -0
  26. textmate_grammar_python-0.7.0/src/textmate_grammar/__init__.py +34 -0
  27. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/__init__.py +73 -0
  28. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/debug.py +22 -0
  29. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/matcher.py +250 -0
  30. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/oniglib.py +259 -0
  31. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/plist.py +577 -0
  32. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/raw_grammar.py +756 -0
  33. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/regexsource.py +393 -0
  34. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/registry.py +482 -0
  35. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/rules.py +964 -0
  36. textmate_grammar_python-0.7.0/src/textmate_grammar/engine/tokenize.py +1070 -0
  37. textmate_grammar_python-0.7.0/src/textmate_grammar/parsers/markdown/__init__.py +57 -0
  38. textmate_grammar_python-0.7.0/src/textmate_grammar/parsers/markdown/markdown.tmLanguage +4950 -0
  39. textmate_grammar_python-0.7.0/src/textmate_grammar/parsers/matlab/MATLAB.tmLanguage +2926 -0
  40. textmate_grammar_python-0.7.0/src/textmate_grammar/parsers/matlab/__init__.py +57 -0
  41. textmate_grammar_python-0.7.0/test/__init__.py +0 -0
  42. textmate_grammar_python-0.7.0/test/differential/.gitignore +5 -0
  43. textmate_grammar_python-0.7.0/test/differential/__init__.py +0 -0
  44. textmate_grammar_python-0.7.0/test/differential/corpus/grammars/LICENSES.txt +15 -0
  45. textmate_grammar_python-0.7.0/test/differential/corpus/grammars/TypeScript.tmLanguage +9858 -0
  46. textmate_grammar_python-0.7.0/test/differential/corpus/grammars/python.tmLanguage.json +4213 -0
  47. textmate_grammar_python-0.7.0/test/differential/corpus/markdown/fenced_injections.md +12 -0
  48. textmate_grammar_python-0.7.0/test/differential/corpus/markdown/hard_breaks.md +3 -0
  49. textmate_grammar_python-0.7.0/test/differential/corpus/markdown/nested_blockquotes.md +8 -0
  50. textmate_grammar_python-0.7.0/test/differential/corpus/markdown/tables.md +4 -0
  51. textmate_grammar_python-0.7.0/test/differential/corpus/markdown/unclosed_fence.md +5 -0
  52. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/anonymous_function_args.m +4 -0
  53. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/crlf_unicode.m +4 -0
  54. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/empty.m +0 -0
  55. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/end_patterns.m +15 -0
  56. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/long_line.m +1 -0
  57. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/nested_while_comments.m +21 -0
  58. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/test_multiple_inheritance_ml.m +14 -0
  59. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/unterminated_comment.m +4 -0
  60. textmate_grammar_python-0.7.0/test/differential/corpus/matlab/whitespace_only.m +2 -0
  61. textmate_grammar_python-0.7.0/test/differential/corpus/python/async_context.py +19 -0
  62. textmate_grammar_python-0.7.0/test/differential/corpus/python/comprehensions.py +9 -0
  63. textmate_grammar_python-0.7.0/test/differential/corpus/python/dataclass.py +11 -0
  64. textmate_grammar_python-0.7.0/test/differential/corpus/python/fstrings_and_comments.py +5 -0
  65. textmate_grammar_python-0.7.0/test/differential/corpus/python/pattern_matching.py +8 -0
  66. textmate_grammar_python-0.7.0/test/differential/corpus/typescript/classes.ts +14 -0
  67. textmate_grammar_python-0.7.0/test/differential/corpus/typescript/control_flow.ts +8 -0
  68. textmate_grammar_python-0.7.0/test/differential/corpus/typescript/decorators.ts +13 -0
  69. textmate_grammar_python-0.7.0/test/differential/corpus/typescript/generics.ts +10 -0
  70. textmate_grammar_python-0.7.0/test/differential/corpus/typescript/template_strings.ts +8 -0
  71. textmate_grammar_python-0.7.0/test/differential/corpus.py +149 -0
  72. textmate_grammar_python-0.7.0/test/differential/engine_adapter.py +108 -0
  73. textmate_grammar_python-0.7.0/test/differential/node_root/package-lock.json +29 -0
  74. textmate_grammar_python-0.7.0/test/differential/node_root/package.json +14 -0
  75. textmate_grammar_python-0.7.0/test/differential/oracle.js +123 -0
  76. textmate_grammar_python-0.7.0/test/differential/test_differential.py +211 -0
  77. textmate_grammar_python-0.7.0/test/unit/__init__.py +2 -0
  78. textmate_grammar_python-0.7.0/test/unit/engine/__init__.py +0 -0
  79. textmate_grammar_python-0.7.0/test/unit/engine/data/markdown.tmLanguage.json +3078 -0
  80. textmate_grammar_python-0.7.0/test/unit/engine/test_matcher.py +274 -0
  81. textmate_grammar_python-0.7.0/test/unit/engine/test_oniglib.py +175 -0
  82. textmate_grammar_python-0.7.0/test/unit/engine/test_plist.py +381 -0
  83. textmate_grammar_python-0.7.0/test/unit/engine/test_raw_grammar.py +280 -0
  84. textmate_grammar_python-0.7.0/test/unit/engine/test_regexsource.py +332 -0
  85. textmate_grammar_python-0.7.0/test/unit/engine/test_registry.py +149 -0
  86. textmate_grammar_python-0.7.0/test/unit/engine/test_rules.py +542 -0
  87. textmate_grammar_python-0.7.0/test/unit/engine/test_tokenize.py +104 -0
  88. textmate_grammar_python-0.7.0/test/unit/matlab/test_tokenization.py +64 -0
  89. textmate_grammar_python-0.7.0/test/unit/test_language_wrappers.py +12 -0
  90. textmate_grammar_python-0.7.0/uv.lock +1632 -0
  91. textmate_grammar_python-0.6.0/PKG-INFO +0 -91
  92. textmate_grammar_python-0.6.0/README.md +0 -68
  93. textmate_grammar_python-0.6.0/pyproject.toml +0 -103
  94. textmate_grammar_python-0.6.0/src/textmate_grammar/__init__.py +0 -1
  95. textmate_grammar_python-0.6.0/src/textmate_grammar/elements.py +0 -552
  96. textmate_grammar_python-0.6.0/src/textmate_grammar/handler.py +0 -301
  97. textmate_grammar_python-0.6.0/src/textmate_grammar/parser.py +0 -904
  98. textmate_grammar_python-0.6.0/src/textmate_grammar/parsers/base.py +0 -192
  99. textmate_grammar_python-0.6.0/src/textmate_grammar/parsers/markdown/__init__.py +0 -27
  100. textmate_grammar_python-0.6.0/src/textmate_grammar/parsers/markdown/grammar.yaml +0 -583
  101. textmate_grammar_python-0.6.0/src/textmate_grammar/parsers/matlab/__init__.py +0 -72
  102. textmate_grammar_python-0.6.0/src/textmate_grammar/parsers/matlab/grammar.yaml +0 -1041
  103. textmate_grammar_python-0.6.0/src/textmate_grammar/utils/cache.py +0 -163
  104. textmate_grammar_python-0.6.0/src/textmate_grammar/utils/exceptions.py +0 -72
  105. textmate_grammar_python-0.6.0/src/textmate_grammar/utils/logger.py +0 -170
  106. {textmate_grammar_python-0.6.0 → textmate_grammar_python-0.7.0}/LICENSE +0 -0
  107. {textmate_grammar_python-0.6.0 → textmate_grammar_python-0.7.0}/src/textmate_grammar/parsers/__init__.py +0 -0
  108. {textmate_grammar_python-0.6.0 → textmate_grammar_python-0.7.0}/src/textmate_grammar/parsers/markdown/LICENSE.txt +0 -0
  109. {textmate_grammar_python-0.6.0 → textmate_grammar_python-0.7.0}/src/textmate_grammar/parsers/matlab/license.txt +0 -0
  110. {textmate_grammar_python-0.6.0 → textmate_grammar_python-0.7.0}/src/textmate_grammar/py.typed +0 -0
  111. {textmate_grammar_python-0.6.0 → textmate_grammar_python-0.7.0}/src/textmate_grammar/utils/__init__.py +0 -0
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
@@ -0,0 +1,72 @@
1
+ name: "CI"
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ pull_request:
6
+ branches:
7
+ - main
8
+ paths:
9
+ - '.github/workflows/ci.yml'
10
+ - '.pre-commit-config.yaml'
11
+ - 'pyproject.toml'
12
+ - 'uv.lock'
13
+ - 'src/**'
14
+ - 'test/**'
15
+
16
+ jobs:
17
+
18
+ unit-test:
19
+
20
+ runs-on: ubuntu-latest
21
+ strategy:
22
+ matrix:
23
+ python-version: ["3.10", "3.11", "3.12"]
24
+
25
+ steps:
26
+ - uses: actions/checkout@v7
27
+
28
+ - name: Install uv
29
+ uses: astral-sh/setup-uv@v10.3.0
30
+ with:
31
+ version: "latest"
32
+
33
+ - name: Install the project dependencies
34
+ run: uv sync --no-dev --group test --python ${{ matrix.python-version }}
35
+
36
+ - name: Test with pytest
37
+ run: |
38
+ uv run pytest -v test/unit
39
+
40
+ differential-test:
41
+ runs-on: ubuntu-latest
42
+ strategy:
43
+ matrix:
44
+ python-version: ["3.10", "3.11", "3.12"]
45
+ node-version: [20]
46
+
47
+ steps:
48
+ - uses: actions/checkout@v7
49
+ with:
50
+ submodules: true
51
+
52
+ - name: Setup node ${{ matrix.node-version }}
53
+ uses: actions/setup-node@v7
54
+ with:
55
+ node-version: ${{ matrix.node-version }}
56
+
57
+ - name: Install node dependencies
58
+ run: |
59
+ cd test/differential/node_root
60
+ npm ci
61
+
62
+ - name: Install uv
63
+ uses: astral-sh/setup-uv@v10.3.0
64
+ with:
65
+ version: "latest"
66
+
67
+ - name: Install the project dependencies
68
+ run: uv sync --no-dev --group test --python ${{ matrix.python-version }}
69
+
70
+ - name: Test with pytest
71
+ run: |
72
+ uv run pytest -v test/differential
@@ -0,0 +1,42 @@
1
+ name: documentation
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - main
8
+ paths:
9
+ - 'src/**'
10
+ - 'docs/**'
11
+ - 'pyproject.toml'
12
+ - 'uv.lock'
13
+ - '.github/workflows/docs.yml'
14
+
15
+ permissions:
16
+ contents: write
17
+
18
+ jobs:
19
+ docs:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v7
23
+
24
+ - name: Install uv
25
+ uses: astral-sh/setup-uv@v10.3.0
26
+ with:
27
+ version: "latest"
28
+
29
+ - name: Install dependencies
30
+ run: uv sync --no-dev --group doc
31
+
32
+ - name: Sphinx build
33
+ run: uv run make -C docs html
34
+
35
+ - name: Deploy to GitHub Pages
36
+ uses: peaceiris/actions-gh-pages@v4
37
+ if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
38
+ with:
39
+ publish_branch: gh-pages
40
+ github_token: ${{ secrets.GITHUB_TOKEN }}
41
+ publish_dir: docs/_build/html
42
+ force_orphan: true
@@ -0,0 +1,31 @@
1
+ name: release with uv
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - main
8
+ paths:
9
+ - 'src/textmate_grammar/__init__.py'
10
+
11
+ jobs:
12
+ release:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v7
16
+
17
+ - name: Install uv
18
+ uses: astral-sh/setup-uv@v10.3.0
19
+ with:
20
+ version: "latest"
21
+
22
+ - name: Install the project dependencies
23
+ run: uv sync --no-dev
24
+
25
+ - name: Build package distributions
26
+ run: uv build
27
+
28
+ - name: Publish to PyPI
29
+ env:
30
+ UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
31
+ run: uv publish
@@ -0,0 +1,171 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+ docs/apidocs/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ #Pipfile.lock
97
+
98
+ # poetry
99
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103
+ # poetry.lock
104
+
105
+ # pdm
106
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107
+ #pdm.lock
108
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109
+ # in version control.
110
+ # https://pdm.fming.dev/#use-with-ide
111
+ .pdm.toml
112
+
113
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
114
+ __pypackages__/
115
+
116
+ # Celery stuff
117
+ celerybeat-schedule
118
+ celerybeat.pid
119
+
120
+ # SageMath parsed files
121
+ *.sage.py
122
+
123
+ # Environments
124
+ .env
125
+ .venv
126
+ env/
127
+ venv/
128
+ ENV/
129
+ env.bak/
130
+ venv.bak/
131
+
132
+ # Spyder project settings
133
+ .spyderproject
134
+ .spyproject
135
+
136
+ # Rope project settings
137
+ .ropeproject
138
+
139
+ # mkdocs documentation
140
+ /site
141
+
142
+ # mypy
143
+ .mypy_cache/
144
+ .dmypy.json
145
+ dmypy.json
146
+
147
+ # Pyre type checker
148
+ .pyre/
149
+
150
+ # pytype static type analyzer
151
+ .pytype/
152
+
153
+ # Cython debug symbols
154
+ cython_debug/
155
+
156
+ # PyCharm
157
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
160
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
161
+ #.idea/
162
+
163
+ # Ruff cache
164
+ .ruff_cache/
165
+
166
+ # Textemate cache
167
+ .textmate_cache/
168
+
169
+ # Rye lock-files
170
+ requirements.lock
171
+ requirements-dev.lock
@@ -0,0 +1,6 @@
1
+ [submodule "syntaxes"]
2
+ path = syntaxes/matlab
3
+ url = https://github.com/mathworks/MATLAB-Language-grammar
4
+ [submodule "vscode-markdown-tm-grammar"]
5
+ path = syntaxes/markdown
6
+ url = https://github.com/microsoft/vscode-markdown-tm-grammar
@@ -0,0 +1,33 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ # Ruff version.
4
+ rev: v0.17.2
5
+ hooks:
6
+ # Run the linter.
7
+ - id: ruff
8
+ args: [--fix]
9
+ pass_filenames: false
10
+ # Run the formatter.
11
+ - id: ruff-format
12
+ pass_filenames: false
13
+
14
+ - repo: https://github.com/pre-commit/mirrors-mypy
15
+ rev: v2.4.0
16
+ hooks:
17
+ - id: mypy
18
+ additional_dependencies: ["types-pyyaml"]
19
+ exclude: |
20
+ (?x)^(
21
+ example.py|
22
+ test\/.*.py|
23
+ docs\/.*.py
24
+ )$
25
+
26
+ - repo: local
27
+ hooks:
28
+ - id: uv-export
29
+ name: export doc requirements from uv.lock
30
+ entry: uv export --no-emit-project --no-dev --group doc --format requirements-txt -o docs/requirements.txt
31
+ language: system
32
+ pass_filenames: false
33
+ files: ^(pyproject\.toml|uv\.lock)$
@@ -0,0 +1,16 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Python Debugger: Current File",
9
+ "type": "debugpy",
10
+ "request": "launch",
11
+ "program": "${file}",
12
+ "console": "integratedTerminal",
13
+ "justMyCode": true
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "python.testing.pytestArgs": [
3
+ "test"
4
+ ],
5
+ "python.testing.unittestEnabled": false,
6
+ "python.testing.pytestEnabled": true,
7
+ "files.exclude": {
8
+ "**/__pycache__": true,
9
+ "**/.mypy_cache": true,
10
+ "**/.pytest_cache": true,
11
+ "**/.ruff_cache": true,
12
+ "**/.tox": true,
13
+ },
14
+ }
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.7.0
4
+
5
+ This is a breaking 0.x release and a full port of the vscode-textmate 9.3.2 tokenization engine. It includes the rule model, scope-selector matcher, state stacks, tokenization loop, plist/JSON grammar loading, and Registry.
6
+
7
+ - The public API now follows vscode-textmate: `Registry`, `parseRawGrammar`, `Grammar.tokenizeLine`, `IToken`, and line-to-line `ruleStack` state.
8
+ - **Breaking:** the legacy element-tree API was removed. `ContentElement`, `flatten`, `parse_file`, and `parse_string` are no longer available.
9
+ - The minimum supported Python version is 3.10.
10
+ - Differential CI compares the Python engine with the pinned Node oracle across a 50-case MATLAB, Markdown, Python, and TypeScript corpus.
11
+ - Consolidates the dependency updates from the preceding implementation work (`onigurumacffi`, PyYAML, and `charset-normalizer`); test, development, and documentation tools are managed in uv dependency groups.
@@ -0,0 +1,22 @@
1
+ Use [uv](https://docs.astral.sh/uv/) to install the project and test dependencies. Install [pre-commit](https://pre-commit.com/) to run Ruff and mypy checks automatically:
2
+
3
+ ```bash
4
+ uv sync --group test
5
+ uv run pre-commit install
6
+ ```
7
+
8
+ Run the unit tests with:
9
+
10
+ ```bash
11
+ uv run pytest -q test/unit
12
+ ```
13
+
14
+ The differential suite compares this port with the pinned Node oracle. It needs Node on `PATH`, the grammar corpus submodules, and the oracle's npm dependencies:
15
+
16
+ ```bash
17
+ git submodule update --init
18
+ (cd test/differential/node_root && npm ci)
19
+ uv run pytest -q test/differential
20
+ ```
21
+
22
+ Run the full checks with `uv run ruff check src/` and `uv run mypy .`. For the documentation build, install the doc group (`uv sync --no-dev --group doc`) and run `uv run make -C docs html`.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.5
2
+ Name: textmate-grammar-python
3
+ Version: 0.7.0
4
+ Summary: A Python port of the vscode-textmate grammar tokenization engine.
5
+ Project-URL: Repository, https://github.com/watermarkhu/textmate-grammar-python
6
+ Project-URL: Documentation, https://textmate-grammar-python.readthedocs.io
7
+ Author-email: Mark Shui Hu <watermarkhu@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: grammar,syntax-highlighting,textmate,tokenization,vscode
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Software Development :: Compilers
17
+ Classifier: Topic :: Text Processing :: General
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: charset-normalizer<4.0.0,>=3.3.2
20
+ Requires-Dist: onigurumacffi<2.0.0,>=1.3.0
21
+ Requires-Dist: pyyaml<7.0.0,>=6.0.1
22
+ Description-Content-Type: text/markdown
23
+
24
+ [![PyPI - Version](https://img.shields.io/pypi/v/textmate-grammar-python.svg)](https://pypi.python.org/pypi/textmate-grammar-python)
25
+ [![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)
26
+ [![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)
27
+ [![Checked with mypy](https://img.shields.io/badge/mypy-checked-blue)](http://mypy-lang.org/)
28
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
29
+ [![Python versions](https://img.shields.io/pypi/pyversions/textmate-grammar-python.svg)](https://pypi.python.org/pypi/textmate-grammar-python)
30
+ [![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)
31
+ [![readthedocs](https://readthedocs.org/projects/textmate-grammar-python/badge/?version=latest)](https://textmate-grammar-python.readthedocs.io)
32
+
33
+ # textmate-grammar-python
34
+
35
+ A Python port of the [vscode-textmate](https://github.com/microsoft/vscode-textmate) grammar tokenization engine. It loads TextMate grammars and tokenizes source one line at a time, carrying the rule stack between lines.
36
+
37
+ The `textmate_grammar.engine` modules port the rule model, scope matcher, grammar loading and registry, and stateful tokenization loop. A differential suite compares token boundaries and scope paths against the real vscode-textmate 9.3.2 Node oracle across a 50-case MATLAB, Markdown, Python, and TypeScript corpus.
38
+
39
+ ## Usage
40
+ Requires Python 3.10 or newer. Install with:
41
+ ```bash
42
+ pip install textmate-grammar-python
43
+ ```
44
+
45
+ The public API follows vscode-textmate's registry and line-tokenization model. A registry loads raw grammar data by scope name; pass each line's returned `ruleStack` into the next call:
46
+
47
+ ```python
48
+ from pathlib import Path
49
+
50
+ from textmate_grammar import INITIAL, Registry, parseRawGrammar
51
+
52
+ grammar_path = Path("MATLAB.tmLanguage")
53
+ raw_grammar = parseRawGrammar(grammar_path.read_text(), str(grammar_path))
54
+ registry = Registry({"loadGrammar": lambda scope: raw_grammar if scope == "source.matlab" else None})
55
+ grammar = registry.loadGrammar("source.matlab")
56
+ state = INITIAL
57
+ for line in Path("example.m").read_text().splitlines():
58
+ result = grammar.tokenizeLine(line, state)
59
+ state = result.ruleStack
60
+ print(result.tokens) # each token has startIndex, endIndex, and scopes
61
+ ```
62
+
63
+ The bundled MATLAB and Markdown grammar helpers are also available from `textmate_grammar.parsers.matlab` and `textmate_grammar.parsers.markdown`.
64
+
65
+ ## Migrating from 0.6.x
66
+
67
+ This 0.7.0 release is breaking within the 0.x series. The old `LanguageParser` / `ContentElement` tree API (including `parse_file`, `parse_string`, and `flatten`) is removed without compatibility shims. Replace it with `Registry`, `parseRawGrammar`, `Grammar.tokenizeLine`, `IToken` tokens, and the `ruleStack` state API shown above.
68
+
69
+ ## Information
70
+
71
+ - For further information, please checkout the [documentation](https://textmate-grammar-python.readthedocs.io/en/latest/).
72
+ - To setup an environment for development, see [CONTRIBUTING.md](https://github.com/watermarkhu/textmate-grammar-python/blob/main/CONTRIBUTING.md)
@@ -0,0 +1,49 @@
1
+ [![PyPI - Version](https://img.shields.io/pypi/v/textmate-grammar-python.svg)](https://pypi.python.org/pypi/textmate-grammar-python)
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
+ [![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
+ [![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)
6
+ [![Python versions](https://img.shields.io/pypi/pyversions/textmate-grammar-python.svg)](https://pypi.python.org/pypi/textmate-grammar-python)
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)
8
+ [![readthedocs](https://readthedocs.org/projects/textmate-grammar-python/badge/?version=latest)](https://textmate-grammar-python.readthedocs.io)
9
+
10
+ # textmate-grammar-python
11
+
12
+ A Python port of the [vscode-textmate](https://github.com/microsoft/vscode-textmate) grammar tokenization engine. It loads TextMate grammars and tokenizes source one line at a time, carrying the rule stack between lines.
13
+
14
+ The `textmate_grammar.engine` modules port the rule model, scope matcher, grammar loading and registry, and stateful tokenization loop. A differential suite compares token boundaries and scope paths against the real vscode-textmate 9.3.2 Node oracle across a 50-case MATLAB, Markdown, Python, and TypeScript corpus.
15
+
16
+ ## Usage
17
+ Requires Python 3.10 or newer. Install with:
18
+ ```bash
19
+ pip install textmate-grammar-python
20
+ ```
21
+
22
+ The public API follows vscode-textmate's registry and line-tokenization model. A registry loads raw grammar data by scope name; pass each line's returned `ruleStack` into the next call:
23
+
24
+ ```python
25
+ from pathlib import Path
26
+
27
+ from textmate_grammar import INITIAL, Registry, parseRawGrammar
28
+
29
+ grammar_path = Path("MATLAB.tmLanguage")
30
+ raw_grammar = parseRawGrammar(grammar_path.read_text(), str(grammar_path))
31
+ registry = Registry({"loadGrammar": lambda scope: raw_grammar if scope == "source.matlab" else None})
32
+ grammar = registry.loadGrammar("source.matlab")
33
+ state = INITIAL
34
+ for line in Path("example.m").read_text().splitlines():
35
+ result = grammar.tokenizeLine(line, state)
36
+ state = result.ruleStack
37
+ print(result.tokens) # each token has startIndex, endIndex, and scopes
38
+ ```
39
+
40
+ The bundled MATLAB and Markdown grammar helpers are also available from `textmate_grammar.parsers.matlab` and `textmate_grammar.parsers.markdown`.
41
+
42
+ ## Migrating from 0.6.x
43
+
44
+ This 0.7.0 release is breaking within the 0.x series. The old `LanguageParser` / `ContentElement` tree API (including `parse_file`, `parse_string`, and `flatten`) is removed without compatibility shims. Replace it with `Registry`, `parseRawGrammar`, `Grammar.tokenizeLine`, `IToken` tokens, and the `ruleStack` state API shown above.
45
+
46
+ ## Information
47
+
48
+ - For further information, please checkout the [documentation](https://textmate-grammar-python.readthedocs.io/en/latest/).
49
+ - To setup an environment for development, see [CONTRIBUTING.md](https://github.com/watermarkhu/textmate-grammar-python/blob/main/CONTRIBUTING.md)
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = .
9
+ BUILDDIR = _build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@@ -0,0 +1,54 @@
1
+ from datetime import date
2
+
3
+ # -- Project information -----------------------------------------------------
4
+
5
+ project = "TextMate Grammar Python"
6
+ version = "0.7.0"
7
+ copyright = f"{date.today().year}, Mark Shui Hu"
8
+ author = "Mark Shui Hu"
9
+
10
+ # -- General configuration ---------------------------------------------------
11
+
12
+ extensions = [
13
+ "myst_parser",
14
+ "autodoc2",
15
+ "sphinx.ext.intersphinx",
16
+ "sphinx.ext.viewcode",
17
+ "sphinx.ext.todo",
18
+ "sphinxcontrib.mermaid",
19
+ ]
20
+ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
21
+ intersphinx_mapping = {
22
+ "python": ("https://docs.python.org/3/", None),
23
+ }
24
+ myst_enable_extensions = ["fieldlist", "deflist"]
25
+
26
+ # -- HTML output -------------------------------------------------
27
+
28
+ html_theme = "furo"
29
+ html_title = "TextMate Grammar Python"
30
+ html_theme_options = {
31
+ "top_of_page_button": "edit",
32
+ "source_repository": "https://github.com/watermarkhu/textmate-grammar-python/",
33
+ "source_branch": "main",
34
+ "source_directory": "docs/",
35
+ }
36
+ html_theme_options = {
37
+ "footer_icons": [
38
+ {
39
+ "name": "GitHub",
40
+ "url": "https://github.com/watermarkhu/textmate-grammar-python",
41
+ "html": """
42
+ <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
43
+ <path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
44
+ </svg>
45
+ """,
46
+ "class": "",
47
+ },
48
+ ],
49
+ }
50
+
51
+ # --- Autodoc configuration ------
52
+
53
+ autodoc2_packages = ["../src/textmate_grammar"]
54
+ autodoc2_hidden_objects = ["dunder", "private", "inherited"]
@@ -0,0 +1,37 @@
1
+ # Textmate Grammar Python
2
+
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
+ [![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)
6
+ [![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
+ [![readthedocs](https://readthedocs.org/projects/textmate-grammar-python/badge/?version=latest)](https://textmate-grammar-python.readthedocs.io)
8
+
9
+ A Python port of the [vscode-textmate](https://github.com/microsoft/vscode-textmate) grammar tokenization engine. It parses TextMate grammars and tokenizes source line by line while preserving the state stack between lines.
10
+
11
+ The engine's token streams are checked against vscode-textmate 9.3.2 using a Node oracle and a differential corpus spanning MATLAB, Markdown, Python, and TypeScript.
12
+
13
+ ```{mermaid}
14
+ flowchart LR
15
+ G[TextMate grammar] --> R[Registry]
16
+ C[source lines] --> R
17
+ R --> T[tokens + rule stack]
18
+ T -. differential comparison .-> O[vscode-textmate 9.3.2 oracle]
19
+ click O "https://github.com/microsoft/vscode-textmate"
20
+ ```
21
+
22
+ ## Index
23
+
24
+ ```{toctree}
25
+ :maxdepth: 2
26
+
27
+ started
28
+ languages
29
+ tokenization
30
+ apidocs/index
31
+ ```
32
+
33
+ ## Sources
34
+ - [Textmate guide](https://www.apeth.com/nonblog/stories/textmatebundle.html)
35
+ - [VSCode Syntax Highlighting guide](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)
36
+ - [vscode-textmate](https://github.com/microsoft/vscode-textmate)
37
+ - [Macromates texmate](https://macromates.com/textmate/manual/)