tree-sitter-hbk 0.1.8__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.
- tree_sitter_hbk-0.1.8/LICENSE +21 -0
- tree_sitter_hbk-0.1.8/MANIFEST.in +3 -0
- tree_sitter_hbk-0.1.8/PKG-INFO +222 -0
- tree_sitter_hbk-0.1.8/README.md +203 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk/__init__.py +12 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk/__init__.pyi +6 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk/binding.c +28 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk/py.typed +0 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk.egg-info/PKG-INFO +222 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk.egg-info/SOURCES.txt +25 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk.egg-info/dependency_links.txt +1 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk.egg-info/not-zip-safe +1 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk.egg-info/requires.txt +3 -0
- tree_sitter_hbk-0.1.8/bindings/python/tree_sitter_hbk.egg-info/top_level.txt +2 -0
- tree_sitter_hbk-0.1.8/grammars/bsl/queries/highlights.scm +93 -0
- tree_sitter_hbk-0.1.8/grammars/bsl/queries/injections.scm +8 -0
- tree_sitter_hbk-0.1.8/grammars/bsl/src/parser.c +32756 -0
- tree_sitter_hbk-0.1.8/grammars/bsl/src/tree_sitter/alloc.h +54 -0
- tree_sitter_hbk-0.1.8/grammars/bsl/src/tree_sitter/array.h +291 -0
- tree_sitter_hbk-0.1.8/grammars/bsl/src/tree_sitter/parser.h +286 -0
- tree_sitter_hbk-0.1.8/grammars/sdbl/src/parser.c +77171 -0
- tree_sitter_hbk-0.1.8/grammars/sdbl/src/tree_sitter/alloc.h +54 -0
- tree_sitter_hbk-0.1.8/grammars/sdbl/src/tree_sitter/array.h +291 -0
- tree_sitter_hbk-0.1.8/grammars/sdbl/src/tree_sitter/parser.h +286 -0
- tree_sitter_hbk-0.1.8/pyproject.toml +29 -0
- tree_sitter_hbk-0.1.8/setup.cfg +4 -0
- tree_sitter_hbk-0.1.8/setup.py +70 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Koryakin Aleksey <alkoleft@gmail.com>
|
|
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,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-hbk
|
|
3
|
+
Version: 0.1.8
|
|
4
|
+
Summary: 1C (BSL) language
|
|
5
|
+
Author: Maxon Matvienko
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mussolene/tree-sitter-bsl
|
|
8
|
+
Keywords: incremental,parsing,tree-sitter,bsl
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
11
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: core
|
|
17
|
+
Requires-Dist: tree-sitter~=0.24; extra == "core"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# tree-sitter-hbk
|
|
21
|
+
|
|
22
|
+
[![CI][ci]](https://github.com/mussolene/tree-sitter-bsl/actions/workflows/ci.yml)
|
|
23
|
+
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-hbk)
|
|
24
|
+
[![crates.io][crates]](https://crates.io/crates/tree-sitter-hbk)
|
|
25
|
+
[![PyPI][pypi]](https://pypi.org/project/tree-sitter-hbk/)
|
|
26
|
+
|
|
27
|
+
Грамматика 1C BSL в формате [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
|
28
|
+
Пакет также содержит отдельную грамматику `sdbl` для языка запросов 1C.
|
|
29
|
+
|
|
30
|
+
[Попробовать](https://mussolene.github.io/tree-sitter-bsl/)
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
## Что входит
|
|
35
|
+
|
|
36
|
+
- `bsl`: грамматика исходных файлов BSL (`.bsl`, `.osl`).
|
|
37
|
+
- `sdbl`: грамматика самостоятельных текстов запросов 1C (`.sdbl`).
|
|
38
|
+
- Query-файлы tree-sitter для подсветки BSL/SDBL и внедрения статических
|
|
39
|
+
строковых литералов BSL, начинающихся с `ВЫБРАТЬ`, `SELECT`, `УНИЧТОЖИТЬ`
|
|
40
|
+
или `DROP`, как `sdbl`.
|
|
41
|
+
- Локальное dev-расширение Zed в [`editors/zed-bsl`](editors/zed-bsl) для
|
|
42
|
+
проверки подсветки BSL, самостоятельного SDBL и внедренного SDBL.
|
|
43
|
+
|
|
44
|
+
BSL и SDBL остаются разными контрактами парсера. Грамматика BSL не встраивает
|
|
45
|
+
SDBL в AST строковых литералов; разбор встроенных запросов выполняется через
|
|
46
|
+
tree-sitter injections и композицию на стороне редактора.
|
|
47
|
+
|
|
48
|
+
## Локальная разработка
|
|
49
|
+
|
|
50
|
+
Локальный tree-sitter playground запускается отдельно для каждой грамматики:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
npm start
|
|
54
|
+
npm run start:bsl
|
|
55
|
+
npm run start:sdbl
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`npm start` является псевдонимом для BSL playground. `npm run start:sdbl`
|
|
59
|
+
запускает playground самостоятельной грамматики SDBL. При необходимости можно
|
|
60
|
+
собрать оба WASM-парсера:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
npm run build:wasm
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Быстрая проверка дерева разбора:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
npm run parse:bsl -- examples/playground/basic.bsl
|
|
70
|
+
npm run parse:sdbl -- examples/playground/select.sdbl
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Небольшие примеры для playground лежат в
|
|
74
|
+
[`examples/playground`](examples/playground):
|
|
75
|
+
|
|
76
|
+
- [`basic.bsl`](examples/playground/basic.bsl) для синтаксиса исходных файлов
|
|
77
|
+
BSL;
|
|
78
|
+
- [`select.sdbl`](examples/playground/select.sdbl) и
|
|
79
|
+
[`query-package.sdbl`](examples/playground/query-package.sdbl) для синтаксиса
|
|
80
|
+
самостоятельных SDBL-запросов.
|
|
81
|
+
|
|
82
|
+
SDBL-примеры разбираются самостоятельной грамматикой SDBL. BSL-строки с
|
|
83
|
+
текстом запроса остаются узлами строк BSL; разбор встроенного запроса относится
|
|
84
|
+
к отдельному контракту injection/composition.
|
|
85
|
+
|
|
86
|
+
Основные команды проверки:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
npm run test:corpus
|
|
90
|
+
npm test
|
|
91
|
+
npm run test:all
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`npm run test:corpus` использует локальный для пакета `tree-sitter-cli` и
|
|
95
|
+
проверяет оба набора corpus-тестов. Для системного `tree-sitter` CLI, который
|
|
96
|
+
поддерживает `-p`, эквивалентные команды:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
tree-sitter test -p grammars/bsl
|
|
100
|
+
tree-sitter test -p grammars/sdbl
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Использование
|
|
104
|
+
|
|
105
|
+
### Rust
|
|
106
|
+
|
|
107
|
+
Добавьте зависимость в [`Cargo.toml`](Cargo.toml):
|
|
108
|
+
|
|
109
|
+
```toml
|
|
110
|
+
[dependencies]
|
|
111
|
+
tree-sitter = "0.25"
|
|
112
|
+
tree-sitter-hbk = "0.1"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```rust
|
|
116
|
+
use tree_sitter::Parser;
|
|
117
|
+
|
|
118
|
+
fn main() {
|
|
119
|
+
let mut parser = Parser::new();
|
|
120
|
+
parser
|
|
121
|
+
.set_language(&tree_sitter_hbk::LANGUAGE.into())
|
|
122
|
+
.expect("Error loading BSL grammar");
|
|
123
|
+
|
|
124
|
+
let source = r#"
|
|
125
|
+
Процедура Привет()
|
|
126
|
+
Сообщить("Привет, мир!");
|
|
127
|
+
КонецПроцедуры
|
|
128
|
+
"#;
|
|
129
|
+
|
|
130
|
+
let tree = parser.parse(source, None).unwrap();
|
|
131
|
+
println!("{}", tree.root_node().to_sexp());
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Node.js
|
|
136
|
+
|
|
137
|
+
Установите пакет:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
npm install tree-sitter-hbk tree-sitter
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const Parser = require("tree-sitter");
|
|
145
|
+
const BSL = require("tree-sitter-hbk");
|
|
146
|
+
|
|
147
|
+
const parser = new Parser();
|
|
148
|
+
parser.setLanguage(BSL);
|
|
149
|
+
|
|
150
|
+
const sourceCode = `
|
|
151
|
+
Процедура Привет()
|
|
152
|
+
Сообщить("Привет, мир!");
|
|
153
|
+
КонецПроцедуры
|
|
154
|
+
`;
|
|
155
|
+
|
|
156
|
+
const tree = parser.parse(sourceCode);
|
|
157
|
+
console.log(tree.rootNode.toString());
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Python
|
|
161
|
+
|
|
162
|
+
Установите пакет:
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
pip install tree-sitter-hbk tree-sitter
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
import tree_sitter_hbk as tshbk
|
|
170
|
+
from tree_sitter import Language, Parser
|
|
171
|
+
|
|
172
|
+
BSL_LANGUAGE = Language(tshbk.language())
|
|
173
|
+
parser = Parser(BSL_LANGUAGE)
|
|
174
|
+
|
|
175
|
+
source = """
|
|
176
|
+
Процедура Привет()
|
|
177
|
+
Сообщить("Привет, мир!");
|
|
178
|
+
КонецПроцедуры
|
|
179
|
+
""".encode()
|
|
180
|
+
|
|
181
|
+
tree = parser.parse(source)
|
|
182
|
+
print(tree.root_node.sexp())
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Грамматика запросов SDBL
|
|
186
|
+
|
|
187
|
+
Пакет также экспортирует самостоятельную грамматику языка запросов SDBL:
|
|
188
|
+
|
|
189
|
+
- Node.js: `require("tree-sitter-hbk").sdbl`;
|
|
190
|
+
- Rust: `tree_sitter_hbk::SDBL_LANGUAGE`;
|
|
191
|
+
- Python: `tree_sitter_hbk.SDBLLanguage()` или низкоуровневая капсула
|
|
192
|
+
`tree_sitter_hbk.sdbl_language()`;
|
|
193
|
+
- Go: `tree_sitter_bsl.SDBLLanguage()` from the existing Go binding package;
|
|
194
|
+
- C: `tree_sitter_sdbl()` из `tree-sitter-bsl.h` и той же библиотеки.
|
|
195
|
+
|
|
196
|
+
Существующие точки входа BSL остаются языком пакета по умолчанию.
|
|
197
|
+
|
|
198
|
+
Пакет включает query-файлы tree-sitter для интеграций с редакторами:
|
|
199
|
+
|
|
200
|
+
- `grammars/bsl/queries/highlights.scm` для подсветки BSL;
|
|
201
|
+
- `grammars/bsl/queries/injections.scm` для внедрения статических строковых
|
|
202
|
+
литералов BSL, начинающихся с ключевых слов SDBL-выражений, как `sdbl`;
|
|
203
|
+
- `grammars/sdbl/queries/highlights.scm` для подсветки самостоятельного SDBL и
|
|
204
|
+
текста запросов, внедренного из BSL.
|
|
205
|
+
|
|
206
|
+
Для Zed используется локальное dev extension:
|
|
207
|
+
[`editors/zed-bsl`](editors/zed-bsl). Оно регистрирует BSL, SDBL и
|
|
208
|
+
специальную для Zed грамматику-носитель `sdbl_embedded`, чтобы исходный текст
|
|
209
|
+
внедренной BSL-строки подсвечивался без изменения контракта самостоятельной
|
|
210
|
+
грамматики `.sdbl`.
|
|
211
|
+
|
|
212
|
+
## Ссылки
|
|
213
|
+
|
|
214
|
+
- Грамматика основана на правилах [BSL Parser](https://github.com/1c-syntax/bsl-parser)
|
|
215
|
+
- Архитектурные решения: [`docs/decisions`](docs/decisions)
|
|
216
|
+
- Активный список parser-задач: [`spec/IMPLEMENTATION_TODO.md`](spec/IMPLEMENTATION_TODO.md)
|
|
217
|
+
- Контракт грамматики SDBL: [`spec/sdbl-query-language.md`](spec/sdbl-query-language.md)
|
|
218
|
+
|
|
219
|
+
[ci]: https://img.shields.io/github/actions/workflow/status/mussolene/tree-sitter-bsl/ci.yml?logo=github&label=CI
|
|
220
|
+
[npm]: https://img.shields.io/npm/v/tree-sitter-hbk?logo=npm
|
|
221
|
+
[crates]: https://img.shields.io/crates/v/tree-sitter-hbk?logo=rust
|
|
222
|
+
[pypi]: https://img.shields.io/pypi/v/tree-sitter-hbk?logo=python
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# tree-sitter-hbk
|
|
2
|
+
|
|
3
|
+
[![CI][ci]](https://github.com/mussolene/tree-sitter-bsl/actions/workflows/ci.yml)
|
|
4
|
+
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-hbk)
|
|
5
|
+
[![crates.io][crates]](https://crates.io/crates/tree-sitter-hbk)
|
|
6
|
+
[![PyPI][pypi]](https://pypi.org/project/tree-sitter-hbk/)
|
|
7
|
+
|
|
8
|
+
Грамматика 1C BSL в формате [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
|
9
|
+
Пакет также содержит отдельную грамматику `sdbl` для языка запросов 1C.
|
|
10
|
+
|
|
11
|
+
[Попробовать](https://mussolene.github.io/tree-sitter-bsl/)
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Что входит
|
|
16
|
+
|
|
17
|
+
- `bsl`: грамматика исходных файлов BSL (`.bsl`, `.osl`).
|
|
18
|
+
- `sdbl`: грамматика самостоятельных текстов запросов 1C (`.sdbl`).
|
|
19
|
+
- Query-файлы tree-sitter для подсветки BSL/SDBL и внедрения статических
|
|
20
|
+
строковых литералов BSL, начинающихся с `ВЫБРАТЬ`, `SELECT`, `УНИЧТОЖИТЬ`
|
|
21
|
+
или `DROP`, как `sdbl`.
|
|
22
|
+
- Локальное dev-расширение Zed в [`editors/zed-bsl`](editors/zed-bsl) для
|
|
23
|
+
проверки подсветки BSL, самостоятельного SDBL и внедренного SDBL.
|
|
24
|
+
|
|
25
|
+
BSL и SDBL остаются разными контрактами парсера. Грамматика BSL не встраивает
|
|
26
|
+
SDBL в AST строковых литералов; разбор встроенных запросов выполняется через
|
|
27
|
+
tree-sitter injections и композицию на стороне редактора.
|
|
28
|
+
|
|
29
|
+
## Локальная разработка
|
|
30
|
+
|
|
31
|
+
Локальный tree-sitter playground запускается отдельно для каждой грамматики:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm start
|
|
35
|
+
npm run start:bsl
|
|
36
|
+
npm run start:sdbl
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`npm start` является псевдонимом для BSL playground. `npm run start:sdbl`
|
|
40
|
+
запускает playground самостоятельной грамматики SDBL. При необходимости можно
|
|
41
|
+
собрать оба WASM-парсера:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm run build:wasm
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Быстрая проверка дерева разбора:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm run parse:bsl -- examples/playground/basic.bsl
|
|
51
|
+
npm run parse:sdbl -- examples/playground/select.sdbl
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Небольшие примеры для playground лежат в
|
|
55
|
+
[`examples/playground`](examples/playground):
|
|
56
|
+
|
|
57
|
+
- [`basic.bsl`](examples/playground/basic.bsl) для синтаксиса исходных файлов
|
|
58
|
+
BSL;
|
|
59
|
+
- [`select.sdbl`](examples/playground/select.sdbl) и
|
|
60
|
+
[`query-package.sdbl`](examples/playground/query-package.sdbl) для синтаксиса
|
|
61
|
+
самостоятельных SDBL-запросов.
|
|
62
|
+
|
|
63
|
+
SDBL-примеры разбираются самостоятельной грамматикой SDBL. BSL-строки с
|
|
64
|
+
текстом запроса остаются узлами строк BSL; разбор встроенного запроса относится
|
|
65
|
+
к отдельному контракту injection/composition.
|
|
66
|
+
|
|
67
|
+
Основные команды проверки:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
npm run test:corpus
|
|
71
|
+
npm test
|
|
72
|
+
npm run test:all
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`npm run test:corpus` использует локальный для пакета `tree-sitter-cli` и
|
|
76
|
+
проверяет оба набора corpus-тестов. Для системного `tree-sitter` CLI, который
|
|
77
|
+
поддерживает `-p`, эквивалентные команды:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
tree-sitter test -p grammars/bsl
|
|
81
|
+
tree-sitter test -p grammars/sdbl
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Использование
|
|
85
|
+
|
|
86
|
+
### Rust
|
|
87
|
+
|
|
88
|
+
Добавьте зависимость в [`Cargo.toml`](Cargo.toml):
|
|
89
|
+
|
|
90
|
+
```toml
|
|
91
|
+
[dependencies]
|
|
92
|
+
tree-sitter = "0.25"
|
|
93
|
+
tree-sitter-hbk = "0.1"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```rust
|
|
97
|
+
use tree_sitter::Parser;
|
|
98
|
+
|
|
99
|
+
fn main() {
|
|
100
|
+
let mut parser = Parser::new();
|
|
101
|
+
parser
|
|
102
|
+
.set_language(&tree_sitter_hbk::LANGUAGE.into())
|
|
103
|
+
.expect("Error loading BSL grammar");
|
|
104
|
+
|
|
105
|
+
let source = r#"
|
|
106
|
+
Процедура Привет()
|
|
107
|
+
Сообщить("Привет, мир!");
|
|
108
|
+
КонецПроцедуры
|
|
109
|
+
"#;
|
|
110
|
+
|
|
111
|
+
let tree = parser.parse(source, None).unwrap();
|
|
112
|
+
println!("{}", tree.root_node().to_sexp());
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Node.js
|
|
117
|
+
|
|
118
|
+
Установите пакет:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
npm install tree-sitter-hbk tree-sitter
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
const Parser = require("tree-sitter");
|
|
126
|
+
const BSL = require("tree-sitter-hbk");
|
|
127
|
+
|
|
128
|
+
const parser = new Parser();
|
|
129
|
+
parser.setLanguage(BSL);
|
|
130
|
+
|
|
131
|
+
const sourceCode = `
|
|
132
|
+
Процедура Привет()
|
|
133
|
+
Сообщить("Привет, мир!");
|
|
134
|
+
КонецПроцедуры
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
const tree = parser.parse(sourceCode);
|
|
138
|
+
console.log(tree.rootNode.toString());
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Python
|
|
142
|
+
|
|
143
|
+
Установите пакет:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
pip install tree-sitter-hbk tree-sitter
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
import tree_sitter_hbk as tshbk
|
|
151
|
+
from tree_sitter import Language, Parser
|
|
152
|
+
|
|
153
|
+
BSL_LANGUAGE = Language(tshbk.language())
|
|
154
|
+
parser = Parser(BSL_LANGUAGE)
|
|
155
|
+
|
|
156
|
+
source = """
|
|
157
|
+
Процедура Привет()
|
|
158
|
+
Сообщить("Привет, мир!");
|
|
159
|
+
КонецПроцедуры
|
|
160
|
+
""".encode()
|
|
161
|
+
|
|
162
|
+
tree = parser.parse(source)
|
|
163
|
+
print(tree.root_node.sexp())
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Грамматика запросов SDBL
|
|
167
|
+
|
|
168
|
+
Пакет также экспортирует самостоятельную грамматику языка запросов SDBL:
|
|
169
|
+
|
|
170
|
+
- Node.js: `require("tree-sitter-hbk").sdbl`;
|
|
171
|
+
- Rust: `tree_sitter_hbk::SDBL_LANGUAGE`;
|
|
172
|
+
- Python: `tree_sitter_hbk.SDBLLanguage()` или низкоуровневая капсула
|
|
173
|
+
`tree_sitter_hbk.sdbl_language()`;
|
|
174
|
+
- Go: `tree_sitter_bsl.SDBLLanguage()` from the existing Go binding package;
|
|
175
|
+
- C: `tree_sitter_sdbl()` из `tree-sitter-bsl.h` и той же библиотеки.
|
|
176
|
+
|
|
177
|
+
Существующие точки входа BSL остаются языком пакета по умолчанию.
|
|
178
|
+
|
|
179
|
+
Пакет включает query-файлы tree-sitter для интеграций с редакторами:
|
|
180
|
+
|
|
181
|
+
- `grammars/bsl/queries/highlights.scm` для подсветки BSL;
|
|
182
|
+
- `grammars/bsl/queries/injections.scm` для внедрения статических строковых
|
|
183
|
+
литералов BSL, начинающихся с ключевых слов SDBL-выражений, как `sdbl`;
|
|
184
|
+
- `grammars/sdbl/queries/highlights.scm` для подсветки самостоятельного SDBL и
|
|
185
|
+
текста запросов, внедренного из BSL.
|
|
186
|
+
|
|
187
|
+
Для Zed используется локальное dev extension:
|
|
188
|
+
[`editors/zed-bsl`](editors/zed-bsl). Оно регистрирует BSL, SDBL и
|
|
189
|
+
специальную для Zed грамматику-носитель `sdbl_embedded`, чтобы исходный текст
|
|
190
|
+
внедренной BSL-строки подсвечивался без изменения контракта самостоятельной
|
|
191
|
+
грамматики `.sdbl`.
|
|
192
|
+
|
|
193
|
+
## Ссылки
|
|
194
|
+
|
|
195
|
+
- Грамматика основана на правилах [BSL Parser](https://github.com/1c-syntax/bsl-parser)
|
|
196
|
+
- Архитектурные решения: [`docs/decisions`](docs/decisions)
|
|
197
|
+
- Активный список parser-задач: [`spec/IMPLEMENTATION_TODO.md`](spec/IMPLEMENTATION_TODO.md)
|
|
198
|
+
- Контракт грамматики SDBL: [`spec/sdbl-query-language.md`](spec/sdbl-query-language.md)
|
|
199
|
+
|
|
200
|
+
[ci]: https://img.shields.io/github/actions/workflow/status/mussolene/tree-sitter-bsl/ci.yml?logo=github&label=CI
|
|
201
|
+
[npm]: https://img.shields.io/npm/v/tree-sitter-hbk?logo=npm
|
|
202
|
+
[crates]: https://img.shields.io/crates/v/tree-sitter-hbk?logo=rust
|
|
203
|
+
[pypi]: https://img.shields.io/pypi/v/tree-sitter-hbk?logo=python
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import tree_sitter
|
|
2
|
+
from ._binding import language, sdbl_language
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def Language():
|
|
6
|
+
"""Return the tree-sitter Language for BSL."""
|
|
7
|
+
return tree_sitter.Language(language())
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def SDBLLanguage():
|
|
11
|
+
"""Return the tree-sitter Language for SDBL."""
|
|
12
|
+
return tree_sitter.Language(sdbl_language())
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#include <Python.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
const TSLanguage *tree_sitter_bsl(void);
|
|
6
|
+
const TSLanguage *tree_sitter_sdbl(void);
|
|
7
|
+
|
|
8
|
+
static PyObject* py_language(PyObject *self, PyObject *args) {
|
|
9
|
+
return PyCapsule_New((void *)tree_sitter_bsl(), "tree_sitter.Language", NULL);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static PyObject* py_sdbl_language(PyObject *self, PyObject *args) {
|
|
13
|
+
return PyCapsule_New((void *)tree_sitter_sdbl(), "tree_sitter.Language", NULL);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static PyMethodDef methods[] = {
|
|
17
|
+
{"language", py_language, METH_NOARGS, "Get the tree-sitter language for BSL."},
|
|
18
|
+
{"sdbl_language", py_sdbl_language, METH_NOARGS, "Get the tree-sitter language for SDBL."},
|
|
19
|
+
{NULL, NULL, 0, NULL}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
static struct PyModuleDef module = {
|
|
23
|
+
PyModuleDef_HEAD_INIT, "_binding", NULL, -1, methods
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
PyMODINIT_FUNC PyInit__binding(void) {
|
|
27
|
+
return PyModule_Create(&module);
|
|
28
|
+
}
|
|
File without changes
|