@1c-syntax/codemirror-lang-bsl

中文文档
0.3.2发布于 2026/07/18MITTypeScriptESM + CJS构建来源已验证近 30 天下载 4882

1C:Enterprise / OneScript (BSL) language support for CodeMirror 6

原始使用文档
文档目录13 节
  1. 👉 Live demo
  2. Install
  3. Usage
  4. What's covered
  5. Upstream references
  6. Limitations
  7. Build & test
  8. Demo
  9. Publishing a release
  10. Setup (one-time)
  11. Cutting a release
  12. Dry-run before cutting
  13. License

@1c-syntax/codemirror-lang-bsl

npm CI License: MIT

CodeMirror 6 language support package for 1C:Enterprise (BSL) and OneScript — Russian and English keyword syntax, preprocessor directives, compilation annotations, multi-line string literals, and embedded query language (SDBL) inside string literals.

👉 Live demo

https://1c-syntax.github.io/codemirror-lang-bsl/ — two side-by-side CodeMirror 6 editors: one with a sample BSL module (procedure with annotation, control flow, async function, region), another with a function whose query string body is highlighted by the embedded SDBL grammar. Add ?theme=light to the URL for the light theme.

API reference (generated from JSDoc with TypeDoc): https://1c-syntax.github.io/codemirror-lang-bsl/api/.

The grammar is implemented in Lezer, references the 1c-syntax/bsl-parser ANTLR4 grammars for structure and the 1c-syntax/vsc-language-1c-bsl TextMate grammar for token style mapping.

Install

npm install @1c-syntax/codemirror-lang-bsl

Usage

import {EditorView, basicSetup} from "codemirror"
import {bsl} from "@1c-syntax/codemirror-lang-bsl"

new EditorView({
  doc: 'Процедура Привет() Экспорт\n    Сообщить("Привет, мир!");\nКонецПроцедуры',
  extensions: [basicSetup, bsl()],
  parent: document.body
})

What's covered

  • Module-level: variable declarations (Перем/Var), procedure/function declarations with Экспорт, default parameters and Знач/Val, async modifier АСИНХ
  • Control flow: Если/ИначеЕсли/Иначе/КонецЕсли, Пока/КонецЦикла, Для … По … Цикл/КонецЦикла, Для Каждого … Из/КонецЦикла, Попытка/Исключение/КонецПопытки
  • Statements: Возврат/Продолжить/Прервать/Перейти, labels ~Метка:, Ждать as both standalone statement and expression, ВызватьИсключение, Выполнить, ДобавитьОбработчик/УдалитьОбработчик
  • Expressions: number literals, string literals (single-line and multi-line with | continuation), date literals 'YYYYMMDDHHMMSS', booleans Истина/Ложь, Неопределено, Null, Новый, ternary ?(…)
  • Operators: arithmetic, comparison, logical (И/Или/Не)
  • Annotations: &НаКлиенте, &НаСервере, &НаКлиентеНаСервереБезКонтекста, … including annotation parameters
  • Preprocessor: #Если/#ИначеЕсли/#Иначе/#КонецЕсли, #Область/#КонецОбласти, #Использовать, #native
  • Comments: // (single-line), /// (BSLDescription doc-comments)
  • SDBL (BSL query language) embedded inside query string literals — a separate Lezer grammar covering 100+ keywords (statement / operator / function / type / metadata-object / virtual-table categories) is mounted as an overlay onto any string literal that starts with ВЫБРАТЬ/SELECT/ УНИЧТОЖИТЬ/DROP. Russian and English keyword variants are both recognised and styled identically.

Upstream references

The grammar and style mapping are derived from the following 1c-syntax projects. When updating this package, diff against the recorded commit to catch grammar changes upstream.

ProjectUsed forPinned commitTag
1c-syntax/bsl-parserLexer/parser structure (BSL + SDBL ANTLR4 grammars)a30f8169885836226208041fbc41001bd64d710ev0.34.1
1c-syntax/vsc-language-1c-bslTextMate scope reference (1c.tmLanguage.json, 1c-query.tmLanguage.json)30e6c7994a2ee745c92fa0238fa2e81c78d4781dv1.33.1
1c-syntax/bsl-language-serverSemantic-token → LSP token type mapping (SemanticTokensProvider, *SemanticTokensSupplier) — pinned against the active develop branch, not the latest releasebe49fcbf45d082a1db15504b51a551f6a55183c0 (develop)latest release at the time: v0.29.0

To re-sync after an upstream change: bump the relevant pinned commit in the table above, replay the upstream diff against src/bsl.grammar and src/index.ts (styleTags), and add regression tests in test/cases.txt.

Limitations

