sctokenizer
A Source Code Tokenizer
Supports those languages: C, C++, Java, Python, PHP
How to install
pip install sctokenizer
How to use
Use sctokenizer:
import sctokenizer
tokens = sctokenizer.tokenize_file(filepath='tests/data/hello_world.cpp', lang='cpp')
for token in tokens:
print(token)
Or create new CppTokenizer:
from sctokenizer import CppTokenizer
tokenizer = CppTokenizer() # this object can be used for multiple source files
with open('tests/data/hello_world.cpp') as f:
source = f.read()
tokens = tokenizer.tokenize(source)
for token in tokens:
print(token)
Or better solution:
from sctokenizer import Source
src = Source.from_file('tests/data/hello_world.cpp', lang='cpp')
tokens = src.tokenize()
for token in tokens:
print(token)
Result is a list of Token. Each Token has four attributes including token_value, token_type, line, column:
(#, TokenType.SPECIAL_SYMBOL, (1, 1))
(include, TokenType.KEYWORD, (1, 2))
(<, TokenType.OPERATOR, (1, 10))
(bits/stdc++.h, TokenType.IDENTIFIER, (1, 11))
(>, TokenType.OPERATOR, (1, 24))
(using, TokenType.KEYWORD, (3, 1))
(namespace, TokenType.KEYWORD, (3, 7))
(std, TokenType.IDENTIFIER, (3, 17))
(;, TokenType.SPECIAL_SYMBOL, (3, 20))
(int, TokenType.KEYWORD, (5, 1))
(main, TokenType.IDENTIFIER, (5, 5))
((, TokenType.SPECIAL_SYMBOL, (5, 9))
(), TokenType.SPECIAL_SYMBOL, (5, 10))
({, TokenType.SPECIAL_SYMBOL, (6, 1))
(cout, TokenType.IDENTIFIER, (7, 5))
(<<, TokenType.OPERATOR, (7, 11))
(", TokenType.SPECIAL_SYMBOL, (7, 13))
(Hello World, TokenType.STRING, (7, 14))
(", TokenType.SPECIAL_SYMBOL, (7, 25))
(;, TokenType.SPECIAL_SYMBOL, (7, 26))
(return, TokenType.KEYWORD, (8, 5))
(0, TokenType.CONSTANT, (8, 12))
(;, TokenType.SPECIAL_SYMBOL, (8, 13))
(}, TokenType.SPECIAL_SYMBOL, (9, 1))
TODO
- Support other languages:
Matlab, Javascript, Typescript,... - Auto detect language
- Parse source to a tree of tokens???
Metadata
Release files for sctokenizer 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sctokenizer-0.0.8.tar.gz | 9.6 kB | Without provenance | Details for sctokenizer-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sctokenizer-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for sctokenizer-0.0.8-py3-none-any.whl |
Total release size: 26.3 kB
Release files / sctokenizer-0.0.8.tar.gz
| Download URL | sctokenizer-0.0.8.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dca1b8fdb4ed60e7f1248adc053fa75995389ab1d329e69e2cb4de53b2f751ee
|
|
BLAKE2b-256 checksum How to use checksums |
c82ae76fa238474952176ed232bbb3e17a093f594a5db1da13fba1d6287bd7a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / sctokenizer-0.0.8-py3-none-any.whl
| Download URL | sctokenizer-0.0.8-py3-none-any.whl |
|---|---|
| Size | 16.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bab9c1829fc39b9b81b3b54ee179d50f04861c6aafbd27bbcfbfdbf3c7f2c553
|
|
BLAKE2b-256 checksum How to use checksums |
64c24701f2a04c6025cd0b401380c1c9af4c55a1cf6a5ca413a08f97462a0247
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for sctokenizer 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.