bashe 0.1.1__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.
bashe-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ssrtw
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.
bashe-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.4
2
+ Name: bashe
3
+ Version: 0.1.1
4
+ Summary: A Tree-sitter based PHP parser for Python, featuring compatibility with phply.
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: tree-sitter>=0.25.2
9
+ Requires-Dist: tree-sitter-php>=0.24.1
10
+ Provides-Extra: phply
11
+ Requires-Dist: phply>=1.2.6; extra == "phply"
12
+ Dynamic: license-file
13
+
14
+ # Bashe
15
+
16
+ <p align="center">
17
+ <img src="assets/logo.png" alt="Bashe logo" width="256">
18
+ </p>
19
+
20
+ [![GitHub release](https://img.shields.io/github/release/ssrtw/bashe/all.svg)](https://github.com/ssrtw/bashe/releases)
21
+ [![license](https://img.shields.io/github/license/ssrtw/bashe.svg)](./LICENSE)
22
+ ![python version badge](https://img.shields.io/badge/language-python3.10-orange.svg)
23
+
24
+ Bashe (巴蛇, pronounced like "parser") is a fast, tree-sitter based PHP
25
+ parser for Python, with optional phply-compatible AST output. The name
26
+ comes from the legendary giant snake in Chinese mythology.
27
+
28
+ ## Features
29
+
30
+ - Parses PHP source into a structured AST using tree-sitter
31
+ - Supports PHP 7 features: scalar types, return type declarations,
32
+ null coalescing (`??`), spaceship operator (`<=>`)
33
+ - Supports PHP 8 features: constructor property promotion, named
34
+ arguments, nullsafe operator (`?->`), match expressions, union types
35
+ - Optional `phply.phpparse`-compatible output — just `pip install bashe[phply]`
36
+ - Minimal dependencies when phply is not needed
37
+
38
+ ## Installation
39
+
40
+ Python 3.10+ is supported; 3.13+ (with [uv](https://docs.astral.sh/uv/)) is
41
+ recommended for the best experience.
42
+
43
+ ```bash
44
+ # Core parser only (tree-sitter + tree-sitter-php)
45
+ uv pip install bashe
46
+
47
+ # With phply compatibility layer
48
+ uv pip install bashe[phply]
49
+ ```
50
+
51
+ ## Quick Start
52
+
53
+ ```python
54
+ from bashe import Bashe
55
+
56
+ parser = Bashe()
57
+ ast = parser.parse('<?php echo "hello, world!"; ?>')
58
+ print(ast)
59
+ ```
60
+
61
+ For phply-compatible AST nodes (`phpast.Variable`, `phpast.FunctionCall`, etc.):
62
+
63
+ ```bash
64
+ uv pip install bashe[phply]
65
+ ```
66
+
67
+ ```python
68
+ from bashe import Bashe
69
+
70
+ parser = Bashe()
71
+ nodes = parser.parse(
72
+ '<?php namespace Foo; class Bar { function baz() { echo __METHOD__; } } ?>',
73
+ filename="/path/to/file.php",
74
+ )
75
+ # All magic constants (__FILE__, __DIR__, __NAMESPACE__, __CLASS__,
76
+ # __FUNCTION__, __METHOD__, __TRAIT__) are resolved at parse time —
77
+ # no need for resolve_magic_constants().
78
+ ```
79
+
80
+ ## Performance
81
+
82
+ Bashe is approximately **2× faster** than phply's lexer-based parser on
83
+ equivalent inputs.
84
+
85
+ | Parser | 3.10 (10k) | Ratio (3.10) | 3.13 (10k) | Ratio (3.13) |
86
+ | ------ | ---------- | ------------ | ---------- | ------------ |
87
+ | bashe | 2.46s | 1.00× | 1.73s | 1.00× |
88
+ | phply | 5.76s | 2.34× | 3.66s | 2.12× |
89
+
90
+ \_Benchmark: parsing `bench.php` (multi-line PHP with includes, evals,
91
+ function definitions) 10,000 times on CPython 3.10 and 3.13
92
+
93
+ ## Development
94
+
95
+ ```bash
96
+ # Install dev dependencies (pytest, ipykernel, phply)
97
+ uv pip install -e ".[dev]"
98
+
99
+ # Run tests
100
+ uv run pytest
101
+ ```
102
+
103
+ ## License
104
+
105
+ MIT — see [LICENSE](./LICENSE).
bashe-0.1.1/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Bashe
2
+
3
+ <p align="center">
4
+ <img src="assets/logo.png" alt="Bashe logo" width="256">
5
+ </p>
6
+
7
+ [![GitHub release](https://img.shields.io/github/release/ssrtw/bashe/all.svg)](https://github.com/ssrtw/bashe/releases)
8
+ [![license](https://img.shields.io/github/license/ssrtw/bashe.svg)](./LICENSE)
9
+ ![python version badge](https://img.shields.io/badge/language-python3.10-orange.svg)
10
+
11
+ Bashe (巴蛇, pronounced like "parser") is a fast, tree-sitter based PHP
12
+ parser for Python, with optional phply-compatible AST output. The name
13
+ comes from the legendary giant snake in Chinese mythology.
14
+
15
+ ## Features
16
+
17
+ - Parses PHP source into a structured AST using tree-sitter
18
+ - Supports PHP 7 features: scalar types, return type declarations,
19
+ null coalescing (`??`), spaceship operator (`<=>`)
20
+ - Supports PHP 8 features: constructor property promotion, named
21
+ arguments, nullsafe operator (`?->`), match expressions, union types
22
+ - Optional `phply.phpparse`-compatible output — just `pip install bashe[phply]`
23
+ - Minimal dependencies when phply is not needed
24
+
25
+ ## Installation
26
+
27
+ Python 3.10+ is supported; 3.13+ (with [uv](https://docs.astral.sh/uv/)) is
28
+ recommended for the best experience.
29
+
30
+ ```bash
31
+ # Core parser only (tree-sitter + tree-sitter-php)
32
+ uv pip install bashe
33
+
34
+ # With phply compatibility layer
35
+ uv pip install bashe[phply]
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ```python
41
+ from bashe import Bashe
42
+
43
+ parser = Bashe()
44
+ ast = parser.parse('<?php echo "hello, world!"; ?>')
45
+ print(ast)
46
+ ```
47
+
48
+ For phply-compatible AST nodes (`phpast.Variable`, `phpast.FunctionCall`, etc.):
49
+
50
+ ```bash
51
+ uv pip install bashe[phply]
52
+ ```
53
+
54
+ ```python
55
+ from bashe import Bashe
56
+
57
+ parser = Bashe()
58
+ nodes = parser.parse(
59
+ '<?php namespace Foo; class Bar { function baz() { echo __METHOD__; } } ?>',
60
+ filename="/path/to/file.php",
61
+ )
62
+ # All magic constants (__FILE__, __DIR__, __NAMESPACE__, __CLASS__,
63
+ # __FUNCTION__, __METHOD__, __TRAIT__) are resolved at parse time —
64
+ # no need for resolve_magic_constants().
65
+ ```
66
+
67
+ ## Performance
68
+
69
+ Bashe is approximately **2× faster** than phply's lexer-based parser on
70
+ equivalent inputs.
71
+
72
+ | Parser | 3.10 (10k) | Ratio (3.10) | 3.13 (10k) | Ratio (3.13) |
73
+ | ------ | ---------- | ------------ | ---------- | ------------ |
74
+ | bashe | 2.46s | 1.00× | 1.73s | 1.00× |
75
+ | phply | 5.76s | 2.34× | 3.66s | 2.12× |
76
+
77
+ \_Benchmark: parsing `bench.php` (multi-line PHP with includes, evals,
78
+ function definitions) 10,000 times on CPython 3.10 and 3.13
79
+
80
+ ## Development
81
+
82
+ ```bash
83
+ # Install dev dependencies (pytest, ipykernel, phply)
84
+ uv pip install -e ".[dev]"
85
+
86
+ # Run tests
87
+ uv run pytest
88
+ ```
89
+
90
+ ## License
91
+
92
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,3 @@
1
+ from .parser import Bashe, php
2
+
3
+ __all__ = ["Bashe", "php"]