A handful of intentional simplifications, mostly to keep the LR grammar free of ambiguity:

  • Context-sensitive preprocessor identifiers. #Если/#Иначе/ #КонецЕсли/#Тогда/#И/#Или/#Не reuse the corresponding BSL keyword terms — styleTags discriminates them via parent selectors. The remaining preprocessor-only words (Область, КонецОбласти, Использовать, native, Удаление/КонецУдаления, Вставка/КонецВставки) are specialized globally; if you use one as an ordinary identifier outside # context, it will be tagged as a preprocessor token. BSL convention does not collide with these names in practice.
  • Comma-skipping in call arguments (Метод(a,,b) or Метод(,a)) is not supported — modelling , as a stand-alone item conflicts with inner f(g(...)) parsing in LR(1) without a custom external tokenizer. All arguments must be non-empty expressions. Affects roughly 1–2% of real-world BSL.
  • Multiline strings cannot contain embedded preprocessor directives. ANTLR's multilineString : STRINGSTART (STRINGPART | BAR | preprocessor)* STRINGTAIL accepts #Если inside a |-continued string; we match the entire literal as one token. Very rare in practice.

Verified against ~100 real-world configuration files (1c-syntax/bsl-language-server and 1c-syntax/vsc-language-1c-bsl fixtures): 85% clean parses, 0 hard failures, the remaining ~15% are either intentional ParseError test cases, source-level typos, or hit one of the three limitations above.

Out of scope (defer to other tools):

  • IntelliSense / completion / hover — that belongs in bsl-language-server.
  • Refactorings, diagnostics — same.

Build & test

npm install
npm run build   # runs lezer-generator + rollup + tsc
npm test        # mocha against test/cases.txt fixtures

The repo ships a public-npm .npmrc so contributors on networks that default to a private mirror (e.g. corporate Artifactory) still resolve packages from https://registry.npmjs.org/. Publishing requires a separate npm login against the public registry.

Demo

The hosted version at https://1c-syntax.github.io/codemirror-lang-bsl/ is deployed automatically by .github/workflows/pages.yml on every push to main. To build the demo locally:

npm install
npm run lint          # ESLint (flat config) on src/, examples/, test/
npm run build         # main library → dist/
npm test              # mocha against test/cases.txt and overlay tests
npm run build:demo    # static demo → docs/{index.html,bundle.js}
npm run build:docs    # TypeDoc API reference → docs/api/
npm run build:site    # demo + docs (CI uses this for gh-pages)
# serve docs/ via any HTTP server, e.g.
python3 -m http.server -d docs 8080

examples/demo.ts is the source; examples/index.html is the HTML shell that the rollup config copies into docs/index.html alongside the bundled bundle.js.

Publishing a release

Releases are cut by publishing a GitHub Release with a tag of the form v<version> (matching package.json#version). The .github/workflows/publish.yml workflow builds, tests, and runs npm publish --provenance --access public against npmjs.org. Authentication is done via npm Trusted Publishing — no long-lived NPM_TOKEN secret is needed; npm exchanges the workflow's OIDC token for a short-lived credential at publish time.

Setup (one-time)

  1. https://www.npmjs.com/package/@1c-syntax/codemirror-lang-bsl/access → Trusted Publishers → Add
  2. Provider: GitHub Actions
  3. Repository owner: 1c-syntax, Repository: codemirror-lang-bsl
  4. Workflow file name: publish.yml
  5. Environment: npm

That's it — no secrets, no tokens. The workflow's id-token: write permission plus --provenance are enough; npm verifies the OIDC token against the configured trusted publisher and accepts the upload.

Cutting a release

  1. Bump package.json#version, commit, push.
  2. https://github.com/1c-syntax/codemirror-lang-bsl/releases/new → tag v<version> (matching package.json#version) → Publish release.
  3. The Publish to npm workflow picks up the release.published event, verifies tag-vs-version, builds, tests, and runs npm publish.

Dry-run before cutting

workflow_dispatch on Publish to npm accepts a dry_run input. Run it to validate auth, build, and tarball contents without actually publishing.

License

MIT — see LICENSE.

版本与发布记录

@1c-syntax/codemirror-lang-bsl 共发布 5 个版本,首次发布于 2026/05/28;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.2latest2026/07/183 个月前
0.3.12026/05/295 个月前
0.3.02026/05/295 个月前
0.2.12026/05/285 个月前
0.2.02026/05/285 个月前

关于 @1c-syntax/codemirror-lang-bsl 的常见问题

@1c-syntax/codemirror-lang-bsl 是什么?

1C:Enterprise / OneScript (BSL) language support for CodeMirror 6

如何安装 @1c-syntax/codemirror-lang-bsl?

在项目目录运行 npm install @1c-syntax/codemirror-lang-bsl,或使用 pnpm add / yarn add / bun add。

@1c-syntax/codemirror-lang-bsl 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@1c-syntax/codemirror-lang-bsl 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@1c-syntax/codemirror-lang-bsl 可以商用吗?

@1c-syntax/codemirror-lang-bsl 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@1c-syntax/codemirror-lang-bsl 的下载量有多少?

根据 npm 官方下载统计,@1c-syntax/codemirror-lang-bsl 在 2026/10/05 – 2026/11/03 这 30 天内被下载 4,882 次,日均约 163 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@1c-syntax/codemirror-lang-bsl 还在维护吗?

最新版本 0.3.2 发布于 2026/07/18(3 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/05/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。