Unify formatting on canonical syntax

This commit is contained in:
2026-08-13 19:31:21 +09:00
parent d9cf24d0eb
commit 515adc2533
25 changed files with 951 additions and 792 deletions
Generated
-42
View File
@@ -23,16 +23,6 @@ version = "3.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
[[package]]
name = "cc"
version = "1.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5d6cac793997bd970000024b2934968efe83b382de4fdcf4fcb46b6ee4ad996"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
@@ -92,8 +82,6 @@ version = "0.1.3"
dependencies = [
"decodal",
"serde_json",
"tree-sitter",
"tree-sitter-decodal",
"wasm-bindgen",
]
@@ -121,12 +109,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "fluent-uri"
version = "0.1.4"
@@ -345,12 +327,6 @@ dependencies = [
"syn 3.0.3",
]
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "slab"
version = "0.4.12"
@@ -379,24 +355,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "tree-sitter"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca"
dependencies = [
"cc",
"regex",
]
[[package]]
name = "tree-sitter-decodal"
version = "0.1.0"
dependencies = [
"cc",
"tree-sitter",
]
[[package]]
name = "unicode-ident"
version = "1.0.24"
+1 -1
View File
@@ -7,8 +7,8 @@ members = [
"crates/decodal-language-tools",
"crates/decodal-language-service",
"crates/decodal-lsp",
"editors/tree-sitter-decodal",
]
exclude = ["editors/tree-sitter-decodal"]
resolver = "2"
[workspace.package]
+12 -6
View File
@@ -5,22 +5,27 @@ Run all commands from the repository root. Publishing requires Cargo, npm, and J
## Versions
- Rust crates: `0.1.3`
- `tree-sitter-decodal`: `0.1.0`
- `decodal-wasm` npm/JSR package: `0.1.4`
- `decodal-codemirror`: unchanged at `0.1.5`
- `decodal-codemirror`: `0.1.6`
## Validate
```sh
cargo fmt --check
cargo test --workspace
cargo test -p decodal --no-default-features
cargo clippy --workspace --all-targets -- -D warnings
cargo clippy -p decodal-wasm --target wasm32-unknown-unknown -- -D warnings
npm --prefix site/decodal-site run build:runtime
cargo clippy -p decodal-language-tools --target wasm32-unknown-unknown -- -D warnings
npm --prefix site/decodal-site run build:wasm
npm --prefix packages/decodal-codemirror test
npm --prefix site/decodal-site test
npm --prefix site/decodal-site run build
deno check packages/decodal-wasm/mod.ts
npm pack --dry-run ./packages/decodal-wasm
deno publish --dry-run --config packages/decodal-wasm/jsr.json
npm pack --dry-run ./packages/decodal-codemirror
deno publish --dry-run --config packages/decodal-codemirror/jsr.json
```
## Publish Rust crates
@@ -31,7 +36,6 @@ Run the corresponding command with `--dry-run` immediately before each real publ
```sh
cargo publish -p decodal-derive
cargo publish -p decodal
cargo publish -p tree-sitter-decodal
cargo publish -p decodal-language-service
cargo publish -p decodal-language-tools
cargo publish -p decodal-lsp
@@ -41,12 +45,14 @@ cargo publish -p decodal-lsp
## Publish JavaScript packages
The runtime build regenerates and normalizes the committed npm/JSR package before publishing.
The WASM build regenerates and normalizes both committed npm/JSR packages before publishing.
```sh
npm --prefix site/decodal-site run build:runtime
npm --prefix site/decodal-site run build:wasm
npm publish ./packages/decodal-wasm
deno publish --config packages/decodal-wasm/jsr.json
npm publish ./packages/decodal-codemirror
deno publish --config packages/decodal-codemirror/jsr.json
```
After both registries accept the release, tag the release commit and update the deployed site.
+7
View File
@@ -70,6 +70,13 @@ pub enum Expr {
params: Vec<Param>,
body: ExprId,
},
/// An explicitly parenthesized expression.
///
/// Keeping this node preserves the delimiters and their trivia for source
/// tools while evaluation remains equivalent to evaluating `expr`.
Parenthesized {
expr: ExprId,
},
Match {
scrutinee: ExprId,
arms: Vec<MatchArm>,
+22
View File
@@ -471,6 +471,13 @@ impl<L: ImportLoader> Engine<L> {
},
)))
}
Expr::Parenthesized { expr } => self.eval_expr(
ExprRef {
module: reference.module,
expr,
},
env,
),
Expr::Match { scrutinee, arms } => {
let value = self.eval_expr(
ExprRef {
@@ -827,6 +834,14 @@ impl<L: ImportLoader> Engine<L> {
) -> Result<bool> {
match self.expr(pattern).clone() {
Expr::Wildcard => Ok(true),
Expr::Parenthesized { expr } => self.matches_pattern(
value,
ExprRef {
module: pattern.module,
expr,
},
env,
),
Expr::ArrayConstraint { .. }
| Expr::CompareConstraint { .. }
| Expr::RegexConstraint(_)
@@ -2043,6 +2058,13 @@ mod tests {
assert_eq!(fields[4].value, Data::Int(-2));
}
#[test]
fn parenthesized_wildcard_remains_a_match_pattern() {
let data = eval_data("result = match 1 { (_): 2; };");
let Data::Object(fields) = data else { panic!() };
assert_eq!(fields[0].value, Data::Int(2));
}
#[test]
fn arithmetic_can_feed_constraints() {
let data = eval_data("port = Int & > 4000 + 42 default 8080;");
+68 -13
View File
@@ -52,9 +52,25 @@ pub enum TokenKind {
Gte,
Lt,
Lte,
/// A line comment, including its leading `#` and excluding its newline.
Comment,
Eof,
}
/// Tokenizes source while retaining comments and source spans for tooling.
///
/// Whitespace remains available through the gaps between adjacent token spans,
/// making this a lossless syntax view when paired with the original source.
pub fn tokenize_source(source: &str) -> Result<Vec<Token>> {
tokenize_source_with_source_id(SourceId(0), source)
}
/// Tokenizes source with a caller-provided source identifier while retaining
/// comments and source spans for tooling.
pub fn tokenize_source_with_source_id(source_id: SourceId, source: &str) -> Result<Vec<Token>> {
Lexer::with_source_id(source_id, source).tokenize_with_comments()
}
pub struct Lexer<'a> {
source_id: SourceId,
source: &'a str,
@@ -78,10 +94,26 @@ impl<'a> Lexer<'a> {
}
pub fn tokenize(mut self) -> Result<Vec<Token>> {
self.tokenize_impl(false)
}
fn tokenize_with_comments(mut self) -> Result<Vec<Token>> {
self.tokenize_impl(true)
}
fn tokenize_impl(&mut self, include_comments: bool) -> Result<Vec<Token>> {
let mut tokens = Vec::new();
let mut previous = None;
loop {
let token = self.next_token(previous.as_ref())?;
self.skip_whitespace();
if self.peek() == Some(b'#') {
let comment = self.lex_comment();
if include_comments {
tokens.push(comment);
}
continue;
}
let token = self.next_non_ws_token(previous.as_ref())?;
let is_eof = token.kind == TokenKind::Eof;
if !is_eof {
previous = Some(token.kind.clone());
@@ -93,11 +125,6 @@ impl<'a> Lexer<'a> {
}
}
fn next_token(&mut self, previous: Option<&TokenKind>) -> Result<Token> {
self.skip_ws_and_comments();
self.next_non_ws_token(previous)
}
fn next_non_ws_token(&mut self, previous: Option<&TokenKind>) -> Result<Token> {
let start = self.pos;
let Some(ch) = self.peek() else {
@@ -259,21 +286,23 @@ impl<'a> Lexer<'a> {
})
}
fn skip_ws_and_comments(&mut self) {
loop {
fn skip_whitespace(&mut self) {
while matches!(self.peek(), Some(b' ' | b'\t' | b'\r' | b'\n')) {
self.pos += 1;
}
if self.peek() == Some(b'#') {
}
fn lex_comment(&mut self) -> Token {
let start = self.pos;
while let Some(c) = self.peek() {
self.pos += 1;
if c == b'\n' {
break;
}
self.pos += 1;
}
continue;
}
break;
Token {
kind: TokenKind::Comment,
span: self.span(start, self.pos),
}
}
@@ -453,4 +482,30 @@ mod tests {
assert!(matches!(tokens[2].kind, TokenKind::Ident(_)));
assert_eq!(tokens[3].kind, TokenKind::RBracket);
}
#[test]
fn tooling_tokens_retain_comments_and_whitespace_gaps() {
let source = "value = 1; # trailing\n\n# leading\nnext = 2;";
let tokens = tokenize_source(source).unwrap();
let comments = tokens
.iter()
.filter(|token| token.kind == TokenKind::Comment)
.collect::<Vec<_>>();
assert_eq!(comments.len(), 2);
assert_eq!(
&source[comments[0].span.start as usize..comments[0].span.end as usize],
"# trailing"
);
assert!(
source[comments[0].span.end as usize..comments[1].span.start as usize].contains("\n\n")
);
let source_id = SourceId(7);
let identified = tokenize_source_with_source_id(source_id, "# comment").unwrap();
assert!(
identified
.iter()
.all(|token| token.span.source == source_id)
);
}
}
+4
View File
@@ -23,6 +23,10 @@ pub use diagnostic::{Diagnostic, DiagnosticKind, Result};
pub use embedding::{HostField, HostValue};
pub use environment::HostEnvironment;
pub use eval::{Engine, format_diagnostic_with};
pub use lexer::{
Token as SyntaxToken, TokenKind as SyntaxTokenKind, tokenize_source,
tokenize_source_with_source_id,
};
pub use module::{
EmptyLoader, ImportCandidate, ImportLoader, LoadedImport, LoadedSource, LoadedValue, Module,
};
+25 -4
View File
@@ -38,7 +38,10 @@ pub struct Parser {
impl Parser {
pub fn new(tokens: Vec<Token>) -> Self {
Self {
tokens,
tokens: tokens
.into_iter()
.filter(|token| token.kind != TokenKind::Comment)
.collect(),
pos: 0,
ast: Ast::new(),
}
@@ -380,8 +383,9 @@ impl Parser {
}
let expr = self.parse_expr(0)?;
self.expect_kind(&TokenKind::RParen, "expected ')' after expression")?;
Ok(expr)
let end_span = self.expect_kind(&TokenKind::RParen, "expected ')' after expression")?;
let span = start_span.join(end_span);
Ok(self.ast.push(Expr::Parenthesized { expr }, span))
}
fn parse_params_after_lparen(&mut self) -> Result<Vec<Param>> {
@@ -692,7 +696,24 @@ mod tests {
let Expr::ArrayConstraint { item } = parsed.ast.get(parsed.root).expr else {
panic!()
};
assert!(matches!(parsed.ast.get(item).expr, Expr::Binary { .. }));
let Expr::Parenthesized { expr } = parsed.ast.get(item).expr else {
panic!()
};
assert!(matches!(parsed.ast.get(expr).expr, Expr::Binary { .. }));
assert_eq!(parsed.ast.span(item), Span::new(SourceId(0), 4, 22));
}
#[test]
fn parser_accepts_the_public_lossless_token_stream() {
let tokens = crate::tokenize_source("value = (# note\n 1);").unwrap();
let parsed = Parser::new(tokens).parse().unwrap();
let Expr::Object(fields) = &parsed.ast.get(parsed.root).expr else {
panic!()
};
assert!(matches!(
parsed.ast.get(fields[0].value).expr,
Expr::Parenthesized { .. }
));
}
#[test]
+1 -3
View File
@@ -7,7 +7,7 @@ license.workspace = true
repository.workspace = true
readme.workspace = true
description = "Source-level language tooling for Decodal."
keywords = ["decodal", "formatter", "lsp", "tree-sitter"]
keywords = ["decodal", "formatter", "lsp", "language-tools"]
categories = ["development-tools", "text-processing"]
[lib]
@@ -16,8 +16,6 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
decodal = { version = "0.1.3", path = "../decodal-core" }
serde_json.workspace = true
tree-sitter = "0.22.6"
tree-sitter-decodal = { version = "0.1.0", path = "../../editors/tree-sitter-decodal" }
wasm-bindgen.workspace = true
[package.metadata.wasm-pack.profile.release]
File diff suppressed because it is too large Load Diff
+11 -8
View File
@@ -58,10 +58,11 @@ The default `decodal-lsp` binary reads Decodal imports from the filesystem.
Embedded hosts can call its library entry point with a custom `LspEnvironment` to reuse structured imports and to make unsaved external documents, such as Markdown, visible to the loader.
Source formatting lives in a separate Rust language tools crate.
Keeping it separate prevents host-specific semantic services from inheriting the formatter's Tree-sitter and WebAssembly dependencies.
It uses the canonical Decodal AST together with the runtime lexer's lossless syntax tokens, so native LSP and WebAssembly callers execute the same formatter implementation.
This component is responsible for operations that must preserve source text details such as comments and whitespace.
It is used by the CodeMirror package's bundled formatter WebAssembly and can also be used by an LSP adapter for formatting.
It does not depend on Tree-sitter or Lezer.
Important paths:
@@ -74,7 +75,7 @@ The current language tools crate exposes the formatter.
## Web editor components
The Web playground editor uses CodeMirror 6 with a generated Lezer parser.
This is the source of syntax highlighting, folding, indentation, editor syntax tree behavior, and the browser formatter command in the browser UI.
Lezer provides syntax highlighting, folding, indentation, and editor syntax tree behavior. The browser formatter command calls the canonical Rust formatter compiled to WebAssembly.
Important paths:
@@ -120,18 +121,20 @@ doc/manual/souce/language/grammar.md
This EBNF is the language-level reference.
The Rust parser, Lezer grammar, and Tree-sitter grammar should be kept aligned with it, but each implementation may encode precedence and recovery behavior in the form required by its parser generator or runtime.
## What is not a public component
## Syntax token API
The Rust lexer is an implementation detail of the Rust parser.
Decodal does not expose a standalone public tokenizer API for editor tooling.
Consumers that need syntax information should use the component that matches their environment:
The `decodal` crate exposes `tokenize_source`, `tokenize_source_with_source_id`, `SyntaxToken`, and `SyntaxTokenKind` for source-preserving tooling.
Comments have explicit tokens, while whitespace is represented by gaps between token spans and can be recovered from the original source.
The evaluator parser and formatter therefore share one lexical definition without making Tree-sitter an upstream dependency.
Consumers should otherwise use the component matching their environment:
- Rust execution and embedding: `decodal`
- Browser execution: `decodal-wasm`
- Web formatting and editor syntax: Lezer / CodeMirror
- Web formatting and editor syntax: canonical formatter / CodeMirror / Lezer
- Semantic editor analysis: `decodal-language-service`
- Language Server Protocol integration: `decodal-lsp`
- Rust formatting: `decodal-language-tools`
- General editor syntax: Tree-sitter
This avoids having a separate token stream API whose behavior would have to be kept compatible with both runtime parsing and editor grammars.
Tree-sitter and Lezer remain downstream editor grammars and are not dependencies of the runtime formatter.
+3 -25
View File
@@ -34,33 +34,13 @@ cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
## crates.io release
The primary crates.io package is `decodal`, which contains the embeddable library.
`decodal-derive` provides optional derive macros for Rust struct integration and is published only when the derive crate changes.
Workspace support crates such as `decodal-cli`, the Rust source crate `decodal-wasm`, `decodal-language-tools`, and `decodal-lsp` are not published to crates.io.
The crates.io release contains `decodal`, `decodal-derive`, `decodal-language-service`, `decodal-language-tools`, and `decodal-lsp`.
`decodal-cli` and the Rust source crate `decodal-wasm` remain repository-only packages.
The generated WebAssembly package under `packages/decodal-wasm/` is published to npm and JSR.
The CodeMirror package bundles the generated formatter WebAssembly from `decodal-language-tools`.
The project is dual licensed as `MIT OR Apache-2.0`.
```sh
cargo publish -p decodal
```
Publish `decodal-derive` first only when that crate has a new version:
```sh
cargo publish -p decodal-derive
```
Before publishing, run:
```sh
cargo fmt --check
cargo test
cargo check -p decodal --no-default-features
cargo publish -p decodal --dry-run
```
If `decodal-derive` changed, also run `cargo publish -p decodal-derive --dry-run`.
The authoritative validation commands, dependency order, and publish commands are maintained in `RELEASING.md` at the repository root.
## Web site and playground
@@ -125,7 +105,6 @@ npx jsr publish --dry-run
The npm package name is `decodal-wasm`.
The JSR package name is `@hare/decodal-wasm`.
JSR currently expects a single SPDX license identifier in `jsr.json`; the WebAssembly package metadata uses `MIT` while the Rust workspace remains dual licensed as `MIT OR Apache-2.0`.
The playground editor uses the `decodal-codemirror` package with the generated Lezer parser in `packages/decodal-codemirror/src/decodal-parser.js`.
The canonical grammar is documented in `doc/manual/souce/language/grammar.md`; regenerate the Lezer parser when that grammar or `editors/lezer-decodal/decodal.grammar` changes.
@@ -149,7 +128,6 @@ npx jsr publish --dry-run
The npm package name is `decodal-codemirror`.
The JSR package name is `@hare/decodal-codemirror`.
JSR currently expects a single SPDX license identifier in `jsr.json`; the CodeMirror package metadata uses `MIT` while the Rust workspace remains dual licensed as `MIT OR Apache-2.0`.
The documentation build still uses the lightweight JavaScript fallback highlighter so Astro can render Markdown without initializing WASM at build time.
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-decodal"
description = "Decodal grammar for tree-sitter"
version = "0.1.0"
version = "0.0.1"
license = "MIT"
readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "decodal"]
+173
View File
@@ -0,0 +1,173 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Decodal contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+4 -2
View File
@@ -1,7 +1,7 @@
{
"name": "@hare/decodal-codemirror",
"version": "0.1.5",
"license": "MIT",
"version": "0.1.6",
"license": "MIT OR Apache-2.0",
"exports": {
".": "./src/mod.ts",
"./format": "./src/format.ts"
@@ -15,6 +15,8 @@
"publish": {
"include": [
"README.md",
"LICENSE-MIT",
"LICENSE-APACHE",
"src/mod.ts",
"src/format.ts",
"src/decodal.js",
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "decodal-codemirror",
"version": "0.1.5",
"version": "0.1.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "decodal-codemirror",
"version": "0.1.5",
"version": "0.1.6",
"license": "MIT OR Apache-2.0",
"devDependencies": {
"@codemirror/language": "^6.12.4",
+3 -1
View File
@@ -1,6 +1,6 @@
{
"name": "decodal-codemirror",
"version": "0.1.5",
"version": "0.1.6",
"description": "CodeMirror 6 language support for Decodal.",
"type": "module",
"license": "MIT OR Apache-2.0",
@@ -28,6 +28,8 @@
"types": "./src/decodal.d.ts",
"files": [
"README.md",
"LICENSE-MIT",
"LICENSE-APACHE",
"src/",
"wasm/decodal_language_tools.js",
"wasm/decodal_language_tools.d.ts",
@@ -0,0 +1,16 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { formatDecodal, initDecodalFormatter } from './format.js';
const wasmPath = new URL('../wasm/decodal_language_tools_bg.wasm', import.meta.url);
test('WASM uses the canonical formatter and is idempotent', async () => {
await initDecodalFormatter({ module_or_path: await readFile(wasmPath) });
const source = 'Server={\n# host\nhost=String default "localhost"; # trailing\n\nport=Int&>0;\n};';
const expected = 'Server = {\n # host\n host = String default "localhost"; # trailing\n\n port = Int & > 0;\n};\n';
assert.deepEqual(formatDecodal(source), { ok: true, source: expected });
assert.deepEqual(formatDecodal(expected), { ok: true, source: expected });
});
+2 -2
View File
@@ -1,8 +1,8 @@
/**
* Decodal source formatting helpers for CodeMirror integrations.
*
* The formatter is backed by WebAssembly generated from the internal Rust
* `decodal-language-tools` crate. Call {@link initDecodalFormatter} once before
* The formatter is backed by WebAssembly generated from the canonical Rust
* `decodal-language-tools` formatter. Call {@link initDecodalFormatter} once before
* using {@link formatDecodal} or {@link formatDecodalCommand}.
*
* @module
Binary file not shown.
+1 -1
View File
@@ -25,7 +25,7 @@
}
},
"../../packages/decodal-codemirror": {
"version": "0.1.5",
"version": "0.1.6",
"license": "MIT OR Apache-2.0",
"devDependencies": {
"@codemirror/language": "^6.12.4",
@@ -1,7 +1,11 @@
import { rmSync, writeFileSync } from 'node:fs';
import { copyFileSync, rmSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
const wasmDir = resolve(import.meta.dirname, '../../../packages/decodal-codemirror/wasm');
const packageDir = resolve(wasmDir, '..');
copyFileSync(resolve(packageDir, '../../LICENSE-MIT'), resolve(packageDir, 'LICENSE-MIT'));
copyFileSync(resolve(packageDir, '../../LICENSE-APACHE'), resolve(packageDir, 'LICENSE-APACHE'));
rmSync(resolve(wasmDir, 'README.md'), { force: true });
rmSync(resolve(wasmDir, 'package.json'), { force: true });
+1 -1
View File
@@ -33,7 +33,7 @@ Production = Server & {
</a>
<ul class="package-list">
<li>decodal-wasm on <a href="https://jsr.io/@hare/decodal-wasm@0.1.4">jsr</a> / <a href="https://www.npmjs.com/package/decodal-wasm">npm</a></li>
<li>decodal-codemirror on <a href="https://jsr.io/@hare/decodal-codemirror@0.1.5">jsr</a> / <a href="https://www.npmjs.com/package/decodal-codemirror">npm</a></li>
<li>decodal-codemirror on <a href="https://jsr.io/@hare/decodal-codemirror@0.1.6">jsr</a> / <a href="https://www.npmjs.com/package/decodal-codemirror">npm</a></li>
</ul>
</section>