Skip to main content

1C (BSL) language

Project description

tree-sitter-hbk

CI npm crates.io PyPI

Грамматика 1C BSL в формате tree-sitter. Пакет также содержит отдельную грамматику sdbl для языка запросов 1C.

Попробовать

playground

Что входит

  • bsl: грамматика исходных файлов BSL (.bsl, .osl).
  • sdbl: грамматика самостоятельных текстов запросов 1C (.sdbl).
  • Query-файлы tree-sitter для подсветки BSL/SDBL и внедрения статических строковых литералов BSL, начинающихся с ВЫБРАТЬ, SELECT, УНИЧТОЖИТЬ или DROP, как sdbl.
  • Локальное dev-расширение Zed в editors/zed-bsl для проверки подсветки BSL, самостоятельного SDBL и внедренного SDBL.

BSL и SDBL остаются разными контрактами парсера. Грамматика BSL не встраивает SDBL в AST строковых литералов; разбор встроенных запросов выполняется через tree-sitter injections и композицию на стороне редактора.

Локальная разработка

Локальный tree-sitter playground запускается отдельно для каждой грамматики:

npm start
npm run start:bsl
npm run start:sdbl

npm start является псевдонимом для BSL playground. npm run start:sdbl запускает playground самостоятельной грамматики SDBL. При необходимости можно собрать оба WASM-парсера:

npm run build:wasm

Быстрая проверка дерева разбора:

npm run parse:bsl -- examples/playground/basic.bsl
npm run parse:sdbl -- examples/playground/select.sdbl

Небольшие примеры для playground лежат в examples/playground:

  • basic.bsl для синтаксиса исходных файлов BSL;
  • select.sdbl и query-package.sdbl для синтаксиса самостоятельных SDBL-запросов.

SDBL-примеры разбираются самостоятельной грамматикой SDBL. BSL-строки с текстом запроса остаются узлами строк BSL; разбор встроенного запроса относится к отдельному контракту injection/composition.

Основные команды проверки:

npm run test:corpus
npm test
npm run test:all

npm run test:corpus использует локальный для пакета tree-sitter-cli и проверяет оба набора corpus-тестов. Для системного tree-sitter CLI, который поддерживает -p, эквивалентные команды:

tree-sitter test -p grammars/bsl
tree-sitter test -p grammars/sdbl

Использование

Rust

Добавьте зависимость в Cargo.toml:

[dependencies]
tree-sitter = "0.25"
tree-sitter-hbk = "0.1"
use tree_sitter::Parser;

fn main() {
    let mut parser = Parser::new();
    parser
        .set_language(&tree_sitter_hbk::LANGUAGE.into())
        .expect("Error loading BSL grammar");

    let source = r#"
        Процедура Привет()
            Сообщить("Привет, мир!");
        КонецПроцедуры
    "#;

    let tree = parser.parse(source, None).unwrap();
    println!("{}", tree.root_node().to_sexp());
}

Node.js

Установите пакет:

npm install tree-sitter-hbk tree-sitter
const Parser = require("tree-sitter");
const BSL = require("tree-sitter-hbk");

const parser = new Parser();
parser.setLanguage(BSL);

const sourceCode = `
Процедура Привет()
    Сообщить("Привет, мир!");
КонецПроцедуры
`;

const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());

Python

Установите пакет:

pip install tree-sitter-hbk tree-sitter
import tree_sitter_hbk as tshbk
from tree_sitter import Language, Parser

BSL_LANGUAGE = Language(tshbk.language())
parser = Parser(BSL_LANGUAGE)

source = """
Процедура Привет()
    Сообщить("Привет, мир!");
КонецПроцедуры
""".encode()

tree = parser.parse(source)
print(tree.root_node.sexp())

Грамматика запросов SDBL

Пакет также экспортирует самостоятельную грамматику языка запросов SDBL:

  • Node.js: require("tree-sitter-hbk").sdbl;
  • Rust: tree_sitter_hbk::SDBL_LANGUAGE;
  • Python: tree_sitter_hbk.SDBLLanguage() или низкоуровневая капсула tree_sitter_hbk.sdbl_language();
  • Go: tree_sitter_bsl.SDBLLanguage() from the existing Go binding package;
  • C: tree_sitter_sdbl() из tree-sitter-bsl.h и той же библиотеки.

