phy-std-base-tokenizer 0.1.0rc1__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.
- phy_std_base_tokenizer-0.1.0rc1/.github/workflows/cibuildwheel-pypi.yml +176 -0
- phy_std_base_tokenizer-0.1.0rc1/.gitignore +12 -0
- phy_std_base_tokenizer-0.1.0rc1/.pylintrc +5 -0
- phy_std_base_tokenizer-0.1.0rc1/.vscode/c_cpp_properties.json +19 -0
- phy_std_base_tokenizer-0.1.0rc1/.vscode/launch.json +15 -0
- phy_std_base_tokenizer-0.1.0rc1/.vscode/settings.json +7 -0
- phy_std_base_tokenizer-0.1.0rc1/.vscode/tasks.json +20 -0
- phy_std_base_tokenizer-0.1.0rc1/CMakeLists.txt +31 -0
- phy_std_base_tokenizer-0.1.0rc1/LICENSE +21 -0
- phy_std_base_tokenizer-0.1.0rc1/PKG-INFO +169 -0
- phy_std_base_tokenizer-0.1.0rc1/README.md +150 -0
- phy_std_base_tokenizer-0.1.0rc1/pyproject.toml +51 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/__init__.py +26 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_phy_compat.py +272 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_token_type.py +144 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/_token.h +102 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/_tokenize.c +674 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/_tokenize.h +32 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/_tokenize_module.c +38 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/lexer/buffer.c +80 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/lexer/buffer.h +10 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/lexer/lexer.c +1779 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/lexer/lexer.h +8 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/lexer/state.c +137 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/lexer/state.h +154 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/tokenizer/helpers.c +687 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/tokenizer/helpers.h +38 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/tokenizer/readline_tokenizer.c +131 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/tokenizer/string_tokenizer.c +148 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/tokenizer/tokenizer.h +14 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize/tokenizer/utf8_tokenizer.c +55 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/_tokenize.pyi +21 -0
- phy_std_base_tokenizer-0.1.0rc1/src/phy_std_base_tokenzier/compat.py +94 -0
- phy_std_base_tokenizer-0.1.0rc1/tests/__init__.py +0 -0
- phy_std_base_tokenizer-0.1.0rc1/tests/test_main.py +57 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/diff.sh +2 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/Python-tokenize.c +445 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/lexer/buffer.c +80 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/lexer/buffer.h +10 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/lexer/lexer.c +1589 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/lexer/lexer.h +8 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/lexer/state.c +135 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/lexer/state.h +153 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/pycore_token.h +110 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/tokenizer/file_tokenizer.c +487 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/tokenizer/helpers.c +649 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/tokenizer/helpers.h +38 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/tokenizer/readline_tokenizer.c +131 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/tokenizer/string_tokenizer.c +148 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/tokenizer/tokenizer.h +14 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314/tokenizer/utf8_tokenizer.c +55 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py314-py315.diff +125 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/Python-tokenize.c +447 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/lexer/buffer.c +80 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/lexer/buffer.h +10 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/lexer/lexer.c +1599 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/lexer/lexer.h +8 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/lexer/state.c +137 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/lexer/state.h +154 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/pycore_token.h +110 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/tokenizer/file_tokenizer.c +487 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/tokenizer/helpers.c +650 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/tokenizer/helpers.h +38 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/tokenizer/readline_tokenizer.c +131 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/tokenizer/string_tokenizer.c +148 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/tokenizer/tokenizer.h +14 -0
- phy_std_base_tokenizer-0.1.0rc1/versions_src/py315/tokenizer/utf8_tokenizer.c +55 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
name: Build wheel & Upload to Pypi
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build_sdist:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- uses: actions/setup-python@v6
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.x"
|
|
20
|
+
|
|
21
|
+
- name: Build release distributions
|
|
22
|
+
run: |
|
|
23
|
+
# NOTE: put your own distribution build steps here.
|
|
24
|
+
python -m pip install build
|
|
25
|
+
python -m build --sdist --outdir dist/
|
|
26
|
+
|
|
27
|
+
- name: Upload distributions
|
|
28
|
+
uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: sdist
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
build_wheels:
|
|
34
|
+
name: Build wheels on ${{ matrix.os }}
|
|
35
|
+
runs-on: ${{ matrix.os }}
|
|
36
|
+
strategy:
|
|
37
|
+
matrix:
|
|
38
|
+
os:
|
|
39
|
+
[
|
|
40
|
+
ubuntu-latest,
|
|
41
|
+
ubuntu-24.04-arm,
|
|
42
|
+
# windows-latest,
|
|
43
|
+
# windows-11-arm,
|
|
44
|
+
# macos-15-intel,
|
|
45
|
+
# macos-latest,
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v5
|
|
50
|
+
|
|
51
|
+
# Used to host cibuildwheel
|
|
52
|
+
- uses: actions/setup-python@v6
|
|
53
|
+
with:
|
|
54
|
+
python-version: "3.x"
|
|
55
|
+
|
|
56
|
+
- name: Install cibuildwheel
|
|
57
|
+
run: python -m pip install cibuildwheel
|
|
58
|
+
|
|
59
|
+
- name: Build wheels
|
|
60
|
+
run: python -m cibuildwheel --output-dir wheelhouse
|
|
61
|
+
# to supply options, put them in 'env', like:
|
|
62
|
+
# env:
|
|
63
|
+
# CIBW_SOME_OPTION: value
|
|
64
|
+
# ...
|
|
65
|
+
|
|
66
|
+
- uses: actions/upload-artifact@v4
|
|
67
|
+
with:
|
|
68
|
+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
|
|
69
|
+
path: wheelhouse/*.whl
|
|
70
|
+
|
|
71
|
+
build_wheels_macos:
|
|
72
|
+
name: Build wheels on macOS ARM with ${{ matrix.py_version }}
|
|
73
|
+
runs-on: macos-latest
|
|
74
|
+
strategy:
|
|
75
|
+
matrix:
|
|
76
|
+
py_version:
|
|
77
|
+
[
|
|
78
|
+
'3.10',
|
|
79
|
+
'3.11',
|
|
80
|
+
'3.12',
|
|
81
|
+
'3.13',
|
|
82
|
+
'3.14',
|
|
83
|
+
'3.15',
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
steps:
|
|
87
|
+
- uses: actions/checkout@v5
|
|
88
|
+
|
|
89
|
+
# Used to host cibuildwheel
|
|
90
|
+
- uses: actions/setup-python@v6
|
|
91
|
+
with:
|
|
92
|
+
python-version: ${{ matrix.py_version }}
|
|
93
|
+
|
|
94
|
+
- name: Install cibuildwheel
|
|
95
|
+
run: python -m pip install uv
|
|
96
|
+
|
|
97
|
+
- name: Build wheels
|
|
98
|
+
run: uv build
|
|
99
|
+
|
|
100
|
+
- uses: actions/upload-artifact@v4
|
|
101
|
+
with:
|
|
102
|
+
name: macos-wheels-${{ matrix.py_version }}-${{ strategy.job-index }}
|
|
103
|
+
path: dist/*.whl
|
|
104
|
+
|
|
105
|
+
build_wheels_win32:
|
|
106
|
+
name: Build wheels on Windows with ${{ matrix.pyversion }}
|
|
107
|
+
runs-on: windows-latest
|
|
108
|
+
strategy:
|
|
109
|
+
matrix:
|
|
110
|
+
pyversion:
|
|
111
|
+
[
|
|
112
|
+
'310',
|
|
113
|
+
'311',
|
|
114
|
+
'312',
|
|
115
|
+
'313',
|
|
116
|
+
'314',
|
|
117
|
+
'315',
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
steps:
|
|
121
|
+
- uses: actions/checkout@v5
|
|
122
|
+
|
|
123
|
+
- uses: MinoruSekine/setup-scoop@v4.0.2
|
|
124
|
+
with:
|
|
125
|
+
buckets: versions
|
|
126
|
+
apps: uv python${{ matrix.pyversion }}
|
|
127
|
+
|
|
128
|
+
- name: Build wheels
|
|
129
|
+
run: |
|
|
130
|
+
scoop reset python${{ matrix.pyversion }}
|
|
131
|
+
uv build
|
|
132
|
+
|
|
133
|
+
- uses: actions/upload-artifact@v4
|
|
134
|
+
with:
|
|
135
|
+
name: win32-wheels-${{ matrix.pyversion }}-${{ strategy.job-index }}
|
|
136
|
+
path: dist/*.whl
|
|
137
|
+
|
|
138
|
+
pypi-publish:
|
|
139
|
+
runs-on: ubuntu-latest
|
|
140
|
+
needs:
|
|
141
|
+
- build_sdist
|
|
142
|
+
- build_wheels
|
|
143
|
+
- build_wheels_macos
|
|
144
|
+
- build_wheels_win32
|
|
145
|
+
permissions:
|
|
146
|
+
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
147
|
+
id-token: write
|
|
148
|
+
|
|
149
|
+
# Dedicated environments with protections for publishing are strongly recommended.
|
|
150
|
+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
|
|
151
|
+
environment:
|
|
152
|
+
name: pypi
|
|
153
|
+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
|
|
154
|
+
# url: https://pypi.org/p/YOURPROJECT
|
|
155
|
+
#
|
|
156
|
+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
|
|
157
|
+
# ALTERNATIVE: exactly, uncomment the following line instead:
|
|
158
|
+
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
|
|
159
|
+
|
|
160
|
+
steps:
|
|
161
|
+
- name: Retrieve release distributions
|
|
162
|
+
uses: actions/download-artifact@v4
|
|
163
|
+
with:
|
|
164
|
+
path: dist/
|
|
165
|
+
|
|
166
|
+
- name: Flatten wheels
|
|
167
|
+
run: |
|
|
168
|
+
shopt -s globstar
|
|
169
|
+
cp -n dist/**/*.whl dist/
|
|
170
|
+
cp -n dist/**/*.tar.gz dist/
|
|
171
|
+
rm -rf dist/*/
|
|
172
|
+
|
|
173
|
+
- name: Publish release distributions to PyPI
|
|
174
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
175
|
+
with:
|
|
176
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"configurations": [
|
|
3
|
+
{
|
|
4
|
+
"name": "Linux",
|
|
5
|
+
"includePath": [
|
|
6
|
+
"${workspaceFolder}/**",
|
|
7
|
+
"${workspaceFolder}/lexer/**",
|
|
8
|
+
"${workspaceFolder}/tokenizer/**",
|
|
9
|
+
"/usr/include/python3.12"
|
|
10
|
+
],
|
|
11
|
+
"defines": [],
|
|
12
|
+
"compilerPath": "/usr/bin/gcc",
|
|
13
|
+
"cStandard": "c17",
|
|
14
|
+
"cppStandard": "gnu++17",
|
|
15
|
+
"intelliSenseMode": "linux-gcc-x64"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"version": 4
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"tasks": [
|
|
4
|
+
{
|
|
5
|
+
"label": "uv build",
|
|
6
|
+
"type": "shell",
|
|
7
|
+
"command": "uv",
|
|
8
|
+
"args": ["build"],
|
|
9
|
+
"problemMatcher": []
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"label": "uv sync",
|
|
13
|
+
"type": "shell",
|
|
14
|
+
"command": "uv",
|
|
15
|
+
"args": ["sync"],
|
|
16
|
+
"problemMatcher": [],
|
|
17
|
+
"dependsOn": ["uv build"]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.15...3.26)
|
|
2
|
+
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
|
|
3
|
+
|
|
4
|
+
find_package(
|
|
5
|
+
Python
|
|
6
|
+
COMPONENTS Development.Module
|
|
7
|
+
REQUIRED)
|
|
8
|
+
|
|
9
|
+
python_add_library(
|
|
10
|
+
_tokenize MODULE
|
|
11
|
+
src/phy_std_base_tokenzier/_tokenize/_tokenize_module.c
|
|
12
|
+
src/phy_std_base_tokenzier/_tokenize/_tokenize.c
|
|
13
|
+
src/phy_std_base_tokenzier/_tokenize/lexer/buffer.c
|
|
14
|
+
src/phy_std_base_tokenzier/_tokenize/lexer/lexer.c
|
|
15
|
+
src/phy_std_base_tokenzier/_tokenize/lexer/state.c
|
|
16
|
+
src/phy_std_base_tokenzier/_tokenize/tokenizer/helpers.c
|
|
17
|
+
src/phy_std_base_tokenzier/_tokenize/tokenizer/readline_tokenizer.c
|
|
18
|
+
src/phy_std_base_tokenzier/_tokenize/tokenizer/string_tokenizer.c
|
|
19
|
+
src/phy_std_base_tokenzier/_tokenize/tokenizer/utf8_tokenizer.c
|
|
20
|
+
WITH_SOABI
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
install(TARGETS _tokenize DESTINATION phy_std_base_tokenzier)
|
|
24
|
+
install(
|
|
25
|
+
FILES src/phy_std_base_tokenzier/__init__.py
|
|
26
|
+
src/phy_std_base_tokenzier/_tokenize.pyi
|
|
27
|
+
src/phy_std_base_tokenzier/_token_type.py
|
|
28
|
+
src/phy_std_base_tokenzier/_phy_compat.py
|
|
29
|
+
src/phy_std_base_tokenzier/compat.py
|
|
30
|
+
DESTINATION phy_std_base_tokenzier
|
|
31
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 PHY PROJECT
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: phy-std-base-tokenizer
|
|
3
|
+
Version: 0.1.0rc1
|
|
4
|
+
Summary: Base tokenizer for phy project extracted from python 3.14 builtin tokenize module
|
|
5
|
+
Author-Email: alfred-du <ihearmywords@hotmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
14
|
+
Project-URL: Homepage, https://github.com/phy-precompiler/std-base-tokenizer
|
|
15
|
+
Project-URL: Repository, https://github.com/phy-precompiler/std-base-tokenizer
|
|
16
|
+
Project-URL: Issues, https://github.com/phy-precompiler/std-base-tokenizer/issues
|
|
17
|
+
Requires-Python: <4,>=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Consistent Tokenizer Across Python Versions
|
|
21
|
+
|
|
22
|
+
<p align="left">
|
|
23
|
+
<a href="#"><img alt="PyPI" src="https://img.shields.io/pypi/v/phy-std-base-tokenizer.svg"></a>
|
|
24
|
+
<a href="#"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/phy-std-base-tokenizer.svg"></a>
|
|
25
|
+
<a href="#"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
This project is part of [`phy`](https://github.com/phy-precompiler).
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+
|
|
32
|
+
This package provides a replacement for Python builtin `tokenize` module and behaves consistently across active python versions.
|
|
33
|
+
|
|
34
|
+
The differences of builtin `tokenize` module among versions includes:
|
|
35
|
+
|
|
36
|
+
- Since Python 3.12, new fstring related token types `FSTRING_START`, `FSTRING_MIDDLE` & `FSTRING_END` were introduced for [PEP 701](https://peps.python.org/pep-0701/), along with notable performance enhancements.
|
|
37
|
+
|
|
38
|
+
- Python 3.14 brings new token types `TSTRING_START`, `TSTRING_MIDDLE` & `TSTRING_END` for new syntax [Template String](https://peps.python.org/pep-0750/).
|
|
39
|
+
|
|
40
|
+
- Python's built-in [`token`](https://docs.python.org/3/library/token.html) module assigns an **integer value** to each token type. However, these numeric values are **not guaranteed to be stable** across Python versions:
|
|
41
|
+
|
|
42
|
+
| token type | python 3.10 | python 3.11 | python 3.12 | python 3.13 | python 3.14+ |
|
|
43
|
+
|------------------|-------------|-------------|-------------|-------------|--------------|
|
|
44
|
+
| ENDMARKER | 0 | 0 | 0 | 0 | 0 |
|
|
45
|
+
| NAME | 1 | 1 | 1 | 1 | 1 |
|
|
46
|
+
| NUMBER | 2 | 2 | 2 | 2 | 2 |
|
|
47
|
+
| STRING | 3 | 3 | 3 | 3 | 3 |
|
|
48
|
+
| NEWLINE | 4 | 4 | 4 | 4 | 4 |
|
|
49
|
+
| INDENT | 5 | 5 | 5 | 5 | 5 |
|
|
50
|
+
| DEDENT | 6 | 6 | 6 | 6 | 6 |
|
|
51
|
+
| LPAR | 7 | 7 | 7 | 7 | 7 |
|
|
52
|
+
| RPAR | 8 | 8 | 8 | 8 | 8 |
|
|
53
|
+
| LSQB | 9 | 9 | 9 | 9 | 9 |
|
|
54
|
+
| RSQB | 10 | 10 | 10 | 10 | 10 |
|
|
55
|
+
| COLON | 11 | 11 | 11 | 11 | 11 |
|
|
56
|
+
| COMMA | 12 | 12 | 12 | 12 | 12 |
|
|
57
|
+
| SEMI | 13 | 13 | 13 | 13 | 13 |
|
|
58
|
+
| PLUS | 14 | 14 | 14 | 14 | 14 |
|
|
59
|
+
| MINUS | 15 | 15 | 15 | 15 | 15 |
|
|
60
|
+
| STAR | 16 | 16 | 16 | 16 | 16 |
|
|
61
|
+
| SLASH | 17 | 17 | 17 | 17 | 17 |
|
|
62
|
+
| VBAR | 18 | 18 | 18 | 18 | 18 |
|
|
63
|
+
| AMPER | 19 | 19 | 19 | 19 | 19 |
|
|
64
|
+
| LESS | 20 | 20 | 20 | 20 | 20 |
|
|
65
|
+
| GREATER | 21 | 21 | 21 | 21 | 21 |
|
|
66
|
+
| EQUAL | 22 | 22 | 22 | 22 | 22 |
|
|
67
|
+
| DOT | 23 | 23 | 23 | 23 | 23 |
|
|
68
|
+
| PERCENT | 24 | 24 | 24 | 24 | 24 |
|
|
69
|
+
| LBRACE | 25 | 25 | 25 | 25 | 25 |
|
|
70
|
+
| RBRACE | 26 | 26 | 26 | 26 | 26 |
|
|
71
|
+
| EQEQUAL | 27 | 27 | 27 | 27 | 27 |
|
|
72
|
+
| NOTEQUAL | 28 | 28 | 28 | 28 | 28 |
|
|
73
|
+
| LESSEQUAL | 29 | 29 | 29 | 29 | 29 |
|
|
74
|
+
| GREATEREQUAL | 30 | 30 | 30 | 30 | 30 |
|
|
75
|
+
| TILDE | 31 | 31 | 31 | 31 | 31 |
|
|
76
|
+
| CIRCUMFLEX | 32 | 32 | 32 | 32 | 32 |
|
|
77
|
+
| LEFTSHIFT | 33 | 33 | 33 | 33 | 33 |
|
|
78
|
+
| RIGHTSHIFT | 34 | 34 | 34 | 34 | 34 |
|
|
79
|
+
| DOUBLESTAR | 35 | 35 | 35 | 35 | 35 |
|
|
80
|
+
| PLUSEQUAL | 36 | 36 | 36 | 36 | 36 |
|
|
81
|
+
| MINEQUAL | 37 | 37 | 37 | 37 | 37 |
|
|
82
|
+
| STAREQUAL | 38 | 38 | 38 | 38 | 38 |
|
|
83
|
+
| SLASHEQUAL | 39 | 39 | 39 | 39 | 39 |
|
|
84
|
+
| PERCENTEQUAL | 40 | 40 | 40 | 40 | 40 |
|
|
85
|
+
| AMPEREQUAL | 41 | 41 | 41 | 41 | 41 |
|
|
86
|
+
| VBAREQUAL | 42 | 42 | 42 | 42 | 42 |
|
|
87
|
+
| CIRCUMFLEXEQUAL | 43 | 43 | 43 | 43 | 43 |
|
|
88
|
+
| LEFTSHIFTEQUAL | 44 | 44 | 44 | 44 | 44 |
|
|
89
|
+
| RIGHTSHIFTEQUAL | 45 | 45 | 45 | 45 | 45 |
|
|
90
|
+
| DOUBLESTAREQUAL | 46 | 46 | 46 | 46 | 46 |
|
|
91
|
+
| DOUBLESLASH | 47 | 47 | 47 | 47 | 47 |
|
|
92
|
+
| DOUBLESLASHEQUAL | 48 | 48 | 48 | 48 | 48 |
|
|
93
|
+
| AT | 49 | 49 | 49 | 49 | 49 |
|
|
94
|
+
| ATEQUAL | 50 | 50 | 50 | 50 | 50 |
|
|
95
|
+
| RARROW | 51 | 51 | 51 | 51 | 51 |
|
|
96
|
+
| ELLIPSIS | 52 | 52 | 52 | 52 | 52 |
|
|
97
|
+
| COLONEQUAL | 53 | 53 | 53 | 53 | 53 |
|
|
98
|
+
| EXCLAMATION | | | 54 | 54 | 54 |
|
|
99
|
+
| OP | 54 | 54 | 55 | 55 | 55 |
|
|
100
|
+
| AWAIT | 55 | 55 | 56 | | |
|
|
101
|
+
| ASYNC | 56 | 56 | 57 | | |
|
|
102
|
+
| TYPE_IGNORE | 57 | 57 | 58 | 56 | 56 |
|
|
103
|
+
| TYPE_COMMENT | 58 | 58 | 59 | 57 | 57 |
|
|
104
|
+
| SOFT_KEYWORD | 59 | 59 | 60 | 58 | 58 |
|
|
105
|
+
| FSTRING_START | | | 61 | 59 | 59 |
|
|
106
|
+
| FSTRING_MIDDLE | | | 62 | 60 | 60 |
|
|
107
|
+
| FSTRING_END | | | 63 | 61 | 61 |
|
|
108
|
+
| TSTRING_START | | | | | 62 |
|
|
109
|
+
| TSTRING_MIDDLE | | | | | 63 |
|
|
110
|
+
| TSTRING_END | | | | | 64 |
|
|
111
|
+
| COMMENT | 61 | 61 | 64 | 62 | 65 |
|
|
112
|
+
| NL | 62 | 62 | 65 | 63 | 66 |
|
|
113
|
+
| ERRORTOKEN | 60 | 60 | 66 | 64 | 67 |
|
|
114
|
+
| N_TOKENS | 64 | 64 | 68 | 66 | 69 |
|
|
115
|
+
| NT_OFFSET | 256 | 256 | 256 | 256 | 256 |
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
This may lead to necessary extra works about token codes alignment if your project relies on consistent numeric token codes across environments.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## What this Project Does
|
|
123
|
+
|
|
124
|
+
This repository extracts the c code related to `lexer` & `tokenize` from CPython 3.15 source code (the latest Python version), and build a standalone python package with the same Python API as built-in `tokenize` module.
|
|
125
|
+
|
|
126
|
+
Use this package to tokenize python codes will produce the same results, regardless of which version of python interpreter is used.
|
|
127
|
+
|
|
128
|
+
This package has **ZERO** dependencies.
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## Installation
|
|
132
|
+
|
|
133
|
+
```shell
|
|
134
|
+
pip install phy-std-base-tokenizer
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
If theres is issue in installing on Windows, refer to [build-on-windows](#build-on-windows) to built it by ones own.
|
|
138
|
+
|
|
139
|
+
## How to use
|
|
140
|
+
|
|
141
|
+
Use this library like builtin `tokenize` module:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from io import BytesIO, StringIO
|
|
145
|
+
import phy_std_base_tokenzier
|
|
146
|
+
|
|
147
|
+
code = '''print(f"hello world to {greeter}!")\ntemplate=t"input a {name}"\n'''
|
|
148
|
+
code_str_readline = StringIO(code).readline
|
|
149
|
+
|
|
150
|
+
for _token in phy_std_base_tokenzier.generate_toks(code_str_readline):
|
|
151
|
+
print(_token)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The generated token is instance of `phy_core.TokInfo`.
|
|
155
|
+
|
|
156
|
+
## Build
|
|
157
|
+
|
|
158
|
+
This library use [`scikit-build-core`](https://github.com/scikit-build/scikit-build-core) and
|
|
159
|
+
[`uv`](https://github.com/astral-sh/uv) to build; `cmake` is a dependency of `scikit-build-core`.
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
uv build
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### build on Windows
|
|
166
|
+
|
|
167
|
+
If you use `visual c++` as compiler to build this package, to avoid error "The C compiler identification is unknown", it is better to use `Command Prompt for VS` app to execute the build command.
|
|
168
|
+
|
|
169
|
+
If error "The C compiler identification is unknown. CMAKE_C_COMPILER could be found" encountered but you have Visual C++ installed, try to install the component `Desktop development with C++`.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Consistent Tokenizer Across Python Versions
|
|
2
|
+
|
|
3
|
+
<p align="left">
|
|
4
|
+
<a href="#"><img alt="PyPI" src="https://img.shields.io/pypi/v/phy-std-base-tokenizer.svg"></a>
|
|
5
|
+
<a href="#"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/phy-std-base-tokenizer.svg"></a>
|
|
6
|
+
<a href="#"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
This project is part of [`phy`](https://github.com/phy-precompiler).
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This package provides a replacement for Python builtin `tokenize` module and behaves consistently across active python versions.
|
|
14
|
+
|
|
15
|
+
The differences of builtin `tokenize` module among versions includes:
|
|
16
|
+
|
|
17
|
+
- Since Python 3.12, new fstring related token types `FSTRING_START`, `FSTRING_MIDDLE` & `FSTRING_END` were introduced for [PEP 701](https://peps.python.org/pep-0701/), along with notable performance enhancements.
|
|
18
|
+
|
|
19
|
+
- Python 3.14 brings new token types `TSTRING_START`, `TSTRING_MIDDLE` & `TSTRING_END` for new syntax [Template String](https://peps.python.org/pep-0750/).
|
|
20
|
+
|
|
21
|
+
- Python's built-in [`token`](https://docs.python.org/3/library/token.html) module assigns an **integer value** to each token type. However, these numeric values are **not guaranteed to be stable** across Python versions:
|
|
22
|
+
|
|
23
|
+
| token type | python 3.10 | python 3.11 | python 3.12 | python 3.13 | python 3.14+ |
|
|
24
|
+
|------------------|-------------|-------------|-------------|-------------|--------------|
|
|
25
|
+
| ENDMARKER | 0 | 0 | 0 | 0 | 0 |
|
|
26
|
+
| NAME | 1 | 1 | 1 | 1 | 1 |
|
|
27
|
+
| NUMBER | 2 | 2 | 2 | 2 | 2 |
|
|
28
|
+
| STRING | 3 | 3 | 3 | 3 | 3 |
|
|
29
|
+
| NEWLINE | 4 | 4 | 4 | 4 | 4 |
|
|
30
|
+
| INDENT | 5 | 5 | 5 | 5 | 5 |
|
|
31
|
+
| DEDENT | 6 | 6 | 6 | 6 | 6 |
|
|
32
|
+
| LPAR | 7 | 7 | 7 | 7 | 7 |
|
|
33
|
+
| RPAR | 8 | 8 | 8 | 8 | 8 |
|
|
34
|
+
| LSQB | 9 | 9 | 9 | 9 | 9 |
|
|
35
|
+
| RSQB | 10 | 10 | 10 | 10 | 10 |
|
|
36
|
+
| COLON | 11 | 11 | 11 | 11 | 11 |
|
|
37
|
+
| COMMA | 12 | 12 | 12 | 12 | 12 |
|
|
38
|
+
| SEMI | 13 | 13 | 13 | 13 | 13 |
|
|
39
|
+
| PLUS | 14 | 14 | 14 | 14 | 14 |
|
|
40
|
+
| MINUS | 15 | 15 | 15 | 15 | 15 |
|
|
41
|
+
| STAR | 16 | 16 | 16 | 16 | 16 |
|
|
42
|
+
| SLASH | 17 | 17 | 17 | 17 | 17 |
|
|
43
|
+
| VBAR | 18 | 18 | 18 | 18 | 18 |
|
|
44
|
+
| AMPER | 19 | 19 | 19 | 19 | 19 |
|
|
45
|
+
| LESS | 20 | 20 | 20 | 20 | 20 |
|
|
46
|
+
| GREATER | 21 | 21 | 21 | 21 | 21 |
|
|
47
|
+
| EQUAL | 22 | 22 | 22 | 22 | 22 |
|
|
48
|
+
| DOT | 23 | 23 | 23 | 23 | 23 |
|
|
49
|
+
| PERCENT | 24 | 24 | 24 | 24 | 24 |
|
|
50
|
+
| LBRACE | 25 | 25 | 25 | 25 | 25 |
|
|
51
|
+
| RBRACE | 26 | 26 | 26 | 26 | 26 |
|
|
52
|
+
| EQEQUAL | 27 | 27 | 27 | 27 | 27 |
|
|
53
|
+
| NOTEQUAL | 28 | 28 | 28 | 28 | 28 |
|
|
54
|
+
| LESSEQUAL | 29 | 29 | 29 | 29 | 29 |
|
|
55
|
+
| GREATEREQUAL | 30 | 30 | 30 | 30 | 30 |
|
|
56
|
+
| TILDE | 31 | 31 | 31 | 31 | 31 |
|
|
57
|
+
| CIRCUMFLEX | 32 | 32 | 32 | 32 | 32 |
|
|
58
|
+
| LEFTSHIFT | 33 | 33 | 33 | 33 | 33 |
|
|
59
|
+
| RIGHTSHIFT | 34 | 34 | 34 | 34 | 34 |
|
|
60
|
+
| DOUBLESTAR | 35 | 35 | 35 | 35 | 35 |
|
|
61
|
+
| PLUSEQUAL | 36 | 36 | 36 | 36 | 36 |
|
|
62
|
+
| MINEQUAL | 37 | 37 | 37 | 37 | 37 |
|
|
63
|
+
| STAREQUAL | 38 | 38 | 38 | 38 | 38 |
|
|
64
|
+
| SLASHEQUAL | 39 | 39 | 39 | 39 | 39 |
|
|
65
|
+
| PERCENTEQUAL | 40 | 40 | 40 | 40 | 40 |
|
|
66
|
+
| AMPEREQUAL | 41 | 41 | 41 | 41 | 41 |
|
|
67
|
+
| VBAREQUAL | 42 | 42 | 42 | 42 | 42 |
|
|
68
|
+
| CIRCUMFLEXEQUAL | 43 | 43 | 43 | 43 | 43 |
|
|
69
|
+
| LEFTSHIFTEQUAL | 44 | 44 | 44 | 44 | 44 |
|
|
70
|
+
| RIGHTSHIFTEQUAL | 45 | 45 | 45 | 45 | 45 |
|
|
71
|
+
| DOUBLESTAREQUAL | 46 | 46 | 46 | 46 | 46 |
|
|
72
|
+
| DOUBLESLASH | 47 | 47 | 47 | 47 | 47 |
|
|
73
|
+
| DOUBLESLASHEQUAL | 48 | 48 | 48 | 48 | 48 |
|
|
74
|
+
| AT | 49 | 49 | 49 | 49 | 49 |
|
|
75
|
+
| ATEQUAL | 50 | 50 | 50 | 50 | 50 |
|
|
76
|
+
| RARROW | 51 | 51 | 51 | 51 | 51 |
|
|
77
|
+
| ELLIPSIS | 52 | 52 | 52 | 52 | 52 |
|
|
78
|
+
| COLONEQUAL | 53 | 53 | 53 | 53 | 53 |
|
|
79
|
+
| EXCLAMATION | | | 54 | 54 | 54 |
|
|
80
|
+
| OP | 54 | 54 | 55 | 55 | 55 |
|
|
81
|
+
| AWAIT | 55 | 55 | 56 | | |
|
|
82
|
+
| ASYNC | 56 | 56 | 57 | | |
|
|
83
|
+
| TYPE_IGNORE | 57 | 57 | 58 | 56 | 56 |
|
|
84
|
+
| TYPE_COMMENT | 58 | 58 | 59 | 57 | 57 |
|
|
85
|
+
| SOFT_KEYWORD | 59 | 59 | 60 | 58 | 58 |
|
|
86
|
+
| FSTRING_START | | | 61 | 59 | 59 |
|
|
87
|
+
| FSTRING_MIDDLE | | | 62 | 60 | 60 |
|
|
88
|
+
| FSTRING_END | | | 63 | 61 | 61 |
|
|
89
|
+
| TSTRING_START | | | | | 62 |
|
|
90
|
+
| TSTRING_MIDDLE | | | | | 63 |
|
|
91
|
+
| TSTRING_END | | | | | 64 |
|
|
92
|
+
| COMMENT | 61 | 61 | 64 | 62 | 65 |
|
|
93
|
+
| NL | 62 | 62 | 65 | 63 | 66 |
|
|
94
|
+
| ERRORTOKEN | 60 | 60 | 66 | 64 | 67 |
|
|
95
|
+
| N_TOKENS | 64 | 64 | 68 | 66 | 69 |
|
|
96
|
+
| NT_OFFSET | 256 | 256 | 256 | 256 | 256 |
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
This may lead to necessary extra works about token codes alignment if your project relies on consistent numeric token codes across environments.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## What this Project Does
|
|
104
|
+
|
|
105
|
+
This repository extracts the c code related to `lexer` & `tokenize` from CPython 3.15 source code (the latest Python version), and build a standalone python package with the same Python API as built-in `tokenize` module.
|
|
106
|
+
|
|
107
|
+
Use this package to tokenize python codes will produce the same results, regardless of which version of python interpreter is used.
|
|
108
|
+
|
|
109
|
+
This package has **ZERO** dependencies.
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## Installation
|
|
113
|
+
|
|
114
|
+
```shell
|
|
115
|
+
pip install phy-std-base-tokenizer
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
If theres is issue in installing on Windows, refer to [build-on-windows](#build-on-windows) to built it by ones own.
|
|
119
|
+
|
|
120
|
+
## How to use
|
|
121
|
+
|
|
122
|
+
Use this library like builtin `tokenize` module:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from io import BytesIO, StringIO
|
|
126
|
+
import phy_std_base_tokenzier
|
|
127
|
+
|
|
128
|
+
code = '''print(f"hello world to {greeter}!")\ntemplate=t"input a {name}"\n'''
|
|
129
|
+
code_str_readline = StringIO(code).readline
|
|
130
|
+
|
|
131
|
+
for _token in phy_std_base_tokenzier.generate_toks(code_str_readline):
|
|
132
|
+
print(_token)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The generated token is instance of `phy_core.TokInfo`.
|
|
136
|
+
|
|
137
|
+
## Build
|
|
138
|
+
|
|
139
|
+
This library use [`scikit-build-core`](https://github.com/scikit-build/scikit-build-core) and
|
|
140
|
+
[`uv`](https://github.com/astral-sh/uv) to build; `cmake` is a dependency of `scikit-build-core`.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
uv build
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### build on Windows
|
|
147
|
+
|
|
148
|
+
If you use `visual c++` as compiler to build this package, to avoid error "The C compiler identification is unknown", it is better to use `Command Prompt for VS` app to execute the build command.
|
|
149
|
+
|
|
150
|
+
If error "The C compiler identification is unknown. CMAKE_C_COMPILER could be found" encountered but you have Visual C++ installed, try to install the component `Desktop development with C++`.
|