Существующие точки входа BSL остаются языком пакета по умолчанию.

Пакет включает query-файлы tree-sitter для интеграций с редакторами:

  • grammars/bsl/queries/highlights.scm для подсветки BSL;
  • grammars/bsl/queries/injections.scm для внедрения статических строковых литералов BSL, начинающихся с ключевых слов SDBL-выражений, как sdbl;
  • grammars/sdbl/queries/highlights.scm для подсветки самостоятельного SDBL и текста запросов, внедренного из BSL.

Для Zed используется локальное dev extension: editors/zed-bsl. Оно регистрирует BSL, SDBL и специальную для Zed грамматику-носитель sdbl_embedded, чтобы исходный текст внедренной BSL-строки подсвечивался без изменения контракта самостоятельной грамматики .sdbl.

Ссылки

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_hbk-0.1.10.tar.gz (172.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_hbk-0.1.10-cp310-abi3-win_amd64.whl (94.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_hbk-0.1.10-cp310-abi3-win32.whl (97.4 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_hbk-0.1.10-cp310-abi3-musllinux_1_2_x86_64.whl (106.8 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_hbk-0.1.10-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (106.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_hbk-0.1.10-cp310-abi3-macosx_11_0_arm64.whl (95.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file tree_sitter_hbk-0.1.10.tar.gz.

File metadata

  • Download URL: tree_sitter_hbk-0.1.10.tar.gz
  • Upload date:
  • Size: 172.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tree_sitter_hbk-0.1.10.tar.gz
Algorithm Hash digest
SHA256 9872228592f17d9b76c61f275f4e9cd47c16e0f32e6f6ba5f0aa5cc609b00895
MD5 035b6cb8d5b1ac523aeb773cec5ccd2b
BLAKE2b-256 e8d4fc20463af85876bc107a0b19c8d73836f52ee80f1294cc317f42a133521d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hbk-0.1.10.tar.gz:

Publisher: publish.yml on mussolene/tree-sitter-bsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hbk-0.1.10-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_hbk-0.1.10-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a3a1340bf0f394b1af4644c86e0ce108258180c11b2cbfb2098574db6adc3cc0
MD5 85570cd248b9eeb97a0a26e243d92704
BLAKE2b-256 9da12d82e7e079171b529e202658afac4a23fbeae979cb43d6f66d414ce4416e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hbk-0.1.10-cp310-abi3-win_amd64.whl:

Publisher: publish.yml on mussolene/tree-sitter-bsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hbk-0.1.10-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for tree_sitter_hbk-0.1.10-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 16f264d8e57d596875d383a9067694177aaeed2933cb2fd58fea595a14841009
MD5 cf27c3f68e1bd27190a0662c9aeb80a2
BLAKE2b-256 ebd242e18988a45519af0b55e65f3cbdde3baf8577415cb921816ec75f4825c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hbk-0.1.10-cp310-abi3-win32.whl:

Publisher: publish.yml on mussolene/tree-sitter-bsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hbk-0.1.10-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_hbk-0.1.10-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dcccf20ad34e45a601f64001f10a09816885956b9159d9c38cf1ebb4fd7f2f18
MD5 40ce37215920865301d7b3500d995b2d
BLAKE2b-256 f1b75d67bfb33f530e18c39b61e69a99c975d5d5516a92583b48fe9e588eae5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hbk-0.1.10-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish.yml on mussolene/tree-sitter-bsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hbk-0.1.10-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_hbk-0.1.10-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 5e5c733494c6612b0f7a1b99a5914449de3ba16d5f8706c0d0bad60e0a0f7f0a
MD5 cef0367684683d8e93ca02fa72b33a4c
BLAKE2b-256 6f288892958fa908188e540f31c051638e14db5b5c749b40fe22a2d78fcbec65

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hbk-0.1.10-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: publish.yml on mussolene/tree-sitter-bsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_hbk-0.1.10-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_hbk-0.1.10-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5de5fff3c8c88a82006a4d48d238d86b282f0d973985d047e69d76c63887c71
MD5 f930b08fafbc9affaba190f48c928bf2
BLAKE2b-256 aaca407018c52af447faf7e40724f32a0709142038ce167e39e86792d1b34ac5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_hbk-0.1.10-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on mussolene/tree-sitter-bsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page