Compare commits
25
Commits
d8af980f7d
...
v0.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4b9247c45 | ||
|
|
375bc80a57 | ||
|
|
335ecde816 | ||
|
|
4142fcd46a | ||
|
|
2d06dc3277 | ||
|
|
37237dc1f7 | ||
|
|
2966d5b979 | ||
|
|
ea858ad28e | ||
|
|
871d342e15 | ||
|
|
6d80c66144 | ||
|
|
8e1cb01f52 | ||
|
|
26d8495631 | ||
|
|
c4332ffb9d | ||
|
|
33ea8b94f9 | ||
|
|
720c71157e | ||
|
|
ee031bd2e8 | ||
|
|
a07f4c48aa | ||
|
|
fe127428f9 | ||
|
|
0b76a600b1 | ||
|
|
ada3578a1d | ||
|
|
b8404df047 | ||
|
|
87fef44c68 | ||
|
|
6e2363632b | ||
|
|
c26f9ca50a | ||
|
|
f928028007 |
Generated
+22
-11
@@ -25,23 +25,34 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "decodal"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"decodal-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-core"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal-derive",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-wasm"
|
||||
version = "0.1.0"
|
||||
name = "decodal-cli"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal-core",
|
||||
"decodal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-derive"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-wasm"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal",
|
||||
"serde_json",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
+13
-7
@@ -3,12 +3,18 @@ members = [
|
||||
"crates/decodal-core",
|
||||
"crates/decodal-cli",
|
||||
"crates/decodal-wasm",
|
||||
"crates/decodal-derive",
|
||||
]
|
||||
resolver = "3"
|
||||
resolver = "2"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
strip = true
|
||||
panic = "abort"
|
||||
[workspace.package]
|
||||
version = "0.1.2"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://gitea.hareworks.net/Hare/Decodal"
|
||||
readme = "README.md"
|
||||
|
||||
[workspace.dependencies]
|
||||
serde_json = "1"
|
||||
wasm-bindgen = "0.2"
|
||||
|
||||
+173
@@ -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
@@ -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.
|
||||
@@ -0,0 +1,82 @@
|
||||
# Decodal
|
||||
|
||||
Decodal is a small deterministic DSL for describing, composing, validating, and materializing structured data.
|
||||
|
||||
It is designed around a lightweight Rust library:
|
||||
|
||||
- host-supplied imports through `SourceLoader`
|
||||
- no filesystem access in the library core
|
||||
- concrete and abstract values with constraints and defaults
|
||||
- deterministic expression evaluation
|
||||
- optional regex support behind a Cargo feature
|
||||
- browser playground support through WebAssembly
|
||||
|
||||
## Library crate
|
||||
|
||||
Embedded hosts should depend on `decodal` and provide imports with a `SourceLoader`.
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
decodal = "0.1"
|
||||
```
|
||||
|
||||
## Derive support
|
||||
|
||||
For embedded Rust applications, Decodal can generate a schema and typed decoder from a Rust struct with the `derive` feature.
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
decodal = { version = "0.1", features = ["derive"] }
|
||||
```
|
||||
|
||||
```rust
|
||||
use decodal::{Decodal, DecodalDecode, DecodalSchema, Engine};
|
||||
|
||||
#[derive(Decodal)]
|
||||
struct Service {
|
||||
name: String,
|
||||
#[decodal(gt = 443, default = 8443)]
|
||||
port: i64,
|
||||
#[decodal(rename = "feature.enable", default = true)]
|
||||
feature_enabled: bool,
|
||||
}
|
||||
```
|
||||
|
||||
The derive implements:
|
||||
|
||||
- `DecodalSchema`, which produces a host schema for `Engine::bind_global`
|
||||
- `DecodalDecode`, which converts materialized `Data` into the Rust struct
|
||||
|
||||
## CLI
|
||||
|
||||
A standalone CLI is kept in this repository as the `decodal-cli` workspace package.
|
||||
It builds a `decodal` binary, but it is not the primary crates.io package.
|
||||
|
||||
Run a Decodal file from the repository:
|
||||
|
||||
```sh
|
||||
cargo run -q -p decodal-cli -- examples/advanced/main.dcdl
|
||||
```
|
||||
|
||||
Enable optional regex support when needed:
|
||||
|
||||
```sh
|
||||
cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
|
||||
```
|
||||
|
||||
## Web playground
|
||||
|
||||
The static documentation site and browser playground live under:
|
||||
|
||||
```text
|
||||
site/decodal-site/
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of:
|
||||
|
||||
- Apache License, Version 2.0
|
||||
- MIT license
|
||||
|
||||
at your option.
|
||||
@@ -1,11 +1,23 @@
|
||||
[package]
|
||||
name = "decodal-cli"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "Command-line interface for the Decodal data description language."
|
||||
keywords = ["decodal", "dsl", "config", "cli"]
|
||||
categories = ["command-line-utilities", "config"]
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "decodal"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
path = "src/main.rs"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
regex = ["decodal-core/regex"]
|
||||
regex = ["decodal/regex"]
|
||||
|
||||
[dependencies]
|
||||
decodal-core = { path = "../decodal-core" }
|
||||
decodal = { version = "0.1.2", path = "../decodal-core" }
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{
|
||||
process::ExitCode,
|
||||
};
|
||||
|
||||
use decodal_core::{
|
||||
use decodal::{
|
||||
Data, Diagnostic, DiagnosticKind, Engine, LoadedSource, SourceId, SourceLoader, Span,
|
||||
format_diagnostic_with,
|
||||
};
|
||||
@@ -28,7 +28,7 @@ fn run() -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
"--version" | "-V" => {
|
||||
println!("Decodal {}", decodal_core::version());
|
||||
println!("Decodal {}", decodal::version());
|
||||
Ok(())
|
||||
}
|
||||
"check" => {
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
[package]
|
||||
name = "decodal-core"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
name = "decodal"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "Parser, evaluator, and embedding API for the Decodal data description language."
|
||||
keywords = ["decodal", "dsl", "config", "schema"]
|
||||
categories = ["config", "parser-implementations"]
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = []
|
||||
derive = ["dep:decodal-derive"]
|
||||
regex = ["std", "dep:regex"]
|
||||
|
||||
[dependencies]
|
||||
decodal-derive = { version = "0.1.1", path = "../decodal-derive", optional = true }
|
||||
regex = { version = "1.10", default-features = false, features = ["std", "unicode-perl"], optional = true }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use decodal_core::{Data, EmptyLoader, Engine, HostValue};
|
||||
use decodal::{Data, EmptyLoader, Engine, HostValue};
|
||||
|
||||
fn main() -> decodal_core::Result<()> {
|
||||
fn main() -> decodal::Result<()> {
|
||||
let mut engine = Engine::new(EmptyLoader);
|
||||
|
||||
engine.bind_global(
|
||||
|
||||
@@ -70,7 +70,10 @@ pub fn normalize_constraints(
|
||||
|
||||
if matches!(
|
||||
primitive,
|
||||
Some((PrimitiveType::String | PrimitiveType::Bool, _))
|
||||
Some((
|
||||
PrimitiveType::String | PrimitiveType::Bool | PrimitiveType::Array,
|
||||
_
|
||||
))
|
||||
) && (lower.is_some() || upper.is_some())
|
||||
{
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
|
||||
@@ -63,6 +63,18 @@ impl HostValue {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn object_from_paths<I, N>(fields: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = (N, HostValue)>,
|
||||
N: Into<String>,
|
||||
{
|
||||
let mut root = Vec::new();
|
||||
for (path, value) in fields {
|
||||
insert_path(&mut root, &path.into(), value);
|
||||
}
|
||||
Self::Object(root)
|
||||
}
|
||||
|
||||
pub fn string_type() -> Self {
|
||||
Self::abstract_with_constraint(Constraint::Type(PrimitiveType::String))
|
||||
}
|
||||
@@ -79,6 +91,10 @@ impl HostValue {
|
||||
Self::abstract_with_constraint(Constraint::Type(PrimitiveType::Bool))
|
||||
}
|
||||
|
||||
pub fn array_type() -> Self {
|
||||
Self::abstract_with_constraint(Constraint::Type(PrimitiveType::Array))
|
||||
}
|
||||
|
||||
pub fn builtin_predicate(name: impl Into<String>) -> Self {
|
||||
Self::abstract_with_constraint(Constraint::BuiltinPredicate(name.into()))
|
||||
}
|
||||
@@ -162,3 +178,38 @@ impl HostValue {
|
||||
self.default(Self::bool(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl HostField {
|
||||
pub fn new(name: impl Into<String>, value: HostValue) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_path(fields: &mut Vec<HostField>, path: &str, value: HostValue) {
|
||||
let mut parts = path.splitn(2, '.');
|
||||
let Some(head) = parts.next().filter(|part| !part.is_empty()) else {
|
||||
return;
|
||||
};
|
||||
if let Some(tail) = parts.next() {
|
||||
if let Some(field) = fields.iter_mut().find(|field| field.name == head) {
|
||||
if let HostValue::Object(children) = &mut field.value {
|
||||
insert_path(children, tail, value);
|
||||
} else {
|
||||
let mut children = Vec::new();
|
||||
insert_path(&mut children, tail, value);
|
||||
field.value = HostValue::Object(children);
|
||||
}
|
||||
} else {
|
||||
let mut children = Vec::new();
|
||||
insert_path(&mut children, tail, value);
|
||||
fields.push(HostField::new(head, HostValue::Object(children)));
|
||||
}
|
||||
} else if let Some(field) = fields.iter_mut().find(|field| field.name == head) {
|
||||
field.value = value;
|
||||
} else {
|
||||
fields.push(HostField::new(head, value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1170,6 +1170,7 @@ fn primitive_type(name: &str) -> Option<PrimitiveType> {
|
||||
"Int" => Some(PrimitiveType::Int),
|
||||
"Float" => Some(PrimitiveType::Float),
|
||||
"Bool" => Some(PrimitiveType::Bool),
|
||||
"Array" => Some(PrimitiveType::Array),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -1250,6 +1251,9 @@ fn value_matches_primitive(value: &RuntimeValue, primitive: PrimitiveType) -> bo
|
||||
) | (
|
||||
RuntimeValue::Concrete(ConcreteValue::Bool(_)),
|
||||
PrimitiveType::Bool
|
||||
) | (
|
||||
RuntimeValue::Concrete(ConcreteValue::Array(_)),
|
||||
PrimitiveType::Array
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ pub struct Lexer<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Lexer<'a> {
|
||||
#[cfg(test)]
|
||||
pub fn new(source: &'a str) -> Self {
|
||||
Self::with_source_id(SourceId(0), source)
|
||||
}
|
||||
@@ -93,6 +94,10 @@ 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 {
|
||||
return Ok(Token {
|
||||
|
||||
@@ -7,22 +7,28 @@ pub mod constraints;
|
||||
pub mod diagnostic;
|
||||
pub mod embedding;
|
||||
pub mod eval;
|
||||
pub mod lexer;
|
||||
mod lexer;
|
||||
pub mod module;
|
||||
pub mod parser;
|
||||
pub mod runtime;
|
||||
pub mod span;
|
||||
pub mod typed;
|
||||
|
||||
pub use ast::{Ast, BinaryOp, CompareOp, Expr, ExprId, Field, Literal, Param};
|
||||
pub use constraints::normalize_constraints;
|
||||
#[cfg(feature = "derive")]
|
||||
pub use decodal_derive::Decodal;
|
||||
pub use diagnostic::{Diagnostic, DiagnosticKind, Result};
|
||||
pub use embedding::{HostField, HostValue};
|
||||
pub use eval::{Engine, format_diagnostic_with};
|
||||
pub use lexer::{Lexer, Token, TokenKind};
|
||||
pub use module::{EmptyLoader, LoadedSource, Module, SourceLoader};
|
||||
pub use parser::{ParseOutput, Parser, SourceForm, parse_source, parse_source_with_source_id};
|
||||
pub use runtime::{Constraint, Data, ExprRef, LiteralValue, ModuleId, PrimitiveType, RuntimeValue};
|
||||
pub use span::{SourceId, Span};
|
||||
pub use typed::{
|
||||
DecodalDecode, DecodalSchema, DecodeError, DecodeResult, IntoHostValue, data_at_path,
|
||||
decode_path, prefix_decode_error,
|
||||
};
|
||||
|
||||
pub fn version() -> &'static str {
|
||||
env!("CARGO_PKG_VERSION")
|
||||
|
||||
@@ -79,6 +79,7 @@ pub enum PrimitiveType {
|
||||
Int,
|
||||
Float,
|
||||
Bool,
|
||||
Array,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
use alloc::{format, string::String, vec::Vec};
|
||||
|
||||
use crate::{Data, HostValue};
|
||||
|
||||
pub trait DecodalSchema {
|
||||
fn decodal_schema() -> HostValue;
|
||||
}
|
||||
|
||||
pub trait DecodalDecode: Sized {
|
||||
fn decodal_decode(data: &Data) -> DecodeResult<Self>;
|
||||
}
|
||||
|
||||
pub trait IntoHostValue {
|
||||
fn into_host_value(self) -> HostValue;
|
||||
}
|
||||
|
||||
pub type DecodeResult<T> = core::result::Result<T, DecodeError>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct DecodeError {
|
||||
pub path: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl DecodeError {
|
||||
pub fn new(path: impl Into<String>, message: impl Into<String>) -> Self {
|
||||
Self {
|
||||
path: path.into(),
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn at_type(path: &str, expected: &'static str) -> Self {
|
||||
Self::new(path, format!("expected {expected}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for DecodeError {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
if self.path.is_empty() {
|
||||
write!(f, "{}", self.message)
|
||||
} else {
|
||||
write!(f, "{}: {}", self.path, self.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for DecodeError {}
|
||||
|
||||
pub fn decode_path<T: DecodalDecode>(data: &Data, path: &str) -> DecodeResult<T> {
|
||||
let value = data_at_path(data, path).ok_or_else(|| DecodeError::new(path, "missing field"))?;
|
||||
T::decodal_decode(value).map_err(|error| prefix_error(path, error))
|
||||
}
|
||||
|
||||
pub fn data_at_path<'a>(data: &'a Data, path: &str) -> Option<&'a Data> {
|
||||
let mut current = data;
|
||||
for part in path.split('.') {
|
||||
if part.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let Data::Object(fields) = current else {
|
||||
return None;
|
||||
};
|
||||
current = &fields.iter().find(|field| field.name == part)?.value;
|
||||
}
|
||||
Some(current)
|
||||
}
|
||||
|
||||
pub fn prefix_decode_error(path: &str, error: DecodeError) -> DecodeError {
|
||||
prefix_error(path, error)
|
||||
}
|
||||
|
||||
fn prefix_error(path: &str, mut error: DecodeError) -> DecodeError {
|
||||
if error.path.is_empty() {
|
||||
error.path = String::from(path);
|
||||
} else if !path.is_empty() {
|
||||
error.path = format!("{path}.{}", error.path);
|
||||
}
|
||||
error
|
||||
}
|
||||
|
||||
impl DecodalSchema for String {
|
||||
fn decodal_schema() -> HostValue {
|
||||
HostValue::string_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodalDecode for String {
|
||||
fn decodal_decode(data: &Data) -> DecodeResult<Self> {
|
||||
match data {
|
||||
Data::String(value) => Ok(value.clone()),
|
||||
_ => Err(DecodeError::at_type("", "String")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHostValue for String {
|
||||
fn into_host_value(self) -> HostValue {
|
||||
HostValue::string(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHostValue for &str {
|
||||
fn into_host_value(self) -> HostValue {
|
||||
HostValue::string(self)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_int_decode {
|
||||
($($ty:ty),* $(,)?) => {
|
||||
$(
|
||||
impl DecodalSchema for $ty {
|
||||
fn decodal_schema() -> HostValue {
|
||||
HostValue::int_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodalDecode for $ty {
|
||||
fn decodal_decode(data: &Data) -> DecodeResult<Self> {
|
||||
match data {
|
||||
Data::Int(value) => <$ty>::try_from(*value)
|
||||
.map_err(|_| DecodeError::new("", "integer value is out of range")),
|
||||
_ => Err(DecodeError::at_type("", "Int")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHostValue for $ty {
|
||||
fn into_host_value(self) -> HostValue {
|
||||
HostValue::int(self as i64)
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
impl_int_decode!(i8, i16, i32, i64, u8, u16, u32);
|
||||
|
||||
impl DecodalSchema for f64 {
|
||||
fn decodal_schema() -> HostValue {
|
||||
HostValue::float_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodalDecode for f64 {
|
||||
fn decodal_decode(data: &Data) -> DecodeResult<Self> {
|
||||
match data {
|
||||
Data::Float(value) => Ok(*value),
|
||||
Data::Int(value) => Ok(*value as f64),
|
||||
_ => Err(DecodeError::at_type("", "Float")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHostValue for f64 {
|
||||
fn into_host_value(self) -> HostValue {
|
||||
HostValue::float(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodalSchema for f32 {
|
||||
fn decodal_schema() -> HostValue {
|
||||
HostValue::float_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodalDecode for f32 {
|
||||
fn decodal_decode(data: &Data) -> DecodeResult<Self> {
|
||||
f64::decodal_decode(data).map(|value| value as f32)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHostValue for f32 {
|
||||
fn into_host_value(self) -> HostValue {
|
||||
HostValue::float(f64::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodalSchema for bool {
|
||||
fn decodal_schema() -> HostValue {
|
||||
HostValue::bool_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl DecodalDecode for bool {
|
||||
fn decodal_decode(data: &Data) -> DecodeResult<Self> {
|
||||
match data {
|
||||
Data::Bool(value) => Ok(*value),
|
||||
_ => Err(DecodeError::at_type("", "Bool")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHostValue for bool {
|
||||
fn into_host_value(self) -> HostValue {
|
||||
HostValue::bool(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DecodalSchema for Vec<T> {
|
||||
fn decodal_schema() -> HostValue {
|
||||
HostValue::array_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DecodalDecode> DecodalDecode for Vec<T> {
|
||||
fn decodal_decode(data: &Data) -> DecodeResult<Self> {
|
||||
match data {
|
||||
Data::Array(items) => items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, item)| {
|
||||
T::decodal_decode(item)
|
||||
.map_err(|error| prefix_error(&format!("[{index}]"), error))
|
||||
})
|
||||
.collect(),
|
||||
_ => Err(DecodeError::at_type("", "Array")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IntoHostValue> IntoHostValue for Vec<T> {
|
||||
fn into_host_value(self) -> HostValue {
|
||||
HostValue::array(self.into_iter().map(IntoHostValue::into_host_value))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "decodal-derive"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "Derive macro for generating Decodal schemas and typed decoders from Rust structs."
|
||||
keywords = ["decodal", "derive", "proc-macro", "schema"]
|
||||
categories = ["config", "development-tools::procedural-macro-helpers"]
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
syn = { version = "2", features = ["full"] }
|
||||
|
||||
[dev-dependencies]
|
||||
decodal = { version = "0.1", path = "../decodal-core" }
|
||||
@@ -0,0 +1,212 @@
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{
|
||||
Data, DeriveInput, Expr, Fields, LitStr, Result, Type, parse_macro_input, spanned::Spanned,
|
||||
};
|
||||
|
||||
#[proc_macro_derive(Decodal, attributes(decodal))]
|
||||
pub fn derive_decodal(input: TokenStream) -> TokenStream {
|
||||
match expand_decodal(parse_macro_input!(input as DeriveInput)) {
|
||||
Ok(tokens) => tokens.into(),
|
||||
Err(error) => error.to_compile_error().into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_decodal(input: DeriveInput) -> Result<TokenStream2> {
|
||||
let name = input.ident;
|
||||
let fields = match input.data {
|
||||
Data::Struct(data) => match data.fields {
|
||||
Fields::Named(fields) => fields.named,
|
||||
_ => {
|
||||
return Err(syn::Error::new(
|
||||
data.struct_token.span(),
|
||||
"Decodal derive supports structs with named fields only",
|
||||
));
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return Err(syn::Error::new(
|
||||
name.span(),
|
||||
"Decodal derive supports structs only",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let mut schema_fields = Vec::new();
|
||||
let mut decode_fields = Vec::new();
|
||||
|
||||
for field in fields {
|
||||
let ident = field.ident.expect("named field");
|
||||
let ty = field.ty;
|
||||
let attrs = FieldAttrs::from_attrs(&field.attrs, &ident.to_string())?;
|
||||
let path = attrs.rename.clone();
|
||||
let schema_value = schema_expr(&ty, &attrs)?;
|
||||
let decode_value = decode_expr(&ty, &path, &attrs);
|
||||
|
||||
schema_fields.push(quote! {
|
||||
(#path, { #schema_value })
|
||||
});
|
||||
decode_fields.push(quote! {
|
||||
#ident: #decode_value
|
||||
});
|
||||
}
|
||||
|
||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
Ok(quote! {
|
||||
impl #impl_generics ::decodal::DecodalSchema for #name #ty_generics #where_clause {
|
||||
fn decodal_schema() -> ::decodal::HostValue {
|
||||
::decodal::HostValue::object_from_paths([
|
||||
#(#schema_fields),*
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
impl #impl_generics ::decodal::DecodalDecode for #name #ty_generics #where_clause {
|
||||
fn decodal_decode(data: &::decodal::Data) -> ::decodal::DecodeResult<Self> {
|
||||
Ok(Self {
|
||||
#(#decode_fields),*
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct FieldAttrs {
|
||||
rename: String,
|
||||
default: Option<DefaultAttr>,
|
||||
constraints: Vec<ConstraintAttr>,
|
||||
}
|
||||
|
||||
impl FieldAttrs {
|
||||
fn from_attrs(attrs: &[syn::Attribute], fallback_name: &str) -> Result<Self> {
|
||||
let mut output = Self {
|
||||
rename: fallback_name.to_string(),
|
||||
..Self::default()
|
||||
};
|
||||
|
||||
for attr in attrs {
|
||||
if !attr.path().is_ident("decodal") {
|
||||
continue;
|
||||
}
|
||||
attr.parse_nested_meta(|meta| {
|
||||
if meta.path.is_ident("rename") {
|
||||
let value: LitStr = meta.value()?.parse()?;
|
||||
output.rename = value.value();
|
||||
return Ok(());
|
||||
}
|
||||
if meta.path.is_ident("default") {
|
||||
if meta.input.peek(syn::Token![=]) {
|
||||
let expr: Expr = meta.value()?.parse()?;
|
||||
output.default = Some(DefaultAttr::Expr(expr));
|
||||
} else {
|
||||
output.default = Some(DefaultAttr::Default);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(kind) = ConstraintKind::from_path(&meta.path) {
|
||||
let expr: Expr = meta.value()?.parse()?;
|
||||
output.constraints.push(ConstraintAttr { kind, expr });
|
||||
return Ok(());
|
||||
}
|
||||
Err(meta.error("unsupported decodal attribute"))
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
|
||||
enum DefaultAttr {
|
||||
Default,
|
||||
Expr(Expr),
|
||||
}
|
||||
|
||||
struct ConstraintAttr {
|
||||
kind: ConstraintKind,
|
||||
expr: Expr,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ConstraintKind {
|
||||
Gt,
|
||||
Gte,
|
||||
Lt,
|
||||
Lte,
|
||||
}
|
||||
|
||||
impl ConstraintKind {
|
||||
fn from_path(path: &syn::Path) -> Option<Self> {
|
||||
if path.is_ident("gt") {
|
||||
Some(Self::Gt)
|
||||
} else if path.is_ident("gte") {
|
||||
Some(Self::Gte)
|
||||
} else if path.is_ident("lt") {
|
||||
Some(Self::Lt)
|
||||
} else if path.is_ident("lte") {
|
||||
Some(Self::Lte)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn method(self) -> syn::Ident {
|
||||
match self {
|
||||
Self::Gt => format_ident!("gt"),
|
||||
Self::Gte => format_ident!("gte"),
|
||||
Self::Lt => format_ident!("lt"),
|
||||
Self::Lte => format_ident!("lte"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn schema_expr(ty: &Type, attrs: &FieldAttrs) -> Result<TokenStream2> {
|
||||
let mut tokens = quote! {
|
||||
let mut schema = <#ty as ::decodal::DecodalSchema>::decodal_schema();
|
||||
};
|
||||
|
||||
for constraint in &attrs.constraints {
|
||||
let method = constraint.kind.method();
|
||||
let expr = &constraint.expr;
|
||||
tokens.extend(quote! {
|
||||
schema = schema.#method(#expr);
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(default) = &attrs.default {
|
||||
let default_expr = match default {
|
||||
DefaultAttr::Default => quote! { <#ty as ::core::default::Default>::default() },
|
||||
DefaultAttr::Expr(expr) => quote! { (#expr) },
|
||||
};
|
||||
tokens.extend(quote! {
|
||||
schema = schema
|
||||
.default(::decodal::IntoHostValue::into_host_value(#default_expr))
|
||||
.expect("Decodal derive generated a valid default");
|
||||
});
|
||||
}
|
||||
|
||||
tokens.extend(quote! { schema });
|
||||
Ok(tokens)
|
||||
}
|
||||
|
||||
fn decode_expr(ty: &Type, path: &str, attrs: &FieldAttrs) -> TokenStream2 {
|
||||
let missing = if let Some(default) = &attrs.default {
|
||||
match default {
|
||||
DefaultAttr::Default => quote! { <#ty as ::core::default::Default>::default() },
|
||||
DefaultAttr::Expr(expr) => quote! { ::core::convert::Into::into(#expr) },
|
||||
}
|
||||
} else {
|
||||
quote! { return Err(::decodal::DecodeError::new(#path, "missing field")); }
|
||||
};
|
||||
|
||||
quote! {
|
||||
if let Some(value) = ::decodal::data_at_path(data, #path) {
|
||||
<#ty as ::decodal::DecodalDecode>::decodal_decode(value)
|
||||
.map_err(|error| ::decodal::prefix_decode_error(#path, error))?
|
||||
} else {
|
||||
#missing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
use decodal::{Data, DecodalDecode, DecodalSchema, EmptyLoader, Engine};
|
||||
use decodal_derive::Decodal;
|
||||
|
||||
#[derive(Debug, PartialEq, Decodal)]
|
||||
struct Service {
|
||||
name: String,
|
||||
#[decodal(gt = 443, default = 8443)]
|
||||
port: i64,
|
||||
#[decodal(default = true, rename = "feature.enable")]
|
||||
feature_enabled: bool,
|
||||
#[decodal(default)]
|
||||
tags: Vec<String>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derives_schema_and_decode() {
|
||||
let mut engine = Engine::new(EmptyLoader);
|
||||
engine
|
||||
.bind_global("Service", Service::decodal_schema())
|
||||
.unwrap();
|
||||
let module = engine
|
||||
.add_root_source(
|
||||
"test",
|
||||
"test",
|
||||
r#"
|
||||
Service & {
|
||||
name = "api";
|
||||
port = 9443;
|
||||
feature.enable = false;
|
||||
tags = ["web", "prod"];
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let value = engine.eval_module(module).unwrap();
|
||||
let data = engine.materialize(&value).unwrap();
|
||||
let service = Service::decodal_decode(&data).unwrap();
|
||||
assert_eq!(
|
||||
service,
|
||||
Service {
|
||||
name: "api".into(),
|
||||
port: 9443,
|
||||
feature_enabled: false,
|
||||
tags: vec!["web".into(), "prod".into()],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn defaults_are_available_in_schema() {
|
||||
let mut engine = Engine::new(EmptyLoader);
|
||||
engine
|
||||
.bind_global("Service", Service::decodal_schema())
|
||||
.unwrap();
|
||||
let module = engine
|
||||
.add_root_source(
|
||||
"test",
|
||||
"test",
|
||||
r#"
|
||||
Service & {
|
||||
name = "api";
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let value = engine.eval_module(module).unwrap();
|
||||
let data = engine.materialize(&value).unwrap();
|
||||
let service = Service::decodal_decode(&data).unwrap();
|
||||
assert_eq!(service.port, 8443);
|
||||
assert!(service.feature_enabled);
|
||||
assert!(service.tags.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decode_reports_field_path() {
|
||||
let data = Data::Object(vec![]);
|
||||
let error = Service::decodal_decode(&data).unwrap_err();
|
||||
assert_eq!(error.path, "name");
|
||||
}
|
||||
@@ -1,15 +1,23 @@
|
||||
[package]
|
||||
name = "decodal-wasm"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "WebAssembly wrapper for evaluating Decodal in browser playgrounds."
|
||||
keywords = ["decodal", "wasm", "dsl", "config"]
|
||||
categories = ["wasm", "config"]
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
decodal-core = { path = "../decodal-core" }
|
||||
serde_json = "1"
|
||||
wasm-bindgen = "0.2"
|
||||
decodal = { version = "0.1.2", path = "../decodal-core" }
|
||||
serde_json.workspace = true
|
||||
wasm-bindgen.workspace = true
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use decodal_core::{
|
||||
use decodal::{
|
||||
Data, Diagnostic, DiagnosticKind, EmptyLoader, Engine, LoadedSource, SourceId, SourceLoader,
|
||||
Span, format_diagnostic_with,
|
||||
};
|
||||
@@ -81,7 +81,7 @@ impl SourceLoader for VirtualLoader {
|
||||
&mut self,
|
||||
current_key: Option<&str>,
|
||||
specifier: &str,
|
||||
) -> decodal_core::Result<LoadedSource> {
|
||||
) -> decodal::Result<LoadedSource> {
|
||||
let key = resolve_import(current_key, specifier).ok_or_else(|| {
|
||||
Diagnostic::new(
|
||||
DiagnosticKind::Import,
|
||||
@@ -139,7 +139,7 @@ fn normalize_path(path: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn format_diagnostic_with_root(diagnostic: &decodal_core::Diagnostic, root_name: &str) -> String {
|
||||
fn format_diagnostic_with_root(diagnostic: &decodal::Diagnostic, root_name: &str) -> String {
|
||||
format_diagnostic_with(diagnostic, |source| {
|
||||
(source == SourceId(0)).then_some(root_name)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
# Components
|
||||
|
||||
Decodal is split into a small runtime core and separate syntax tooling components.
|
||||
The public surface is intentionally organized by use case: execute Decodal with Rust or WebAssembly, edit Decodal on the Web with Lezer and CodeMirror, and integrate Decodal into general-purpose editors with Tree-sitter.
|
||||
|
||||
## Runtime components
|
||||
|
||||
### Rust crate
|
||||
|
||||
The `decodal` crate is the primary Rust runtime and embedding API.
|
||||
It owns parsing, evaluation, materialization, diagnostics, host-provided values, and schema/decode traits.
|
||||
Rust applications should use this crate when they want to load Decodal source, evaluate it, or embed Decodal into a host program.
|
||||
|
||||
Important paths:
|
||||
|
||||
```text
|
||||
crates/decodal-core/
|
||||
crates/decodal-derive/
|
||||
```
|
||||
|
||||
`decodal-derive` provides optional derive macros for Rust struct integration.
|
||||
It is a companion to the runtime crate rather than an editor or syntax-highlighting component.
|
||||
|
||||
### WebAssembly package
|
||||
|
||||
`decodal-wasm` exposes the runtime to browsers.
|
||||
The documentation site playground uses it to evaluate Decodal entirely in the browser.
|
||||
|
||||
Important paths:
|
||||
|
||||
```text
|
||||
crates/decodal-wasm/
|
||||
site/decodal-site/src/wasm/
|
||||
```
|
||||
|
||||
The generated files in `site/decodal-site/src/wasm/` are committed so the site can build without requiring every consumer to run `wasm-pack` first.
|
||||
The WebAssembly package is for execution, not syntax highlighting.
|
||||
|
||||
## Web editor components
|
||||
|
||||
The Web playground editor uses CodeMirror 6 with a generated Lezer parser.
|
||||
This is the source of syntax highlighting, folding, indentation, and editor syntax tree behavior in the browser UI.
|
||||
|
||||
Important paths:
|
||||
|
||||
```text
|
||||
editors/lezer-decodal/decodal.grammar
|
||||
packages/decodal-codemirror/src/decodal.js
|
||||
packages/decodal-codemirror/src/decodal-parser.js
|
||||
packages/decodal-codemirror/src/decodal-parser.terms.js
|
||||
```
|
||||
|
||||
The npm package is `decodal-codemirror`.
|
||||
The JSR package is `@hare/decodal-codemirror`.
|
||||
|
||||
The Lezer grammar is derived from the canonical grammar documentation, but it is not a literal copy of the EBNF.
|
||||
Precedence and token conflict handling are represented in the Lezer grammar in the form CodeMirror needs.
|
||||
|
||||
## General editor components
|
||||
|
||||
Tree-sitter is the portable editor-integration grammar.
|
||||
Editors such as Zed, Neovim, Helix, and Emacs should consume this component when they need Decodal parsing or highlighting outside the Web playground.
|
||||
|
||||
Important paths:
|
||||
|
||||
```text
|
||||
editors/tree-sitter-decodal/grammar.js
|
||||
editors/tree-sitter-decodal/queries/highlights.scm
|
||||
editors/tree-sitter-decodal/queries/locals.scm
|
||||
editors/tree-sitter-decodal/src/
|
||||
```
|
||||
|
||||
The generated parser sources under `editors/tree-sitter-decodal/src/` are committed so editor integrations can consume the grammar without regenerating it first.
|
||||
|
||||
## Canonical grammar
|
||||
|
||||
The human-readable grammar lives in:
|
||||
|
||||
```text
|
||||
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
|
||||
|
||||
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:
|
||||
|
||||
- Rust execution and embedding: `decodal`
|
||||
- Browser execution: `decodal-wasm`
|
||||
- Web editor syntax: Lezer / CodeMirror
|
||||
- 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.
|
||||
@@ -59,8 +59,9 @@ Config = MyConfig & {
|
||||
|
||||
## default の合成
|
||||
|
||||
初期方針では、`&` による異なる default 同士の合成は conflict とする。
|
||||
同じ default は同一候補として扱ってよい。
|
||||
`&` で片方だけが default を持つ場合、その default を保持する。
|
||||
同じ thunk 由来の default 同士は同一 default として保持する。
|
||||
異なる default 同士は conflict とする。
|
||||
|
||||
```text
|
||||
merge_default(None, None) -> None
|
||||
|
||||
@@ -17,14 +17,14 @@ let / function env
|
||||
```
|
||||
|
||||
Module top-level bindings shadow prelude bindings.
|
||||
Primitive type names such as `String`, `Int`, `Float`, and `Bool` are handled before environment lookup, so they are reserved and cannot be shadowed by host bindings.
|
||||
Primitive type names such as `String`, `Int`, `Float`, `Bool`, and `Array` are handled before environment lookup, so they are reserved and cannot be shadowed by host bindings.
|
||||
|
||||
## Global bindings
|
||||
|
||||
The host can bind values before adding or evaluating user sources.
|
||||
|
||||
```rust
|
||||
use decodal_core::{EmptyLoader, Engine, HostValue};
|
||||
use decodal::{EmptyLoader, Engine, HostValue};
|
||||
|
||||
let mut engine = Engine::new(EmptyLoader);
|
||||
|
||||
@@ -87,6 +87,46 @@ Concrete(Object {
|
||||
|
||||
This matches the runtime model used for Decodal source-defined schema objects.
|
||||
|
||||
## Typed Rust integration
|
||||
|
||||
Hosts can enable the `derive` feature on `decodal` to keep a Rust struct, the Decodal schema, and the decoded result in sync.
|
||||
The derive implements two traits from the `decodal` crate:
|
||||
|
||||
- `DecodalSchema`: builds a `HostValue` schema that can be passed to `Engine::bind_global`.
|
||||
- `DecodalDecode`: decodes materialized `Data` back into the Rust type.
|
||||
|
||||
```rust
|
||||
use decodal::{Decodal, DecodalDecode, DecodalSchema, EmptyLoader, Engine};
|
||||
|
||||
#[derive(Decodal)]
|
||||
struct Service {
|
||||
name: String,
|
||||
|
||||
#[decodal(gt = 443, default = 8443)]
|
||||
port: i64,
|
||||
|
||||
#[decodal(rename = "feature.enable", default = true)]
|
||||
feature_enabled: bool,
|
||||
}
|
||||
|
||||
let mut engine = Engine::new(EmptyLoader);
|
||||
engine.bind_global("Service", Service::decodal_schema())?;
|
||||
|
||||
let value = engine.eval_module(module)?;
|
||||
let data = engine.materialize(&value)?;
|
||||
let service = Service::decodal_decode(&data)?;
|
||||
```
|
||||
|
||||
Supported field attributes are intentionally small:
|
||||
|
||||
- `rename = "path.to.field"`
|
||||
- `default`
|
||||
- `default = value`
|
||||
- numeric constraints: `gt`, `gte`, `lt`, `lte`
|
||||
|
||||
The derive does not add host callbacks or reflection.
|
||||
It only generates schema construction and typed decoding code.
|
||||
|
||||
## SourceLoader and prelude together
|
||||
|
||||
`SourceLoader` and host prelude bindings are independent mechanisms.
|
||||
|
||||
@@ -37,7 +37,7 @@ primitive type conflict や明らかな numeric bound conflict は合成時に
|
||||
|
||||
## Core defaults
|
||||
|
||||
`decodal-core` defaults to `std` only.
|
||||
`decodal` defaults to `std` only.
|
||||
|
||||
```toml
|
||||
[features]
|
||||
@@ -46,7 +46,7 @@ std = []
|
||||
regex = ["std", "dep:regex"]
|
||||
```
|
||||
|
||||
Building `decodal-core` with `--no-default-features` keeps the core in `no_std + alloc` mode and avoids optional dependencies.
|
||||
Building `decodal` with `--no-default-features` keeps the core in `no_std + alloc` mode and avoids optional dependencies.
|
||||
|
||||
## Regex
|
||||
|
||||
@@ -54,7 +54,7 @@ Regex constraints are implemented behind the `regex` feature.
|
||||
When the feature is disabled, regex constraints parse and compose, but validating a concrete value against them returns an unsupported feature diagnostic.
|
||||
|
||||
```sh
|
||||
cargo run -q -p decodal --features regex -- examples/regex/main.dcdl
|
||||
cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
|
||||
```
|
||||
|
||||
Regex constraints are accumulated during `&` composition.
|
||||
@@ -63,5 +63,5 @@ Concrete strings must match every regex constraint attached to the abstract valu
|
||||
|
||||
## CLI features
|
||||
|
||||
`decodal-cli` exposes a matching `regex` feature that enables `decodal-core/regex`.
|
||||
`decodal-cli` exposes a matching `regex` feature that enables `decodal/regex`.
|
||||
The feature is not enabled by default so the default CLI binary remains small.
|
||||
|
||||
@@ -84,5 +84,5 @@ module root や field は thunk として保持され、参照されたときだ
|
||||
関数引数は thunk として関数の environment に束縛する。
|
||||
関数本体で引数が参照されたときだけ force する。
|
||||
|
||||
任意の関数呼び出し結果をグローバルに memoize する必要はない。
|
||||
関数呼び出し結果そのものはグローバルには memoize しない。
|
||||
field に束縛された関数呼び出し結果は、その field thunk の評価結果として memoize される。
|
||||
|
||||
@@ -9,17 +9,46 @@ Run the normal Rust checks from the repository root.
|
||||
```sh
|
||||
cargo fmt --check
|
||||
cargo test
|
||||
cargo check -p decodal-core --no-default-features
|
||||
cargo check -p decodal --no-default-features
|
||||
nix flake check
|
||||
```
|
||||
|
||||
Regex support is optional and should be tested explicitly when touched.
|
||||
|
||||
```sh
|
||||
cargo test -p decodal-core --features regex
|
||||
cargo run -q -p decodal --features regex -- examples/regex/main.dcdl
|
||||
cargo test -p decodal --features regex
|
||||
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` and the Rust source crate `decodal-wasm` are not published to crates.io.
|
||||
The generated WebAssembly package under `site/decodal-site/src/wasm/` is published to npm and JSR.
|
||||
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`.
|
||||
|
||||
## Web site and playground
|
||||
|
||||
The Astro documentation site and browser playground are kept in:
|
||||
@@ -36,8 +65,13 @@ Important files:
|
||||
```text
|
||||
site/decodal-site/src/pages/docs/[...slug].astro
|
||||
site/decodal-site/src/pages/playground.astro
|
||||
site/decodal-site/src/scripts/playground.js
|
||||
site/decodal-site/src/scripts/playground-examples.js
|
||||
site/decodal-site/src/layouts/ManualLayout.astro
|
||||
site/decodal-site/src/lib/docs.js
|
||||
site/decodal-site/src/lib/highlight.js
|
||||
packages/decodal-codemirror/src/decodal.js
|
||||
packages/decodal-codemirror/src/decodal-parser.js
|
||||
crates/decodal-wasm/src/lib.rs
|
||||
```
|
||||
|
||||
@@ -58,6 +92,51 @@ site/decodal-site/src/wasm/
|
||||
|
||||
These generated files are committed so the site can be built without requiring every consumer to regenerate the wasm package first.
|
||||
|
||||
Publish the generated WebAssembly package from its package directory:
|
||||
|
||||
```sh
|
||||
cd site/decodal-site/src/wasm
|
||||
npm publish
|
||||
npx jsr publish
|
||||
```
|
||||
|
||||
Run dry-runs first when preparing a release:
|
||||
|
||||
```sh
|
||||
npm pack --dry-run
|
||||
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.
|
||||
|
||||
Publish the CodeMirror package from its package directory:
|
||||
|
||||
```sh
|
||||
cd packages/decodal-codemirror
|
||||
npm install
|
||||
npm publish
|
||||
npx jsr publish
|
||||
```
|
||||
|
||||
Run dry-runs first when preparing a release:
|
||||
|
||||
```sh
|
||||
npm install
|
||||
npm pack --dry-run
|
||||
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.
|
||||
|
||||
To run the site locally:
|
||||
|
||||
```sh
|
||||
@@ -72,7 +151,8 @@ cd site/decodal-site
|
||||
npm run deploy
|
||||
```
|
||||
|
||||
The deploy script runs `npm run build` and then uploads `dist/` to the Pages project named `decodal-site`.
|
||||
The deploy script runs `npm run build` and then uploads `dist/` to the Pages project named `decodal-site` on branch `master`.
|
||||
Cloudflare Pages treats this as production when the project production branch is `master`.
|
||||
Use `CLOUDFLARE_PROJECT_NAME` when deploying to a differently named Pages project.
|
||||
|
||||
```sh
|
||||
@@ -129,12 +209,18 @@ The generated parser files under `editors/tree-sitter-decodal/src/` are committe
|
||||
|
||||
When the Decodal syntax changes:
|
||||
|
||||
1. Update `grammar.js`.
|
||||
2. Run `npx tree-sitter generate`.
|
||||
3. Add or update corpus tests in `corpus/`.
|
||||
4. Update highlight queries in `queries/highlights.scm` if token names changed.
|
||||
5. Run `npx tree-sitter test`.
|
||||
6. Run Rust checks from the repository root if the language parser or examples also changed.
|
||||
1. Update the canonical EBNF in `doc/manual/souce/language/grammar.md`.
|
||||
2. Update the Rust parser/lexer as needed.
|
||||
3. Update `editors/tree-sitter-decodal/grammar.js` and run `npx tree-sitter generate` / `npx tree-sitter test`.
|
||||
4. Update `editors/lezer-decodal/decodal.grammar` and regenerate the CodeMirror parser:
|
||||
|
||||
```sh
|
||||
cd site/decodal-site
|
||||
npx lezer-generator ../../editors/lezer-decodal/decodal.grammar -o ../../packages/decodal-codemirror/src/decodal-parser.js
|
||||
```
|
||||
|
||||
5. Add or update corpus/tests/examples.
|
||||
6. Run Rust and site checks from the repository root.
|
||||
|
||||
## Development shell
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ Decodal は Deferred Constraint Data Language、略称 DCDL のプロジェク
|
||||
## 目次
|
||||
|
||||
1. [Introduction](./introduction.md)
|
||||
2. [Language Specification](./language/index.md)
|
||||
2. [Components](./components.md)
|
||||
3. [Language Specification](./language/index.md)
|
||||
1. [Lexical Structure and Syntax](./language/syntax.md)
|
||||
2. [Value](./language/value/index.md)
|
||||
1. [String](./language/value/string.md)
|
||||
@@ -35,7 +36,7 @@ Decodal は Deferred Constraint Data Language、略称 DCDL のプロジェク
|
||||
9. [Materialization and Errors](./language/materialization-and-errors.md)
|
||||
10. [Naming Conventions](./language/naming.md)
|
||||
11. [Examples](./language/examples.md)
|
||||
3. [Implementation Design](./design/index.md)
|
||||
4. [Implementation Design](./design/index.md)
|
||||
1. [Execution Pipeline](./design/execution-pipeline.md)
|
||||
2. [Runtime Model](./design/runtime-model.md)
|
||||
3. [Thunk and Lazy Evaluation](./design/thunk-and-lazy-evaluation.md)
|
||||
@@ -43,5 +44,5 @@ Decodal は Deferred Constraint Data Language、略称 DCDL のプロジェク
|
||||
5. [Diagnostics and Fallback](./design/diagnostics-and-fallback.md)
|
||||
6. [Embedding API](./design/embedding-api.md)
|
||||
7. [Features](./design/features.md)
|
||||
4. [Development](./development.md)
|
||||
5. [Open Issues](./open-issues.md)
|
||||
5. [Development](./development.md)
|
||||
6. [Open Issues](./open-issues.md)
|
||||
|
||||
@@ -188,11 +188,12 @@ RuntimeValue =
|
||||
|
||||
## default の合成
|
||||
|
||||
同じフィールドに複数の `default` が合成された場合の詳細規則は未確定である。
|
||||
現時点の単純な方針は以下である。
|
||||
`default` の合成規則は以下である。
|
||||
|
||||
- `&` による default 同士の衝突はエラーにする。
|
||||
- 同一 default 値は許可してよい。
|
||||
- `//` による patch では右辺 default が左辺 default を置き換える。
|
||||
- `&` で片方だけが default を持つ場合、その default を保持する。
|
||||
- `&` で両方が異なる default を持つ場合、conflict になる。
|
||||
- `Abstract & Concrete` が成功した場合、結果は concrete value になり default は消える。
|
||||
- `//` では右辺が左辺を置き換える。object/object の場合は field ごとに再帰 patch されるため、右辺 field の default が左辺 field の default を置き換える。
|
||||
|
||||
この方針により、`&` は制約を保った合成、`//` は上書き操作として説明できる。
|
||||
`default` thunk は materialize 時に必要になった時点で評価する。
|
||||
評価された default value は、同じ abstract value に残っている制約を満たす必要がある。
|
||||
|
||||
@@ -74,5 +74,5 @@ Error 評価失敗
|
||||
関数引数は thunk として渡せる。
|
||||
関数本体内で引数が参照されたときに評価する。
|
||||
|
||||
任意の関数呼び出し結果をグローバルに memoize することは必須ではない。
|
||||
関数呼び出し結果そのものはグローバルには memoize しない。
|
||||
ただし、フィールドに束縛された呼び出し結果は、そのフィールド thunk の評価結果として memoize される。
|
||||
|
||||
@@ -5,21 +5,19 @@
|
||||
## 基本的な設定スキーマ
|
||||
|
||||
```dcdl
|
||||
rec {
|
||||
Host = IPv4Address;
|
||||
Host = IPv4Address;
|
||||
|
||||
Port = Int & >= 1 & <= 65535;
|
||||
NarrowedPort = Port & > 443;
|
||||
Port = Int & >= 1 & <= 65535;
|
||||
NarrowedPort = Port & > 443;
|
||||
|
||||
MyConfig = {
|
||||
host = Host;
|
||||
port = NarrowedPort default 8080;
|
||||
feature_hoge = {
|
||||
enable = Bool default true;
|
||||
fuga = Int default 10;
|
||||
};
|
||||
MyConfig = {
|
||||
host = Host;
|
||||
port = NarrowedPort default 8080;
|
||||
feature_hoge = {
|
||||
enable = Bool default true;
|
||||
fuga = Int default 10;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
NewConfig = MyConfig & {
|
||||
host = "127.0.0.1";
|
||||
@@ -33,28 +31,20 @@ disabled_config = NewConfig & {
|
||||
enabled_config = NewConfig;
|
||||
```
|
||||
|
||||
## 関数と文字列生成
|
||||
## 関数と制約
|
||||
|
||||
```dcdl
|
||||
let
|
||||
maybe_hw = String & /Hello! .*/;
|
||||
part = {
|
||||
greet = String;
|
||||
target = String;
|
||||
};
|
||||
mk_hw = (part: part) =>
|
||||
maybe_hw & "${part.greet}! ${part.target}";
|
||||
Port = Int & >= 1 & <= 65535;
|
||||
add_offset = (base: Port, offset: Int) => base + offset;
|
||||
in
|
||||
mk_hw({
|
||||
greet = "Hello";
|
||||
target = "World";
|
||||
})
|
||||
add_offset(8000, 80)
|
||||
```
|
||||
|
||||
評価結果:
|
||||
|
||||
```text
|
||||
"Hello! World"
|
||||
8080
|
||||
```
|
||||
|
||||
## match
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
function call expression は、関数値を引数に適用する式である。
|
||||
|
||||
```dcdl
|
||||
mk_hw({
|
||||
greet = "Hello";
|
||||
target = "World";
|
||||
})
|
||||
increment(41)
|
||||
```
|
||||
|
||||
## 評価
|
||||
@@ -14,4 +11,5 @@ mk_hw({
|
||||
引数は thunk として渡せる。
|
||||
関数本体内で引数が参照されたときに評価する。
|
||||
|
||||
任意の関数呼び出し結果をグローバルに memoize することは必須ではない。
|
||||
関数呼び出し結果そのものはグローバルには memoize しない。
|
||||
フィールドに束縛された呼び出し結果は、そのフィールド thunk の評価結果として memoize される。
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
function expression は、引数を受け取り式を返す値である。
|
||||
|
||||
```dcdl
|
||||
(part: {
|
||||
greet = String;
|
||||
target = String;
|
||||
}) =>
|
||||
"${part.greet}! ${part.target}"
|
||||
(value: Int) => value + 1
|
||||
```
|
||||
|
||||
関数仕様の詳細は [関数](../functions.md) に置く。
|
||||
|
||||
@@ -4,12 +4,10 @@ let expression は、ローカル束縛を作る。
|
||||
|
||||
```dcdl
|
||||
let
|
||||
part = {
|
||||
greet = "Hello";
|
||||
target = "World";
|
||||
};
|
||||
base = 8000;
|
||||
offset = 80;
|
||||
in
|
||||
"${part.greet}! ${part.target}"
|
||||
base + offset
|
||||
```
|
||||
|
||||
## 評価
|
||||
|
||||
@@ -12,4 +12,5 @@ config.feature_hoge.enable
|
||||
左側の式を object として評価し、指定された field を参照する。
|
||||
参照先 field は必要になるまで評価されない。
|
||||
|
||||
存在しない field への参照をエラーにするか、open schema として扱うかは未確定である。
|
||||
存在しない field への参照は diagnostic になる。
|
||||
Decodal は unknown / Any のような値を伝播せず、field の有無を曖昧にしない。
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
# String Interpolation Expression
|
||||
# String Interpolation
|
||||
|
||||
string interpolation は、文字列内に式を埋め込む候補機能である。
|
||||
文字列補間は初期実装には含めない。
|
||||
|
||||
```dcdl
|
||||
"${part.greet}! ${part.target}"
|
||||
```
|
||||
Decodal の string literal は、現時点では literal text として扱う。
|
||||
式を埋め込む構文は定義しない。
|
||||
|
||||
## 評価
|
||||
|
||||
補間式の評価タイミングは通常の遅延評価に従う。
|
||||
文字列補間を初期実装に含めるかは未確定である。
|
||||
必要になった場合は、文字列連結や明示的な formatting function として別途設計する。
|
||||
|
||||
@@ -5,54 +5,47 @@
|
||||
## 構文
|
||||
|
||||
```dcdl
|
||||
(part: {
|
||||
greet = String;
|
||||
target = String;
|
||||
}) =>
|
||||
"${part.greet}! ${part.target}"
|
||||
(value: Int) => value + 1
|
||||
```
|
||||
|
||||
関数呼び出しは通常の呼び出し構文で行う。
|
||||
|
||||
```dcdl
|
||||
mk_hw({
|
||||
greet = "Hello";
|
||||
target = "World";
|
||||
})
|
||||
let
|
||||
increment = (value: Int) => value + 1;
|
||||
in
|
||||
increment(41)
|
||||
```
|
||||
|
||||
複数引数の構文は候補として以下を想定する。
|
||||
複数引数も指定できる。
|
||||
|
||||
```dcdl
|
||||
(
|
||||
input_a: {
|
||||
hoge = Int & >= 0;
|
||||
},
|
||||
input_b: {
|
||||
fuga = 20;
|
||||
}
|
||||
) =>
|
||||
(input_a: { hoge = Int & >= 0; }, input_b: { fuga = Int; }) =>
|
||||
{
|
||||
# ...
|
||||
hoge = input_a.hoge;
|
||||
fuga = input_b.fuga;
|
||||
}
|
||||
```
|
||||
|
||||
## 関数の意味
|
||||
|
||||
関数は値として扱える。
|
||||
ただし、最終データとして関数値を出力できるかどうかは別途定める。
|
||||
設定ファイルを materialize する段階では、未適用の関数値は出力不能な値として扱うのが自然である。
|
||||
関数は runtime value として扱えるが、最終データとして materialize することはできない。
|
||||
未適用の関数値が materialize 対象に残っている場合は diagnostic になる。
|
||||
|
||||
関数値は opaque であり、関数値同士の等価性は提供しない。
|
||||
`&` で関数値同士を合成すると conflict になる。
|
||||
|
||||
## 評価方針
|
||||
|
||||
関数は以下の方針を基本とする。
|
||||
関数は以下の方針で評価する。
|
||||
|
||||
- 関数は純粋である。
|
||||
- 関数はレキシカルスコープを持つ。
|
||||
- 関数は定義時の環境を参照として保持する。
|
||||
- 引数は必要になるまで評価しない。
|
||||
- フィールドに束縛された関数呼び出し結果は、そのフィールド評価結果として memoize される。
|
||||
- 任意の関数呼び出しそのものをグローバルに memoize することは必須ではない。
|
||||
- 引数は thunk として渡され、必要になるまで評価されない。
|
||||
- 関数呼び出し結果そのものはグローバルには memoize しない。
|
||||
- フィールドに束縛された関数呼び出し結果は、そのフィールド thunk の評価結果として memoize される。
|
||||
- 再帰的な依存は thunk cycle として diagnostic になる。
|
||||
|
||||
関数値の内部モデル例:
|
||||
|
||||
@@ -63,29 +56,3 @@ Function {
|
||||
env: EnvRef
|
||||
}
|
||||
```
|
||||
|
||||
## 関数と重さ
|
||||
|
||||
関数の文法・パーサー自体は大きくない。
|
||||
実装上の重さは、主に評価モデルと意味論から発生する。
|
||||
|
||||
注意点:
|
||||
|
||||
- クロージャが環境を掴む。
|
||||
- 引数を lazy にするか strict にするかを決める必要がある。
|
||||
- 関数呼び出し結果をどこまで memoize するかを決める必要がある。
|
||||
- 再帰関数を許可するかを決める必要がある。
|
||||
- 関数値同士の `&` をどう扱うかを決める必要がある。
|
||||
- 関数値を object に入れたとき、materialize 可能かを決める必要がある。
|
||||
- import 循環と関数適用が絡んだときの cycle detection が必要になる。
|
||||
|
||||
軽量に保つため、初期仕様では以下の制限を検討できる。
|
||||
|
||||
- 関数は pure。
|
||||
- lexical closure は許可。
|
||||
- 引数は thunk として渡す。
|
||||
- 関数本体は必要になるまで評価しない。
|
||||
- 関数値は opaque。
|
||||
- 関数同士の `&` は、同一関数参照以外は conflict。
|
||||
- 関数値は最終データとして出力できない。
|
||||
- 再帰は cycle error として扱う、または v1 では禁止する。
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
# Grammar
|
||||
|
||||
This page is the canonical grammar reference for Decodal syntax.
|
||||
Parser implementations such as the Rust parser, Tree-sitter grammar, and Lezer grammar should follow this grammar and may add implementation-specific precedence annotations where needed.
|
||||
|
||||
## Lexical grammar
|
||||
|
||||
```ebnf
|
||||
source_character = ? any Unicode scalar value ? ;
|
||||
newline = "\n" | "\r\n" | "\r" ;
|
||||
space = " " | "\t" | newline ;
|
||||
comment = "#" , { ? any character except newline ? } ;
|
||||
|
||||
digit = "0" … "9" ;
|
||||
letter = "A" … "Z" | "a" … "z" ;
|
||||
identifier = letter , { letter | digit | "_" } ;
|
||||
|
||||
integer = digit , { digit } ;
|
||||
float = digit , { digit } , "." , digit , { digit } ;
|
||||
|
||||
string = '"' , { string_character | escape } , '"' ;
|
||||
string_character = ? any character except '"', "\\", or newline ? ;
|
||||
escape = "\\" , source_character ;
|
||||
|
||||
regex = "/" , regex_character , { regex_character } , "/" ;
|
||||
regex_character = escape | ? any character except "/", "\\", or newline ? ;
|
||||
```
|
||||
|
||||
Whitespace and comments separate tokens and are otherwise ignored by the parser.
|
||||
|
||||
## Syntactic grammar
|
||||
|
||||
```ebnf
|
||||
module = { statement } ;
|
||||
statement = field_definition , [ ";" ]
|
||||
| expression , [ ";" ] ;
|
||||
|
||||
expression = default_expression ;
|
||||
|
||||
default_expression = patch_expression , [ "default" , default_expression ] ;
|
||||
patch_expression = compose_expression , { "//" , compose_expression } ;
|
||||
compose_expression = logical_or_expression , { "&" , logical_or_expression } ;
|
||||
|
||||
logical_or_expression = logical_and_expression , { "||" , logical_and_expression } ;
|
||||
logical_and_expression = comparison_expression , { "&&" , comparison_expression } ;
|
||||
comparison_expression = concat_expression , [ comparison_operator , concat_expression ] ;
|
||||
concat_expression = additive_expression , { "++" , additive_expression } ;
|
||||
additive_expression = multiplicative_expression , { ( "+" | "-" ) , multiplicative_expression } ;
|
||||
multiplicative_expression = unary_expression , { ( "*" | "/" ) , unary_expression } ;
|
||||
|
||||
unary_expression = [ "!" | "-" ] , postfix_expression ;
|
||||
postfix_expression = primary_expression , { call_suffix | path_suffix } ;
|
||||
call_suffix = "(" , [ argument_list ] , ")" ;
|
||||
path_suffix = "." , identifier ;
|
||||
|
||||
primary_expression = literal
|
||||
| identifier
|
||||
| comparison_constraint
|
||||
| object
|
||||
| array
|
||||
| let_expression
|
||||
| function_expression
|
||||
| match_expression
|
||||
| import_expression
|
||||
| "(" , expression , ")" ;
|
||||
|
||||
literal = string | integer | float | "true" | "false" | regex ;
|
||||
comparison_operator = "==" | "!=" | "<" | "<=" | ">" | ">=" ;
|
||||
comparison_constraint = ( "<" | "<=" | ">" | ">=" ) , expression ;
|
||||
|
||||
object = "{" , [ field_definition , { ";" , field_definition } , [ ";" ] ] , "}" ;
|
||||
field_definition = field_path , "=" , expression ;
|
||||
field_path = identifier , { "." , identifier } ;
|
||||
|
||||
array = "[" , [ expression , { "," , expression } , [ "," ] ] , "]" ;
|
||||
|
||||
let_expression = "let" , { field_definition , ";" } , "in" , expression ;
|
||||
function_expression = "(" , [ parameter_list ] , ")" , "=>" , expression ;
|
||||
parameter_list = parameter , { "," , parameter } , [ "," ] ;
|
||||
parameter = identifier , [ ":" , expression ] ;
|
||||
|
||||
match_expression = "match" , expression , "{" , [ match_arm , { ";" , match_arm } , [ ";" ] ] , "}" ;
|
||||
match_arm = pattern , ":" , expression ;
|
||||
pattern = "_" | expression ;
|
||||
|
||||
import_expression = "import" , string ;
|
||||
argument_list = expression , { "," , expression } , [ "," ] ;
|
||||
```
|
||||
|
||||
## Precedence
|
||||
|
||||
Precedence is highest first.
|
||||
|
||||
1. function call and field path reference
|
||||
2. unary `!` and `-`
|
||||
3. `*` and `/`
|
||||
4. `+` and `-`
|
||||
5. `++`
|
||||
6. `==`, `!=`, `<`, `<=`, `>`, `>=`
|
||||
7. `&&`
|
||||
8. `||`
|
||||
9. `&`
|
||||
10. `//`
|
||||
11. `default`
|
||||
|
||||
Binary operators are left-associative except `default`, which is right-associative.
|
||||
|
||||
## Tooling mapping
|
||||
|
||||
Syntax tooling should derive token categories from this grammar rather than making a tool-specific grammar canonical.
|
||||
Tree-sitter and Lezer grammars are implementation artifacts that follow this page.
|
||||
@@ -95,4 +95,5 @@ match value {
|
||||
通常の式はエラー内容に基づいて分岐できない。
|
||||
|
||||
汎用 `try / catch` は core には含めない。
|
||||
fallback は `default`、`match`、および将来的な optional import / optional field access のような限定された仕組みで表現する。
|
||||
fallback は `default` と `match` で表現する。
|
||||
optional import や optional field access は core には含めない。
|
||||
|
||||
@@ -29,7 +29,8 @@ result = schema;
|
||||
```
|
||||
|
||||
この場合、`result` の右辺の `schema` は同じ module の top-level field `schema` を参照する。
|
||||
通常の object literal 内の field を暗黙に recursive scope にするかは別仕様とする。
|
||||
通常の object literal 内の field は、その object 内の sibling field を暗黙には識別子として参照できない。
|
||||
object 内の値を参照する場合は、外側で束縛された値や明示的な path reference を使う。
|
||||
|
||||
## SourceLoader
|
||||
|
||||
|
||||
@@ -183,19 +183,10 @@ Patched = Base // {
|
||||
|
||||
## object 全体の置換
|
||||
|
||||
`//` が deep patch である場合、object 全体を置き換えたいときの escape hatch が必要になる。
|
||||
`//` では object/object は常に deep patch される。
|
||||
object field 全体を特別に置き換えるための `replace(...)` 構文や組み込み関数は core には含めない。
|
||||
|
||||
候補として、`replace(...)` を組み込み関数として提供する。
|
||||
|
||||
```dcdl
|
||||
Replaced = Base // {
|
||||
feature_hoge = replace({
|
||||
enable = false;
|
||||
});
|
||||
};
|
||||
```
|
||||
|
||||
この場合、`feature_hoge` は再帰 patch されず、右辺の object に丸ごと置き換わる。
|
||||
object 全体を別構造にしたい場合は、patch 対象より外側で値を作り直す。
|
||||
|
||||
## `&` と `//` の使い分け
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 構文と字句
|
||||
|
||||
この章では、表層構文の方針をまとめる。
|
||||
厳密な EBNF は未確定であり、今後このファイルに詳細化する。
|
||||
厳密な構文は [Grammar](./grammar.md) の EBNF を参照する。
|
||||
|
||||
## 言語名と拡張子
|
||||
|
||||
@@ -93,9 +93,9 @@ config.feature_hoge.enable
|
||||
}
|
||||
```
|
||||
|
||||
## 予約語候補
|
||||
## 予約語
|
||||
|
||||
以下は予約語または予約構文として扱う候補である。
|
||||
以下は予約語として扱う。
|
||||
|
||||
```text
|
||||
let
|
||||
@@ -105,11 +105,8 @@ import
|
||||
default
|
||||
true
|
||||
false
|
||||
rec
|
||||
```
|
||||
|
||||
`rec` の扱いは未確定である。
|
||||
|
||||
## 演算子
|
||||
|
||||
主要な演算子は以下である。
|
||||
|
||||
@@ -9,7 +9,10 @@ ratio = Float;
|
||||
threshold = Float default 0.5;
|
||||
```
|
||||
|
||||
## 未確定事項
|
||||
## Int との関係
|
||||
|
||||
`Int` と `Float` の暗黙変換を許可するかは未確定である。
|
||||
軽量実装では、両者を明確に分ける方が単純である。
|
||||
`Int` と `Float` は primitive type constraint としては別の型である。
|
||||
`Float` constraint は concrete `Float` を要求し、`Int` constraint は concrete `Int` を要求する。
|
||||
|
||||
数値演算や比較式では `Int` と `Float` を同じ numeric value として扱える。
|
||||
混在した四則演算の結果は `Float` になる。
|
||||
|
||||
@@ -9,9 +9,10 @@ name = String;
|
||||
retry = Int default 3;
|
||||
ratio = Float;
|
||||
enable = Bool default true;
|
||||
tags = Array;
|
||||
```
|
||||
|
||||
現在の primitive type は `String`、`Int`、`Float`、`Bool` である。
|
||||
現在の primitive type は `String`、`Int`、`Float`、`Bool`、`Array` である。
|
||||
各型の個別仕様へのリンクは [Manual Index](../../index.md) に集約する。
|
||||
|
||||
primitive type と制約合成の詳細は [制約と default](../constraints-and-defaults.md) も参照する。
|
||||
|
||||
@@ -17,4 +17,5 @@ greeting = String default "hello";
|
||||
message = String & /Hello! .*/;
|
||||
```
|
||||
|
||||
正規表現制約を必須機能にするかは未確定である。
|
||||
正規表現制約の検証は Rust crate の `regex` feature で有効化される。
|
||||
feature が無効な場合、正規表現制約は具体 string に対して検証できず diagnostic になる。
|
||||
|
||||
@@ -1,60 +1,23 @@
|
||||
# 未確定事項
|
||||
|
||||
今後決める必要がある事項を管理する。
|
||||
詳細化するときは、各項目を該当する仕様ファイルへ移動または反映する。
|
||||
実装または仕様方針が固まった項目は、該当する仕様ファイルへ反映してここから外す。
|
||||
|
||||
## 構文
|
||||
## Materialize target and host projection
|
||||
|
||||
- 正式な字句・構文仕様。
|
||||
- 演算子の優先順位。
|
||||
- `rec` の扱い。
|
||||
- コメント構文を `#` のみにするか。
|
||||
Decodal の評価結果は、制約・default・関数値を含む中間値になり得る。
|
||||
そのため、Decodal 単独で常に「最終成果物」を一意に決めるのではなく、host 側が期待する型や出力形式を与えて materialize / decode する経路を明確にする必要がある。
|
||||
|
||||
## 型・制約
|
||||
決めること:
|
||||
|
||||
- 配列要素の制約表現。
|
||||
- object の open/closed schema の扱い。
|
||||
- 正規表現を必須機能にするか optional feature にするか。
|
||||
- 代表的な組み込み述語の範囲。
|
||||
- Rust API で評価結果の field/path を選択して decode / materialize できるようにするか。
|
||||
- `decodal-derive` の struct schema と評価結果を合成して decode する経路を、主要な materialize path として位置づけるか。
|
||||
- CLI / WASM では target path を指定して JSON-compatible value へ materialize する形にするか。
|
||||
- 制約や関数値が残った値を出力したい場合、materialize ではなく inspect/debug API として分けるか。
|
||||
|
||||
## default
|
||||
現時点の案:
|
||||
|
||||
- `default` 同士の conflict 解決規則。
|
||||
- `&` による default 合成の厳密な規則。
|
||||
- `//` による default 置換の厳密な規則。
|
||||
- default thunk の評価失敗をどの段階で報告するか。
|
||||
|
||||
## 演算子
|
||||
|
||||
- `//` による制約・default の置換詳細。
|
||||
- `replace(...)` を採用するか、別構文を設けるか。
|
||||
- 配列に対する patch 操作を右辺置換だけにするか。
|
||||
- 配列 append / prepend / remove などを提供するか。
|
||||
|
||||
## 関数
|
||||
|
||||
- 関数値の最終出力可否。
|
||||
- 再帰関数を許可するか。
|
||||
- 関数同士の `&` の扱い。
|
||||
- 関数値の等価性。
|
||||
- 関数呼び出し結果の memoize 範囲。
|
||||
|
||||
## 評価
|
||||
|
||||
- thunk のエラー memoize 方針。
|
||||
- import cache の単位。
|
||||
- 循環 import の診断メッセージ。
|
||||
- materialize 対象の範囲指定方法。
|
||||
|
||||
## match
|
||||
|
||||
- match の網羅性チェックを行うか。
|
||||
- 到達不能分岐を警告するか。
|
||||
- パターン構文の範囲。
|
||||
|
||||
## エラー処理
|
||||
|
||||
- optional import を導入するか。
|
||||
- optional field access を導入するか。
|
||||
- optional fallback が捕捉できる失敗の範囲。
|
||||
- エラー報告に制約由来の説明をどこまで含めるか。
|
||||
- Rust では `evaluate -> select field/path -> expected schema と合成 -> decode` を主経路にする。
|
||||
- CLI / WASM では、明示された target path または module 全体を JSON-compatible value として materialize する。
|
||||
- materialize できない unresolved abstract value、default のない制約値、関数値は diagnostic にする。
|
||||
- Decodal 言語内には materialize 構文を追加せず、host API / CLI / WASM の責務として扱う。
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# lezer-decodal
|
||||
|
||||
Lezer implementation of the Decodal grammar for CodeMirror 6.
|
||||
|
||||
The canonical grammar is documented in:
|
||||
|
||||
```text
|
||||
../../doc/manual/souce/language/grammar.md
|
||||
```
|
||||
|
||||
Regenerate the CodeMirror parser from the site directory:
|
||||
|
||||
```sh
|
||||
cd ../../site/decodal-site
|
||||
npx lezer-generator ../../editors/lezer-decodal/decodal.grammar -o ../../packages/decodal-codemirror/src/decodal-parser.js
|
||||
```
|
||||
|
||||
The generated parser is committed with the `decodal-codemirror` package because both the playground and external Web editors consume it.
|
||||
@@ -0,0 +1,172 @@
|
||||
@top Source { Statement* }
|
||||
|
||||
Statement {
|
||||
FieldDefinition Semicolon? |
|
||||
Expression Semicolon?
|
||||
}
|
||||
|
||||
Expression { DefaultExpression }
|
||||
|
||||
DefaultExpression {
|
||||
PatchExpression |
|
||||
PatchExpression !default Default DefaultExpression
|
||||
}
|
||||
|
||||
PatchExpression {
|
||||
ComposeExpression |
|
||||
PatchExpression !patch SlashSlash ComposeExpression
|
||||
}
|
||||
|
||||
ComposeExpression {
|
||||
LogicalOrExpression |
|
||||
ComposeExpression !compose Amp LogicalOrExpression
|
||||
}
|
||||
|
||||
LogicalOrExpression {
|
||||
LogicalAndExpression |
|
||||
LogicalOrExpression !or PipePipe LogicalAndExpression
|
||||
}
|
||||
|
||||
LogicalAndExpression {
|
||||
ComparisonExpression |
|
||||
LogicalAndExpression !and AmpAmp ComparisonExpression
|
||||
}
|
||||
|
||||
ComparisonExpression {
|
||||
ConcatExpression |
|
||||
ConcatExpression !compare CompareOperator ConcatExpression
|
||||
}
|
||||
|
||||
ConcatExpression {
|
||||
AdditiveExpression |
|
||||
ConcatExpression !concat PlusPlus AdditiveExpression
|
||||
}
|
||||
|
||||
AdditiveExpression {
|
||||
MultiplicativeExpression |
|
||||
AdditiveExpression !add (Plus | Minus) MultiplicativeExpression
|
||||
}
|
||||
|
||||
MultiplicativeExpression {
|
||||
UnaryExpression |
|
||||
MultiplicativeExpression !multiply (Star | Slash) UnaryExpression
|
||||
}
|
||||
|
||||
UnaryExpression {
|
||||
PostfixExpression |
|
||||
(Bang | Minus) !unary UnaryExpression
|
||||
}
|
||||
|
||||
PostfixExpression {
|
||||
PrimaryExpression |
|
||||
PostfixExpression !call CallSuffix |
|
||||
PostfixExpression !path Dot Identifier
|
||||
}
|
||||
|
||||
CallSuffix { LParen ArgumentList? RParen }
|
||||
ArgumentList { Expression (Comma Expression)* Comma? }
|
||||
|
||||
PrimaryExpression {
|
||||
Literal |
|
||||
Identifier |
|
||||
ComparisonConstraint |
|
||||
Object |
|
||||
Array |
|
||||
LetExpression |
|
||||
FunctionExpression |
|
||||
MatchExpression |
|
||||
ImportExpression |
|
||||
LParen Expression RParen
|
||||
}
|
||||
|
||||
Literal { String | Integer | Float | True | False | Regex }
|
||||
CompareOperator { EqualEqual | BangEqual | Lt | Lte | Gt | Gte }
|
||||
ComparisonConstraint { (Lt | Lte | Gt | Gte) Expression }
|
||||
|
||||
Object { LBrace (FieldDefinition (Semicolon FieldDefinition)* Semicolon?)? RBrace }
|
||||
FieldDefinition { FieldPath Equal Expression }
|
||||
FieldPath { Identifier !fieldPath (Dot Identifier)* }
|
||||
|
||||
Array { LBracket (Expression (Comma Expression)* Comma?)? RBracket }
|
||||
|
||||
LetExpression { Let FieldDefinitionList In Expression }
|
||||
FieldDefinitionList { (FieldDefinition Semicolon)* }
|
||||
|
||||
FunctionExpression { LParen ParameterList? RParen Arrow Expression }
|
||||
ParameterList { Parameter (Comma Parameter)* Comma? }
|
||||
Parameter { Identifier Colon Expression }
|
||||
|
||||
MatchExpression { Match Expression LBrace (MatchArm (Semicolon MatchArm)* Semicolon?)? RBrace }
|
||||
MatchArm { Pattern Colon Expression }
|
||||
Pattern { Underscore | Expression }
|
||||
|
||||
ImportExpression { Import String }
|
||||
|
||||
@precedence {
|
||||
fieldPath @left,
|
||||
default @right,
|
||||
patch @left,
|
||||
compose @left,
|
||||
or @left,
|
||||
and @left,
|
||||
compare @left,
|
||||
concat @left,
|
||||
add @left,
|
||||
multiply @left,
|
||||
unary,
|
||||
call @left,
|
||||
path @left
|
||||
}
|
||||
|
||||
@tokens {
|
||||
Let { "let" }
|
||||
In { "in" }
|
||||
Match { "match" }
|
||||
Import { "import" }
|
||||
Default { "default" }
|
||||
True { "true" }
|
||||
False { "false" }
|
||||
|
||||
Identifier { $[A-Za-z_] $[A-Za-z0-9_]* }
|
||||
Integer { $[0-9]+ }
|
||||
Float { $[0-9]+ "." $[0-9]+ }
|
||||
String { '"' (!["\\\n] | "\\" _)* '"' }
|
||||
Regex { "/" (![/\\\n] | "\\" _)+ "/" }
|
||||
Comment { "#" ![\n]* }
|
||||
|
||||
LBrace { "{" }
|
||||
RBrace { "}" }
|
||||
LBracket { "[" }
|
||||
RBracket { "]" }
|
||||
LParen { "(" }
|
||||
RParen { ")" }
|
||||
Semicolon { ";" }
|
||||
Comma { "," }
|
||||
Dot { "." }
|
||||
Colon { ":" }
|
||||
Equal { "=" }
|
||||
EqualEqual { "==" }
|
||||
Bang { "!" }
|
||||
BangEqual { "!=" }
|
||||
Arrow { "=>" }
|
||||
Amp { "&" }
|
||||
AmpAmp { "&&" }
|
||||
PipePipe { "||" }
|
||||
Plus { "+" }
|
||||
PlusPlus { "++" }
|
||||
Minus { "-" }
|
||||
Star { "*" }
|
||||
Slash { "/" }
|
||||
SlashSlash { "//" }
|
||||
Gt { ">" }
|
||||
Gte { ">=" }
|
||||
Lt { "<" }
|
||||
Lte { "<=" }
|
||||
Underscore { "_" }
|
||||
|
||||
whitespace { @whitespace+ }
|
||||
|
||||
@precedence { Let, In, Match, Import, Default, True, False, Float, Integer, Underscore, Identifier }
|
||||
}
|
||||
|
||||
@skip { whitespace | Comment }
|
||||
@@ -0,0 +1,12 @@
|
||||
# tree-sitter-decodal
|
||||
|
||||
Tree-sitter implementation of the Decodal grammar.
|
||||
|
||||
The canonical grammar is documented in:
|
||||
|
||||
```text
|
||||
../../doc/manual/souce/language/grammar.md
|
||||
```
|
||||
|
||||
This grammar is an editor/tooling implementation of that EBNF reference.
|
||||
Generated parser files under `src/` are committed.
|
||||
@@ -1,3 +1,6 @@
|
||||
// Tree-sitter implementation of the canonical EBNF grammar in
|
||||
// doc/manual/souce/language/grammar.md.
|
||||
|
||||
const PREC = {
|
||||
DEFAULT: 1,
|
||||
PATCH: 2,
|
||||
|
||||
@@ -16,7 +16,7 @@ This example exercises multiple current Decodal features together:
|
||||
Run it with:
|
||||
|
||||
```sh
|
||||
cargo run -q -p decodal -- examples/advanced/main.dcdl
|
||||
cargo run -q -p decodal-cli -- examples/advanced/main.dcdl
|
||||
```
|
||||
|
||||
The entrypoint is `main.dcdl`.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Regex constraints are optional. Run this example with the `regex` feature enabled:
|
||||
|
||||
```sh
|
||||
cargo run -q -p decodal --features regex -- examples/regex/main.dcdl
|
||||
cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
|
||||
```
|
||||
|
||||
Without the feature, regex validation returns an unsupported feature diagnostic.
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ let
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "decodal";
|
||||
version = "0.1.0";
|
||||
version = "0.1.1";
|
||||
|
||||
src = lib.cleanSourceWith {
|
||||
src = srcRoot;
|
||||
@@ -37,7 +37,7 @@ rustPlatform.buildRustPackage {
|
||||
|
||||
cargoBuildFlags = [
|
||||
"-p"
|
||||
"decodal"
|
||||
"decodal-cli"
|
||||
];
|
||||
|
||||
doInstallCheck = true;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# decodal-codemirror
|
||||
|
||||
CodeMirror 6 language support for Decodal.
|
||||
|
||||
This package provides the Lezer parser metadata, highlighting tags, indentation rules, and block folding used by the Decodal Web playground.
|
||||
It does not include the Decodal runtime or WebAssembly evaluator.
|
||||
Use `decodal-wasm` when you want to evaluate Decodal in a browser.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install decodal-codemirror
|
||||
```
|
||||
|
||||
JSR:
|
||||
|
||||
```sh
|
||||
deno add jsr:@hare/decodal-codemirror
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { basicSetup } from 'codemirror';
|
||||
import { EditorView } from '@codemirror/view';
|
||||
import { decodal } from 'decodal-codemirror';
|
||||
|
||||
new EditorView({
|
||||
doc: 'Server = { port = Int default 8080; };',
|
||||
extensions: [
|
||||
basicSetup,
|
||||
decodal(),
|
||||
],
|
||||
parent: document.querySelector('#editor'),
|
||||
});
|
||||
```
|
||||
|
||||
## Exports
|
||||
|
||||
```js
|
||||
import {
|
||||
decodal,
|
||||
decodalLanguage,
|
||||
decodalHighlightStyle,
|
||||
} from 'decodal-codemirror';
|
||||
```
|
||||
|
||||
`decodal()` accepts a small options object:
|
||||
|
||||
```js
|
||||
decodal({ highlight: false })
|
||||
```
|
||||
|
||||
Use this when you want the language support without the bundled highlight style.
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@hare/decodal-codemirror",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"exports": "./src/mod.ts",
|
||||
"imports": {
|
||||
"@codemirror/language": "npm:@codemirror/language@^6.12.4",
|
||||
"@lezer/highlight": "npm:@lezer/highlight@^1.2.3",
|
||||
"@lezer/lr": "npm:@lezer/lr@^1.4.10"
|
||||
},
|
||||
"publish": {
|
||||
"include": [
|
||||
"README.md",
|
||||
"src/mod.ts",
|
||||
"src/decodal.js",
|
||||
"src/decodal.d.ts",
|
||||
"src/decodal.js.d.ts",
|
||||
"src/decodal-parser-jsr.js",
|
||||
"src/decodal-parser.js",
|
||||
"src/decodal-parser.terms.js",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/language": {
|
||||
"version": "6.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.4.tgz",
|
||||
"integrity": "sha512-1q4PaT+o6PbgpkJt4Q8Fv5XJxTy4FUZ4MWETtyiDw3J0Pyr9E2vqcKL+k9wcvjNTIsauxvE7OfmWj3FRPHQ76A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.23.0",
|
||||
"@lezer/common": "^1.5.0",
|
||||
"@lezer/highlight": "^1.0.0",
|
||||
"@lezer/lr": "^1.0.0",
|
||||
"style-mod": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/state": {
|
||||
"version": "6.7.1",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.7.1.tgz",
|
||||
"integrity": "sha512-9QzNDgE4EYDnAHfrTlR2lwiPciiOymLtwKK+8yHQzCc7GXhAP9xdEbEJFy2IWB1j9UGUl9BsgMmTo/ImA02T7A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@marijn/find-cluster-break": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/view": {
|
||||
"version": "6.43.6",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.6.tgz",
|
||||
"integrity": "sha512-EVunGSYN1wz1p75WY1s3Xg7t3i8Yol0kGZGizNdX9BUFgMFILYVe8/u6EVpo7Ff5PwbZuILb4QAq7IZoKzIEQA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.7.0",
|
||||
"crelt": "^1.0.6",
|
||||
"style-mod": "^4.1.0",
|
||||
"w3c-keyname": "^2.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@lezer/common": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.2.tgz",
|
||||
"integrity": "sha512-sxQE460fPZyU3sdc8lafxiPwJHBzZRy/udNFynGQky1SePYBdhkBl1kOagA9uT3pxR8K09bOrmTUqA9wb/PjSQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@lezer/highlight": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz",
|
||||
"integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lezer/common": "^1.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@lezer/lr": {
|
||||
"version": "1.4.10",
|
||||
"resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.10.tgz",
|
||||
"integrity": "sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lezer/common": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@marijn/find-cluster-break": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.3.tgz",
|
||||
"integrity": "sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/crelt": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.7.tgz",
|
||||
"integrity": "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/style-mod": {
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz",
|
||||
"integrity": "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/w3c-keyname": {
|
||||
"version": "2.2.8",
|
||||
"resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
|
||||
"integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.2",
|
||||
"description": "CodeMirror 6 language support for Decodal.",
|
||||
"type": "module",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://gitea.hareworks.net/Hare/Decodal.git",
|
||||
"directory": "packages/decodal-codemirror"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/decodal.d.ts",
|
||||
"import": "./src/decodal.js"
|
||||
},
|
||||
"./parser": "./src/decodal-parser.js",
|
||||
"./terms": "./src/decodal-parser.terms.js"
|
||||
},
|
||||
"types": "./src/decodal.d.ts",
|
||||
"files": [
|
||||
"README.md",
|
||||
"src/"
|
||||
],
|
||||
"keywords": [
|
||||
"decodal",
|
||||
"codemirror",
|
||||
"lezer"
|
||||
],
|
||||
"dependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
||||
import {LRParser} from "npm:@lezer/lr@^1.4.10"
|
||||
export const parser = LRParser.deserialize({
|
||||
version: 14,
|
||||
states: "7vQYQPOOO#nQPO'#CaOOQO'#Cr'#Cr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$lRvURzVQxVV#d!m#e#tQ#l!rV#|#w$O$RX#j!r#w$O$RR!P[R!u!OQ!WaQ$U$[R$f$dQkOR!`kSmPoR!bmQ!dqR#[!dQ!gsS#`!g#nR#n!sQuUR!juQ!nxR#f!nQ#x#lR$P#x",
|
||||
nodeNames: "⚠ Comment Source Statement FieldDefinition FieldPath Identifier Dot Equal Expression DefaultExpression PatchExpression ComposeExpression LogicalOrExpression LogicalAndExpression ComparisonExpression ConcatExpression AdditiveExpression MultiplicativeExpression UnaryExpression PostfixExpression PrimaryExpression Literal String Integer Float True False Regex ComparisonConstraint Lt Lte Gt Gte Object LBrace Semicolon RBrace Array LBracket Comma RBracket LetExpression Let FieldDefinitionList In FunctionExpression LParen ParameterList Parameter Colon RParen Arrow MatchExpression Match MatchArm Pattern Underscore ImportExpression Import CallSuffix ArgumentList Bang Minus Star Slash Plus PlusPlus CompareOperator EqualEqual BangEqual AmpAmp PipePipe Amp SlashSlash Default",
|
||||
maxTerm: 85,
|
||||
skippedNodes: [0,1],
|
||||
repeatNodeCount: 7,
|
||||
tokenData: "=T~R!PX^$Upq$Uqr$yrs%Wst&zvw'cxy'pyz'uz{'z{|(P|}(^}!O(c!O!P(h!P!Q(m!Q![+T![!]+n!]!^+s!^!_+x!_!`,V!`!a,l!c!},y!}#O-[#P#Q-a#R#S-f#T#W,y#W#X-y#X#Y,y#Y#Z1Z#Z#],y#]#^3k#^#`,y#`#a6}#a#b8b#b#h,y#h#i:r#i#o,y#o#p<n#p#q<s#q#r=O#y#z$U$f$g$U#BY#BZ$U$IS$I_$U$I|$JO$U$JT$JU$U$KV$KW$U&FU&FV$U~$ZY!w~X^$Upq$U#y#z$U$f$g$U#BY#BZ$U$IS$I_$U$I|$JO$U$JT$JU$U$KV$KW$U&FU&FV$U~%OP!`~!_!`%R~%WO!h~~%ZWOY%WZr%Wrs%ss#O%W#O#P%x#P;'S%W;'S;=`&t<%lO%W~%xOg~~%{RO;'S%W;'S;=`&U;=`O%W~&XXOY%W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T#X,y#X#Y3W#Y#o,y~3_Sk~U~!Q![,y!c!},y#R#S,y#T#o,y~3pVU~!Q![,y!c!},y#R#S,y#T#a,y#a#b4V#b#c6j#c#o,y~4[UU~!Q![,y!c!},y#R#S,y#T#d,y#d#e4n#e#o,y~4sUU~!Q![,y!c!},y#R#S,y#T#c,y#c#d5V#d#o,y~5[UU~!Q![,y!c!},y#R#S,y#T#f,y#f#g5n#g#o,y~5sUU~!Q![,y!c!},y#R#S,y#T#h,y#h#i6V#i#o,y~6^S!]~U~!Q![,y!c!},y#R#S,y#T#o,y~6qS}~U~!Q![,y!c!},y#R#S,y#T#o,y~7SUU~!Q![,y!c!},y#R#S,y#T#X,y#X#Y7f#Y#o,y~7kUU~!Q![,y!c!},y#R#S,y#T#h,y#h#i7}#i#o,y~8US{~U~!Q![,y!c!},y#R#S,y#T#o,y~8gTU~!Q![,y!c!},y#R#S,y#T#U8v#U#o,y~8{UU~!Q![,y!c!},y#R#S,y#T#h,y#h#i9_#i#o,y~9dUU~!Q![,y!c!},y#R#S,y#T#V,y#V#W9v#W#o,y~9{UU~!Q![,y!c!},y#R#S,y#T#[,y#[#]:_#]#o,y~:fS!W~U~!Q![,y!c!},y#R#S,y#T#o,y~:wUU~!Q![,y!c!},y#R#S,y#T#f,y#f#g;Z#g#o,y~;`UU~!Q![,y!c!},y#R#S,y#T#i,y#i#j;r#j#o,y~;wUU~!Q![,y!c!},y#R#S,y#T#X,y#X#Y<Z#Y#o,y~<bSj~U~!Q![,y!c!},y#R#S,y#T#o,y~<sOs~~<vP#p#q<y~=OO!j~~=TOu~",
|
||||
tokenizers: [0, 1],
|
||||
topRules: {"Source":[0,2]},
|
||||
tokenPrec: 2481
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
||||
import {LRParser} from "@lezer/lr"
|
||||
export const parser = LRParser.deserialize({
|
||||
version: 14,
|
||||
states: "7vQYQPOOO#nQPO'#CaOOQO'#Cr'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j$k$lRvURzVQxVV#d!m#e#tQ#l!rV#|#w$O$RX#j!r#w$O$RR!P[R!u!OQ!WaQ$U$[R$f$dQkOR!`kSmPoR!bmQ!dqR#[!dQ!gsS#`!g#nR#n!sQuUR!juQ!nxR#f!nQ#x#lR$P#x",
|
||||
nodeNames: "⚠ Comment Source Statement FieldDefinition FieldPath Identifier Dot Equal Expression DefaultExpression PatchExpression ComposeExpression LogicalOrExpression LogicalAndExpression ComparisonExpression ConcatExpression AdditiveExpression MultiplicativeExpression UnaryExpression PostfixExpression PrimaryExpression Literal String Integer Float True False Regex ComparisonConstraint Lt Lte Gt Gte Object LBrace Semicolon RBrace Array LBracket Comma RBracket LetExpression Let FieldDefinitionList In FunctionExpression LParen ParameterList Parameter Colon RParen Arrow MatchExpression Match MatchArm Pattern Underscore ImportExpression Import CallSuffix ArgumentList Bang Minus Star Slash Plus PlusPlus CompareOperator EqualEqual BangEqual AmpAmp PipePipe Amp SlashSlash Default",
|
||||
maxTerm: 85,
|
||||
skippedNodes: [0,1],
|
||||
repeatNodeCount: 7,
|
||||
tokenData: "=T~R!PX^$Upq$Uqr$yrs%Wst&zvw'cxy'pyz'uz{'z{|(P|}(^}!O(c!O!P(h!P!Q(m!Q![+T![!]+n!]!^+s!^!_+x!_!`,V!`!a,l!c!},y!}#O-[#P#Q-a#R#S-f#T#W,y#W#X-y#X#Y,y#Y#Z1Z#Z#],y#]#^3k#^#`,y#`#a6}#a#b8b#b#h,y#h#i:r#i#o,y#o#p<n#p#q<s#q#r=O#y#z$U$f$g$U#BY#BZ$U$IS$I_$U$I|$JO$U$JT$JU$U$KV$KW$U&FU&FV$U~$ZY!w~X^$Upq$U#y#z$U$f$g$U#BY#BZ$U$IS$I_$U$I|$JO$U$JT$JU$U$KV$KW$U&FU&FV$U~%OP!`~!_!`%R~%WO!h~~%ZWOY%WZr%Wrs%ss#O%W#O#P%x#P;'S%W;'S;=`&t<%lO%W~%xOg~~%{RO;'S%W;'S;=`&U;=`O%W~&XXO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,y#T#X,y#X#Y3W#Y#o,y~3_Sk~U~!Q![,y!c!},y#R#S,y#T#o,y~3pVU~!Q![,y!c!},y#R#S,y#T#a,y#a#b4V#b#c6j#c#o,y~4[UU~!Q![,y!c!},y#R#S,y#T#d,y#d#e4n#e#o,y~4sUU~!Q![,y!c!},y#R#S,y#T#c,y#c#d5V#d#o,y~5[UU~!Q![,y!c!},y#R#S,y#T#f,y#f#g5n#g#o,y~5sUU~!Q![,y!c!},y#R#S,y#T#h,y#h#i6V#i#o,y~6^S!]~U~!Q![,y!c!},y#R#S,y#T#o,y~6qS}~U~!Q![,y!c!},y#R#S,y#T#o,y~7SUU~!Q![,y!c!},y#R#S,y#T#X,y#X#Y7f#Y#o,y~7kUU~!Q![,y!c!},y#R#S,y#T#h,y#h#i7}#i#o,y~8US{~U~!Q![,y!c!},y#R#S,y#T#o,y~8gTU~!Q![,y!c!},y#R#S,y#T#U8v#U#o,y~8{UU~!Q![,y!c!},y#R#S,y#T#h,y#h#i9_#i#o,y~9dUU~!Q![,y!c!},y#R#S,y#T#V,y#V#W9v#W#o,y~9{UU~!Q![,y!c!},y#R#S,y#T#[,y#[#]:_#]#o,y~:fS!W~U~!Q![,y!c!},y#R#S,y#T#o,y~:wUU~!Q![,y!c!},y#R#S,y#T#f,y#f#g;Z#g#o,y~;`UU~!Q![,y!c!},y#R#S,y#T#i,y#i#j;r#j#o,y~;wUU~!Q![,y!c!},y#R#S,y#T#X,y#X#Y<Z#Y#o,y~<bSj~U~!Q![,y!c!},y#R#S,y#T#o,y~<sOs~~<vP#p#q<y~=OO!j~~=TOu~",
|
||||
tokenizers: [0, 1],
|
||||
topRules: {"Source":[0,2]},
|
||||
tokenPrec: 2481
|
||||
})
|
||||
@@ -0,0 +1,77 @@
|
||||
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
||||
export const
|
||||
Comment = 1,
|
||||
Source = 2,
|
||||
Statement = 3,
|
||||
FieldDefinition = 4,
|
||||
FieldPath = 5,
|
||||
Identifier = 6,
|
||||
Dot = 7,
|
||||
Equal = 8,
|
||||
Expression = 9,
|
||||
DefaultExpression = 10,
|
||||
PatchExpression = 11,
|
||||
ComposeExpression = 12,
|
||||
LogicalOrExpression = 13,
|
||||
LogicalAndExpression = 14,
|
||||
ComparisonExpression = 15,
|
||||
ConcatExpression = 16,
|
||||
AdditiveExpression = 17,
|
||||
MultiplicativeExpression = 18,
|
||||
UnaryExpression = 19,
|
||||
PostfixExpression = 20,
|
||||
PrimaryExpression = 21,
|
||||
Literal = 22,
|
||||
String = 23,
|
||||
Integer = 24,
|
||||
Float = 25,
|
||||
True = 26,
|
||||
False = 27,
|
||||
Regex = 28,
|
||||
ComparisonConstraint = 29,
|
||||
Lt = 30,
|
||||
Lte = 31,
|
||||
Gt = 32,
|
||||
Gte = 33,
|
||||
Object = 34,
|
||||
LBrace = 35,
|
||||
Semicolon = 36,
|
||||
RBrace = 37,
|
||||
Array = 38,
|
||||
LBracket = 39,
|
||||
Comma = 40,
|
||||
RBracket = 41,
|
||||
LetExpression = 42,
|
||||
Let = 43,
|
||||
FieldDefinitionList = 44,
|
||||
In = 45,
|
||||
FunctionExpression = 46,
|
||||
LParen = 47,
|
||||
ParameterList = 48,
|
||||
Parameter = 49,
|
||||
Colon = 50,
|
||||
RParen = 51,
|
||||
Arrow = 52,
|
||||
MatchExpression = 53,
|
||||
Match = 54,
|
||||
MatchArm = 55,
|
||||
Pattern = 56,
|
||||
Underscore = 57,
|
||||
ImportExpression = 58,
|
||||
Import = 59,
|
||||
CallSuffix = 60,
|
||||
ArgumentList = 61,
|
||||
Bang = 62,
|
||||
Minus = 63,
|
||||
Star = 64,
|
||||
Slash = 65,
|
||||
Plus = 66,
|
||||
PlusPlus = 67,
|
||||
CompareOperator = 68,
|
||||
EqualEqual = 69,
|
||||
BangEqual = 70,
|
||||
AmpAmp = 71,
|
||||
PipePipe = 72,
|
||||
Amp = 73,
|
||||
SlashSlash = 74,
|
||||
Default = 75
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { HighlightStyle } from '@codemirror/language';
|
||||
import { LRLanguage, LanguageSupport } from '@codemirror/language';
|
||||
|
||||
export declare const decodalLanguage: LRLanguage;
|
||||
export declare const decodalHighlightStyle: HighlightStyle;
|
||||
|
||||
export interface DecodalOptions {
|
||||
highlight?: boolean;
|
||||
}
|
||||
|
||||
export declare function decodal(options?: DecodalOptions): LanguageSupport;
|
||||
@@ -0,0 +1,73 @@
|
||||
import { LRLanguage, LanguageSupport, HighlightStyle, syntaxHighlighting, foldNodeProp, indentNodeProp } from '@codemirror/language';
|
||||
import { styleTags, tags as t } from '@lezer/highlight';
|
||||
import { parser } from './decodal-parser.js';
|
||||
|
||||
const parserWithMetadata = parser.configure({
|
||||
props: [
|
||||
styleTags({
|
||||
'Let In Match Import Default': t.keyword,
|
||||
'True False': t.bool,
|
||||
Identifier: t.variableName,
|
||||
String: t.string,
|
||||
Regex: t.regexp,
|
||||
'Integer Float': t.number,
|
||||
Comment: t.lineComment,
|
||||
'Plus Minus Star Slash PlusPlus Equal EqualEqual Bang BangEqual Amp AmpAmp PipePipe SlashSlash Gt Gte Lt Lte Arrow': t.operator,
|
||||
'LBrace RBrace': t.brace,
|
||||
'LBracket RBracket': t.squareBracket,
|
||||
'LParen RParen': t.paren,
|
||||
'Semicolon Comma Dot Colon': t.punctuation,
|
||||
}),
|
||||
indentNodeProp.add({
|
||||
Object: context => context.column(context.node.from) + context.unit,
|
||||
Array: context => context.column(context.node.from) + context.unit,
|
||||
MatchExpression: context => context.column(context.node.from) + context.unit,
|
||||
LetExpression: context => context.column(context.node.from) + context.unit,
|
||||
}),
|
||||
foldNodeProp.add({
|
||||
Object: foldDelimited('{', '}'),
|
||||
Array: foldDelimited('[', ']'),
|
||||
MatchExpression: foldDelimited('{', '}'),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
function foldDelimited(open, close) {
|
||||
return (node, state) => {
|
||||
const text = state.doc.sliceString(node.from, node.to);
|
||||
const openIndex = text.indexOf(open);
|
||||
const closeIndex = text.lastIndexOf(close);
|
||||
if (openIndex < 0 || closeIndex <= openIndex) return null;
|
||||
const from = node.from + openIndex + open.length;
|
||||
const to = node.from + closeIndex;
|
||||
return from < to ? { from, to } : null;
|
||||
};
|
||||
}
|
||||
|
||||
export const decodalLanguage = LRLanguage.define({
|
||||
parser: parserWithMetadata,
|
||||
languageData: {
|
||||
commentTokens: { line: '#' },
|
||||
closeBrackets: { brackets: ['(', '[', '{', '"'] },
|
||||
},
|
||||
});
|
||||
|
||||
export const decodalHighlightStyle = HighlightStyle.define([
|
||||
{ tag: t.keyword, color: '#93c5fd', fontWeight: '700' },
|
||||
{ tag: t.variableName, color: 'inherit' },
|
||||
{ tag: t.bool, color: '#fbbf24' },
|
||||
{ tag: t.number, color: '#fbbf24' },
|
||||
{ tag: t.string, color: '#86efac' },
|
||||
{ tag: t.regexp, color: '#86efac' },
|
||||
{ tag: t.lineComment, color: '#94a3b8', fontStyle: 'italic' },
|
||||
{ tag: t.operator, color: '#f9a8d4' },
|
||||
{ tag: [t.brace, t.squareBracket, t.paren, t.punctuation], color: '#f9a8d4' },
|
||||
]);
|
||||
|
||||
export function decodal(options = {}) {
|
||||
const { highlight = true } = options;
|
||||
return new LanguageSupport(
|
||||
decodalLanguage,
|
||||
highlight ? [syntaxHighlighting(decodalHighlightStyle)] : [],
|
||||
);
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { HighlightStyle, LRLanguage, LanguageSupport } from '@codemirror/language';
|
||||
|
||||
export declare const decodalLanguage: LRLanguage;
|
||||
export declare const decodalHighlightStyle: HighlightStyle;
|
||||
|
||||
export interface DecodalOptions {
|
||||
highlight?: boolean;
|
||||
}
|
||||
|
||||
export declare function decodal(options?: DecodalOptions): LanguageSupport;
|
||||
@@ -0,0 +1,77 @@
|
||||
import { HighlightStyle, LRLanguage, LanguageSupport, foldNodeProp, indentNodeProp, syntaxHighlighting } from 'npm:@codemirror/language@^6.12.4';
|
||||
import { styleTags, tags as t } from 'npm:@lezer/highlight@^1.2.3';
|
||||
import { parser } from './decodal-parser-jsr.js';
|
||||
|
||||
const parserWithMetadata = parser.configure({
|
||||
props: [
|
||||
styleTags({
|
||||
'Let In Match Import Default': t.keyword,
|
||||
'True False': t.bool,
|
||||
Identifier: t.variableName,
|
||||
String: t.string,
|
||||
Regex: t.regexp,
|
||||
'Integer Float': t.number,
|
||||
Comment: t.lineComment,
|
||||
'Plus Minus Star Slash PlusPlus Equal EqualEqual Bang BangEqual Amp AmpAmp PipePipe SlashSlash Gt Gte Lt Lte Arrow': t.operator,
|
||||
'LBrace RBrace': t.brace,
|
||||
'LBracket RBracket': t.squareBracket,
|
||||
'LParen RParen': t.paren,
|
||||
'Semicolon Comma Dot Colon': t.punctuation,
|
||||
}),
|
||||
indentNodeProp.add({
|
||||
Object: context => context.column(context.node.from) + context.unit,
|
||||
Array: context => context.column(context.node.from) + context.unit,
|
||||
MatchExpression: context => context.column(context.node.from) + context.unit,
|
||||
LetExpression: context => context.column(context.node.from) + context.unit,
|
||||
}),
|
||||
foldNodeProp.add({
|
||||
Object: foldDelimited('{', '}'),
|
||||
Array: foldDelimited('[', ']'),
|
||||
MatchExpression: foldDelimited('{', '}'),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
function foldDelimited(open: string, close: string) {
|
||||
return (node: { from: number; to: number }, state: { doc: { sliceString(from: number, to: number): string } }) => {
|
||||
const text = state.doc.sliceString(node.from, node.to);
|
||||
const openIndex = text.indexOf(open);
|
||||
const closeIndex = text.lastIndexOf(close);
|
||||
if (openIndex < 0 || closeIndex <= openIndex) return null;
|
||||
const from = node.from + openIndex + open.length;
|
||||
const to = node.from + closeIndex;
|
||||
return from < to ? { from, to } : null;
|
||||
};
|
||||
}
|
||||
|
||||
export const decodalLanguage: LRLanguage = LRLanguage.define({
|
||||
parser: parserWithMetadata,
|
||||
languageData: {
|
||||
commentTokens: { line: '#' },
|
||||
closeBrackets: { brackets: ['(', '[', '{', '"'] },
|
||||
},
|
||||
});
|
||||
|
||||
export const decodalHighlightStyle: HighlightStyle = HighlightStyle.define([
|
||||
{ tag: t.keyword, color: '#93c5fd', fontWeight: '700' },
|
||||
{ tag: t.variableName, color: 'inherit' },
|
||||
{ tag: t.bool, color: '#fbbf24' },
|
||||
{ tag: t.number, color: '#fbbf24' },
|
||||
{ tag: t.string, color: '#86efac' },
|
||||
{ tag: t.regexp, color: '#86efac' },
|
||||
{ tag: t.lineComment, color: '#94a3b8', fontStyle: 'italic' },
|
||||
{ tag: t.operator, color: '#f9a8d4' },
|
||||
{ tag: [t.brace, t.squareBracket, t.paren, t.punctuation], color: '#f9a8d4' },
|
||||
]);
|
||||
|
||||
export interface DecodalOptions {
|
||||
highlight?: boolean;
|
||||
}
|
||||
|
||||
export function decodal(options: DecodalOptions = {}): LanguageSupport {
|
||||
const { highlight = true } = options;
|
||||
return new LanguageSupport(
|
||||
decodalLanguage,
|
||||
highlight ? [syntaxHighlighting(decodalHighlightStyle)] : [],
|
||||
);
|
||||
}
|
||||
@@ -2,4 +2,9 @@ import { defineConfig } from 'astro/config';
|
||||
|
||||
export default defineConfig({
|
||||
output: 'static',
|
||||
vite: {
|
||||
resolve: {
|
||||
preserveSymlinks: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Generated
+178
@@ -9,13 +9,29 @@
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@astrojs/check": "^0.9.4",
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10",
|
||||
"astro": "^4.16.18",
|
||||
"codemirror": "^6.0.2",
|
||||
"decodal-codemirror": "file:../../packages/decodal-codemirror",
|
||||
"marked": "^12.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lezer/generator": "^1.8.0",
|
||||
"wrangler": "^4.104.0"
|
||||
}
|
||||
},
|
||||
"../../packages/decodal-codemirror": {
|
||||
"version": "0.1.2",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
}
|
||||
},
|
||||
"node_modules/@astrojs/check": {
|
||||
"version": "0.9.9",
|
||||
"resolved": "https://registry.npmjs.org/@astrojs/check/-/check-0.9.9.tgz",
|
||||
@@ -560,6 +576,87 @@
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/autocomplete": {
|
||||
"version": "6.20.3",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.20.3.tgz",
|
||||
"integrity": "sha512-tlosUqb+3BbxCxZdu4tKeRghPFC+QM7q4X5YhKV2eCmPG+1r2F3f4AaSz5sCrFqUtX4Jh20VFTKecl16MgiV9g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/language": "^6.0.0",
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.17.0",
|
||||
"@lezer/common": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/commands": {
|
||||
"version": "6.10.4",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.4.tgz",
|
||||
"integrity": "sha512-Ryk9y9T0FFVF0cUGhAknveAyUOl/A1qReTFi+qPKtOh2Z9F4AUBz3XOrYD4ZEgZirdugVzHvd/2/Wcwy5OliTg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/language": "^6.0.0",
|
||||
"@codemirror/state": "^6.7.0",
|
||||
"@codemirror/view": "^6.27.0",
|
||||
"@lezer/common": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/language": {
|
||||
"version": "6.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.4.tgz",
|
||||
"integrity": "sha512-1q4PaT+o6PbgpkJt4Q8Fv5XJxTy4FUZ4MWETtyiDw3J0Pyr9E2vqcKL+k9wcvjNTIsauxvE7OfmWj3FRPHQ76A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.23.0",
|
||||
"@lezer/common": "^1.5.0",
|
||||
"@lezer/highlight": "^1.0.0",
|
||||
"@lezer/lr": "^1.0.0",
|
||||
"style-mod": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/lint": {
|
||||
"version": "6.9.7",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.7.tgz",
|
||||
"integrity": "sha512-28/+iWLYxKxsvGYhSYL7zaCZqLz5+FFFDq9tVsvGv9kv8RY4fFAchJ5WX9M3YrrRlTIsECjsXPqeNgnSmNP2dg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.42.0",
|
||||
"crelt": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/search": {
|
||||
"version": "6.7.1",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.7.1.tgz",
|
||||
"integrity": "sha512-uMe5UO6PamJtSHrXhhHOzSX3ReWtiJrva6GnPMwSOrZtiExb5X5eExhr2OUZQVvdxPsKpY3Ro2mFbQadpPWmHA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.37.0",
|
||||
"crelt": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/state": {
|
||||
"version": "6.7.1",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.7.1.tgz",
|
||||
"integrity": "sha512-9QzNDgE4EYDnAHfrTlR2lwiPciiOymLtwKK+8yHQzCc7GXhAP9xdEbEJFy2IWB1j9UGUl9BsgMmTo/ImA02T7A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@marijn/find-cluster-break": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/view": {
|
||||
"version": "6.43.6",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.6.tgz",
|
||||
"integrity": "sha512-EVunGSYN1wz1p75WY1s3Xg7t3i8Yol0kGZGizNdX9BUFgMFILYVe8/u6EVpo7Ff5PwbZuILb4QAq7IZoKzIEQA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.7.0",
|
||||
"crelt": "^1.0.6",
|
||||
"style-mod": "^4.1.0",
|
||||
"w3c-keyname": "^2.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@cspotcode/source-map-support": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
||||
@@ -1632,6 +1729,50 @@
|
||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
}
|
||||
},
|
||||
"node_modules/@lezer/common": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.2.tgz",
|
||||
"integrity": "sha512-sxQE460fPZyU3sdc8lafxiPwJHBzZRy/udNFynGQky1SePYBdhkBl1kOagA9uT3pxR8K09bOrmTUqA9wb/PjSQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@lezer/generator": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/@lezer/generator/-/generator-1.8.0.tgz",
|
||||
"integrity": "sha512-/SF4EDWowPqV1jOgoGSGTIFsE7Ezdr7ZYxyihl5eMKVO5tlnpIhFcDavgm1hHY5GEonoOAEnJ0CU0x+tvuAuUg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lezer/common": "^1.1.0",
|
||||
"@lezer/lr": "^1.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"lezer-generator": "src/lezer-generator.cjs"
|
||||
}
|
||||
},
|
||||
"node_modules/@lezer/highlight": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz",
|
||||
"integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lezer/common": "^1.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@lezer/lr": {
|
||||
"version": "1.4.10",
|
||||
"resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.10.tgz",
|
||||
"integrity": "sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lezer/common": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@marijn/find-cluster-break": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.3.tgz",
|
||||
"integrity": "sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
@@ -2981,6 +3122,21 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/codemirror": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.2.tgz",
|
||||
"integrity": "sha512-VhydHotNW5w1UGK0Qj96BwSk/Zqbp9WbnyK2W/eVMv4QyF41INRGpjUhFJY7/uDNuudSc33a/PKr4iDqRduvHw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@codemirror/autocomplete": "^6.0.0",
|
||||
"@codemirror/commands": "^6.0.0",
|
||||
"@codemirror/language": "^6.0.0",
|
||||
"@codemirror/lint": "^6.0.0",
|
||||
"@codemirror/search": "^6.0.0",
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/color": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
|
||||
@@ -3055,6 +3211,12 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/crelt": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.7.tgz",
|
||||
"integrity": "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cssesc": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
|
||||
@@ -3084,6 +3246,10 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/decodal-codemirror": {
|
||||
"resolved": "../../packages/decodal-codemirror",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/decode-named-character-reference": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz",
|
||||
@@ -6429,6 +6595,12 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/style-mod": {
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz",
|
||||
"integrity": "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "10.2.2",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-10.2.2.tgz",
|
||||
@@ -7126,6 +7298,12 @@
|
||||
"integrity": "sha512-/BpdSx+yCQGnCvecbyXdxHDkuk55/G3xwnC0GqY4gmQ3j+A+g8kzzgB4Nk/SINjqn6+waqw3EgbVF2QKExkRxQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/w3c-keyname": {
|
||||
"version": "2.2.8",
|
||||
"resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
|
||||
"integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/web-namespaces": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/web-namespaces/-/web-namespaces-2.0.1.tgz",
|
||||
|
||||
@@ -8,15 +8,22 @@
|
||||
"build": "astro build",
|
||||
"preview": "astro preview --host 0.0.0.0",
|
||||
"build:wasm": "wasm-pack build ../../crates/decodal-wasm --target web --out-dir ../../site/decodal-site/src/wasm --release",
|
||||
"deploy": "npm run build && wrangler pages deploy dist --project-name ${CLOUDFLARE_PROJECT_NAME:-decodal-site}",
|
||||
"deploy": "npm run build && node scripts/deploy-pages.mjs",
|
||||
"deploy:wasm": "npm run build:wasm && npm run deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/check": "^0.9.4",
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10",
|
||||
"astro": "^4.16.18",
|
||||
"codemirror": "^6.0.2",
|
||||
"decodal-codemirror": "file:../../packages/decodal-codemirror",
|
||||
"marked": "^12.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lezer/generator": "^1.8.0",
|
||||
"wrangler": "^4.104.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
const projectName = process.env.CLOUDFLARE_PROJECT_NAME ?? 'decodal-site';
|
||||
const branch = process.env.CLOUDFLARE_BRANCH ?? 'master';
|
||||
|
||||
const result = spawnSync(
|
||||
'wrangler',
|
||||
['pages', 'deploy', 'dist', '--project-name', projectName, '--branch', branch],
|
||||
{ stdio: 'inherit', shell: process.platform === 'win32' },
|
||||
);
|
||||
|
||||
process.exit(result.status ?? 1);
|
||||
@@ -2,7 +2,7 @@
|
||||
import { nav } from '../lib/docs.js';
|
||||
import '../style.css';
|
||||
|
||||
const { title = 'Decodal', active = '', playground = false } = Astro.props;
|
||||
const { title = 'Decodal', active = '', playground = false, frontpage = false } = Astro.props;
|
||||
|
||||
function renderNav(items, prefix = []) {
|
||||
return `<ul class="nav-tree">${items
|
||||
@@ -25,22 +25,27 @@ function renderNav(items, prefix = []) {
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<a class="brand" href="/docs/introduction/">Decodal</a>
|
||||
<a class="brand" href="/">Decodal</a>
|
||||
<nav class="topnav">
|
||||
<a href="/docs/introduction/">Docs</a>
|
||||
<a href="/playground/">Playground</a>
|
||||
<a href="https://gitea.hareworks.net/Hare/Decodal">Source</a>
|
||||
</nav>
|
||||
</header>
|
||||
<div class={playground ? 'layout playground-layout' : 'layout'}>
|
||||
{!playground && (
|
||||
<div class={playground || frontpage ? 'layout playground-layout' : 'layout'}>
|
||||
{!playground && !frontpage && (
|
||||
<aside class="sidebar">
|
||||
<a class="sidebar-title" href="/docs/">Manual</a>
|
||||
<nav set:html={renderNav(nav)} />
|
||||
</aside>
|
||||
)}
|
||||
<main class={playground ? 'playground' : ''}>
|
||||
<main class={playground ? 'playground' : frontpage ? 'frontpage' : ''}>
|
||||
<slot />
|
||||
</main>
|
||||
</div>
|
||||
<footer class="site-footer">
|
||||
<span>2026 Hare</span>
|
||||
<a href="https://gitea.hareworks.net/Hare/Decodal">Source</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -19,11 +19,13 @@ export const docs = Object.fromEntries(
|
||||
|
||||
export const nav = [
|
||||
{ title: 'Introduction', slug: 'introduction' },
|
||||
{ title: 'Components', slug: 'components' },
|
||||
{
|
||||
title: 'Language Specification',
|
||||
slug: 'language',
|
||||
children: [
|
||||
{ title: 'Syntax', slug: 'language/syntax' },
|
||||
{ title: 'Grammar', slug: 'language/grammar' },
|
||||
{
|
||||
title: 'Value',
|
||||
slug: 'language/value',
|
||||
|
||||
@@ -25,6 +25,66 @@ export function highlightCode(code, language = '') {
|
||||
return escapeHtml(code);
|
||||
}
|
||||
|
||||
export function highlightDecodalTokens(source, tokens) {
|
||||
let html = '';
|
||||
let cursor = 0;
|
||||
for (const token of tokens) {
|
||||
if (token.start > cursor) html += escapeHtml(source.slice(cursor, token.start));
|
||||
const text = source.slice(token.start, token.end);
|
||||
const kind = tokenClass(token.kind, text);
|
||||
html += kind ? `<span class="${kind}">${escapeHtml(text)}</span>` : escapeHtml(text);
|
||||
cursor = token.end;
|
||||
}
|
||||
if (cursor < source.length) html += escapeHtml(source.slice(cursor));
|
||||
return html;
|
||||
}
|
||||
|
||||
function tokenClass(kind, text) {
|
||||
if (['let', 'in', 'fn', 'match', 'import', 'default'].includes(kind)) return 'tok-keyword';
|
||||
if (kind === 'ident' && ['String', 'Int', 'Float', 'Bool', 'Array'].includes(text)) return 'tok-type';
|
||||
if (kind === 'ident') return '';
|
||||
if (['true', 'false'].includes(kind)) return 'tok-literal';
|
||||
if (['int', 'float'].includes(kind)) return 'tok-number';
|
||||
if (kind === 'string') return 'tok-string';
|
||||
if (kind === 'regex') return 'tok-regex';
|
||||
if (kind === 'comment') return 'tok-comment';
|
||||
if (
|
||||
[
|
||||
'equal',
|
||||
'equal_equal',
|
||||
'bang',
|
||||
'bang_equal',
|
||||
'arrow',
|
||||
'amp',
|
||||
'amp_amp',
|
||||
'pipe_pipe',
|
||||
'plus',
|
||||
'plus_plus',
|
||||
'minus',
|
||||
'star',
|
||||
'slash',
|
||||
'slash_slash',
|
||||
'gt',
|
||||
'gte',
|
||||
'lt',
|
||||
'lte',
|
||||
'dot',
|
||||
'colon',
|
||||
'semicolon',
|
||||
'comma',
|
||||
'l_brace',
|
||||
'r_brace',
|
||||
'l_bracket',
|
||||
'r_bracket',
|
||||
'l_paren',
|
||||
'r_paren',
|
||||
].includes(kind)
|
||||
) {
|
||||
return 'tok-operator';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function highlightDecodal(source) {
|
||||
let html = '';
|
||||
let index = 0;
|
||||
|
||||
@@ -1,3 +1,89 @@
|
||||
---
|
||||
return Astro.redirect('/docs/introduction/');
|
||||
import ManualLayout from '../layouts/ManualLayout.astro';
|
||||
|
||||
const example = `Port = Int >= 1 & <= 65535 default 8080;
|
||||
|
||||
Server = {
|
||||
host = String default "localhost";
|
||||
port = Port;
|
||||
};
|
||||
|
||||
Production = Server & {
|
||||
host = "example.com";
|
||||
};`;
|
||||
---
|
||||
<ManualLayout title="Decodal" frontpage>
|
||||
<section class="hero">
|
||||
<h1>Decodal keeps configuration, constraints, and defaults in one composable value.</h1>
|
||||
<p class="hero-copy">
|
||||
Define structured data with constraints, compose it with patches, and materialize the result from Rust,
|
||||
WebAssembly, or the browser playground.
|
||||
</p>
|
||||
<div class="hero-actions">
|
||||
<a class="button primary" href="/playground/">Try the playground</a>
|
||||
<a class="button secondary" href="/docs/introduction/">Read the manual</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="home-packages" aria-label="Official packages">
|
||||
<h2>Official packages</h2>
|
||||
<div class="package-links">
|
||||
<a href="https://crates.io/crates/decodal">
|
||||
<span>Rust crate</span>
|
||||
<strong>crates.io/crates/decodal</strong>
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/decodal-wasm">
|
||||
<span>npm package</span>
|
||||
<strong>npmjs.com/package/decodal-wasm</strong>
|
||||
</a>
|
||||
<a href="https://jsr.io/@hare/decodal-wasm@0.1.2">
|
||||
<span>JSR package</span>
|
||||
<strong>jsr.io/@hare/decodal-wasm</strong>
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/decodal-codemirror">
|
||||
<span>CodeMirror package</span>
|
||||
<strong>npmjs.com/package/decodal-codemirror</strong>
|
||||
</a>
|
||||
<a href="https://jsr.io/@hare/decodal-codemirror@0.1.2">
|
||||
<span>CodeMirror on JSR</span>
|
||||
<strong>jsr.io/@hare/decodal-codemirror</strong>
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="home-grid" aria-label="Decodal overview">
|
||||
<article class="home-card">
|
||||
<h2>What it is</h2>
|
||||
<p>
|
||||
Decodal is a small data language for configuration shapes that need validation, defaults,
|
||||
lazy imports, and predictable composition.
|
||||
</p>
|
||||
</article>
|
||||
<article class="home-card">
|
||||
<h2>Where it runs</h2>
|
||||
<p>
|
||||
Use the Rust crate for runtime embedding, the WASM package in browsers, CodeMirror/Lezer for the Web editor,
|
||||
and Tree-sitter for general editor integration.
|
||||
</p>
|
||||
</article>
|
||||
<article class="home-card">
|
||||
<h2>Start here</h2>
|
||||
<p>
|
||||
Open the playground to run examples in your browser, or read the components page to see how the runtime and
|
||||
editor pieces fit together.
|
||||
</p>
|
||||
<p><a href="/docs/components/">View components →</a></p>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="home-example" aria-label="Decodal example">
|
||||
<div>
|
||||
<h2>A compact example</h2>
|
||||
<p>
|
||||
Constraints and defaults are values. Compose them with concrete data and materialize when the host knows what
|
||||
output shape it expects.
|
||||
</p>
|
||||
</div>
|
||||
<pre><code>{example}</code></pre>
|
||||
</section>
|
||||
</ManualLayout>
|
||||
|
||||
@@ -9,6 +9,11 @@ import ManualLayout from '../layouts/ManualLayout.astro';
|
||||
<p>Virtual files are evaluated in the browser through WebAssembly. Use import paths such as <code>./schemas/service.dcdl</code>.</p>
|
||||
</div>
|
||||
<div class="playground-actions">
|
||||
<label class="example-picker">
|
||||
<span>Example</span>
|
||||
<select id="example-select" aria-label="Playground example"></select>
|
||||
</label>
|
||||
<button id="load-example" type="button">Load</button>
|
||||
<p id="status" class="status">Loading WASM...</p>
|
||||
<button id="run" disabled>Run</button>
|
||||
</div>
|
||||
@@ -24,13 +29,10 @@ import ManualLayout from '../layouts/ManualLayout.astro';
|
||||
<button id="delete-file" class="danger-button" type="button">Delete file</button>
|
||||
</aside>
|
||||
|
||||
<label class="pane input-pane">
|
||||
<section class="pane input-pane">
|
||||
<span id="active-file">Input</span>
|
||||
<div class="editor-wrap">
|
||||
<pre id="source-highlight" aria-hidden="true"></pre>
|
||||
<textarea id="source" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</label>
|
||||
<div id="editor" class="code-editor"></div>
|
||||
</section>
|
||||
|
||||
<section class="pane output-pane">
|
||||
<span>Output</span>
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
export const playgroundExamples = [
|
||||
{
|
||||
id: 'service-deployment',
|
||||
title: 'Service deployment',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/service.dcdl";
|
||||
prod = import "./env/prod.dcdl";
|
||||
shared = import "./shared/tags.dcdl";
|
||||
in
|
||||
schema.Service & prod.ServicePatch & {
|
||||
name = "api";
|
||||
image = "registry.example.com/api:2026-06-24";
|
||||
port = 9000 + 443;
|
||||
public = prod.is_public && 9000 + 443 > 9000;
|
||||
tags = shared.common ++ ["api", "edge"];
|
||||
}
|
||||
`,
|
||||
'schemas/service.dcdl': `Service = {
|
||||
name = String;
|
||||
image = String;
|
||||
port = Int & > 443 default 8443;
|
||||
replicas = Int & > 0 default 2;
|
||||
public = Bool default false;
|
||||
feature.metrics = Bool default true;
|
||||
feature.tracing = Bool default false;
|
||||
};
|
||||
`,
|
||||
'env/prod.dcdl': `is_public = true;
|
||||
|
||||
ServicePatch = {
|
||||
replicas = 3;
|
||||
feature.tracing = true;
|
||||
};
|
||||
`,
|
||||
'shared/tags.dcdl': `common = ["decodal", "prod"];
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'access-policy',
|
||||
title: 'Access policy',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
policy = import "./policy/base.dcdl";
|
||||
teams = import "./policy/teams.dcdl";
|
||||
env = "prod";
|
||||
in
|
||||
{
|
||||
service = "payments";
|
||||
readers = policy.defaultReaders ++ teams.observability;
|
||||
writers = policy.defaultWriters ++ teams.payments;
|
||||
admins = match env {
|
||||
"prod": policy.breakglassAdmins;
|
||||
_: teams.platform;
|
||||
};
|
||||
audit.required = env == "prod";
|
||||
audit.retention_days = match env {
|
||||
"prod": 365;
|
||||
_: 30;
|
||||
};
|
||||
}
|
||||
`,
|
||||
'policy/base.dcdl': `defaultReaders = ["group:engineering", "group:support"];
|
||||
defaultWriters = ["group:platform"];
|
||||
breakglassAdmins = ["user:oncall-primary", "user:oncall-secondary"];
|
||||
`,
|
||||
'policy/teams.dcdl': `platform = ["group:platform-admins"];
|
||||
payments = ["group:payments-api", "group:payments-sre"];
|
||||
observability = ["group:observability"];
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'edge-worker',
|
||||
title: 'Edge worker config',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/worker.dcdl";
|
||||
routes = import "./routes.dcdl";
|
||||
production = true;
|
||||
in
|
||||
schema.Worker & {
|
||||
name = "decodal-docs";
|
||||
compatibility_date = "2026-06-15";
|
||||
workers_dev = !production;
|
||||
route.host = routes.primary_host;
|
||||
route.paths = routes.docs_paths ++ routes.playground_paths;
|
||||
cache.ttl_seconds = 60 * 60;
|
||||
cache.bypass = !production;
|
||||
}
|
||||
`,
|
||||
'schemas/worker.dcdl': `Worker = {
|
||||
name = String;
|
||||
compatibility_date = String;
|
||||
workers_dev = Bool default false;
|
||||
route.host = String;
|
||||
cache.ttl_seconds = Int & >= 0 default 300;
|
||||
cache.bypass = Bool default false;
|
||||
};
|
||||
`,
|
||||
'routes.dcdl': `primary_host = "decodal.example.com";
|
||||
docs_paths = ["/docs/*", "/assets/*"];
|
||||
playground_paths = ["/playground/*"];
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'data-pipeline',
|
||||
title: 'Data pipeline',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/pipeline.dcdl";
|
||||
presets = import "./presets/batch.dcdl";
|
||||
env = "staging";
|
||||
in
|
||||
schema.Pipeline & presets.Batch & {
|
||||
name = "events-rollup";
|
||||
source.topic = "events.raw";
|
||||
sink.table = "analytics.events_daily";
|
||||
workers = match env {
|
||||
"prod": 8;
|
||||
"staging": 3;
|
||||
_: 1;
|
||||
};
|
||||
alerts.enabled = env != "dev";
|
||||
transforms = presets.standardTransforms ++ ["dedupe", "aggregate_daily"];
|
||||
}
|
||||
`,
|
||||
'schemas/pipeline.dcdl': `Pipeline = {
|
||||
name = String;
|
||||
source.topic = String;
|
||||
sink.table = String;
|
||||
workers = Int & > 0 default 1;
|
||||
batch.size = Int & >= 100 default 1000;
|
||||
batch.timeout_seconds = Int & > 0 default 60;
|
||||
alerts.enabled = Bool default false;
|
||||
};
|
||||
`,
|
||||
'presets/batch.dcdl': `standardTransforms = ["parse_json", "validate_schema", "enrich_metadata"];
|
||||
|
||||
Batch = {
|
||||
batch.size = 5000;
|
||||
batch.timeout_seconds = 30 + 30;
|
||||
};
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'diagnostics',
|
||||
title: 'Diagnostics: invalid port',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/service.dcdl";
|
||||
in
|
||||
schema.Service & {
|
||||
name = "broken-api";
|
||||
port = 442;
|
||||
}
|
||||
`,
|
||||
'schemas/service.dcdl': `Service = {
|
||||
name = String;
|
||||
port = Int & > 443 default 8443;
|
||||
replicas = Int & > 0 default 2;
|
||||
};
|
||||
`,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -1,29 +1,13 @@
|
||||
import init, { evaluateProject } from '../wasm/decodal_wasm.js';
|
||||
import { highlightDecodal } from '../lib/highlight.js';
|
||||
import { EditorView, basicSetup } from 'codemirror';
|
||||
import { keymap } from '@codemirror/view';
|
||||
import { decodal } from 'decodal-codemirror';
|
||||
import { playgroundExamples } from './playground-examples.js';
|
||||
|
||||
const STORAGE_KEY = 'decodal-playground-project-v1';
|
||||
const starterProject = playgroundExamples[0];
|
||||
|
||||
const starterFiles = {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/service.dcdl";
|
||||
in
|
||||
schema.Service & {
|
||||
name = "api";
|
||||
port = 9000 + 443;
|
||||
tags = ["web"] ++ ["prod"];
|
||||
feature.enable = 9000 + 443 > 9000 && true;
|
||||
}
|
||||
`,
|
||||
'schemas/service.dcdl': `Service = {
|
||||
name = String;
|
||||
port = Int & > 443 default 8443;
|
||||
feature.enable = Bool default true;
|
||||
};
|
||||
`,
|
||||
};
|
||||
|
||||
const source = document.getElementById('source');
|
||||
const sourceHighlight = document.getElementById('source-highlight');
|
||||
const editorHost = document.getElementById('editor');
|
||||
const output = document.getElementById('output');
|
||||
const run = document.getElementById('run');
|
||||
const status = document.getElementById('status');
|
||||
@@ -31,12 +15,78 @@ const fileTree = document.getElementById('file-tree');
|
||||
const activeFile = document.getElementById('active-file');
|
||||
const newFile = document.getElementById('new-file');
|
||||
const deleteFile = document.getElementById('delete-file');
|
||||
const exampleSelect = document.getElementById('example-select');
|
||||
const loadExample = document.getElementById('load-example');
|
||||
|
||||
const project = loadProject();
|
||||
|
||||
const editorTheme = EditorView.theme({
|
||||
'&': {
|
||||
backgroundColor: '#0f172a',
|
||||
color: '#e5e7eb',
|
||||
height: '100%',
|
||||
},
|
||||
'.cm-scroller': {
|
||||
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',
|
||||
fontSize: '14px',
|
||||
lineHeight: '1.5',
|
||||
overflow: 'auto',
|
||||
},
|
||||
'.cm-content': {
|
||||
caretColor: '#e5e7eb',
|
||||
minHeight: '100%',
|
||||
padding: '12px',
|
||||
},
|
||||
'.cm-gutters': {
|
||||
backgroundColor: '#111827',
|
||||
borderRight: '1px solid #334155',
|
||||
color: '#94a3b8',
|
||||
},
|
||||
'&.cm-focused': {
|
||||
outline: 'none',
|
||||
},
|
||||
'&.cm-focused .cm-cursor': {
|
||||
borderLeftColor: '#e5e7eb',
|
||||
},
|
||||
'&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection': {
|
||||
backgroundColor: 'rgb(59 130 246 / 0.35)',
|
||||
},
|
||||
}, { dark: true });
|
||||
|
||||
const editor = new EditorView({
|
||||
doc: project.files[project.activePath] ?? '',
|
||||
parent: editorHost,
|
||||
extensions: [
|
||||
basicSetup,
|
||||
decodal(),
|
||||
editorTheme,
|
||||
keymap.of([
|
||||
{
|
||||
key: 'Mod-Enter',
|
||||
run() {
|
||||
execute();
|
||||
return true;
|
||||
},
|
||||
},
|
||||
]),
|
||||
EditorView.updateListener.of((update) => {
|
||||
if (!update.docChanged) return;
|
||||
project.files[project.activePath] = update.state.doc.toString();
|
||||
saveProject();
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
for (const example of playgroundExamples) {
|
||||
const option = document.createElement('option');
|
||||
option.value = example.id;
|
||||
option.textContent = example.title;
|
||||
exampleSelect.append(option);
|
||||
}
|
||||
exampleSelect.value = starterProject.id;
|
||||
|
||||
setActiveFile(project.activePath);
|
||||
renderFileTree();
|
||||
updateHighlight();
|
||||
|
||||
function loadProject() {
|
||||
try {
|
||||
@@ -49,7 +99,11 @@ function loadProject() {
|
||||
} catch (_error) {
|
||||
// Fall back to the starter project.
|
||||
}
|
||||
return { files: { ...starterFiles }, activePath: 'main.dcdl' };
|
||||
return { files: cloneFiles(starterProject.files), activePath: starterProject.activePath };
|
||||
}
|
||||
|
||||
function cloneFiles(files) {
|
||||
return Object.fromEntries(Object.entries(files).map(([path, source]) => [path, source]));
|
||||
}
|
||||
|
||||
function normalizeFiles(files) {
|
||||
@@ -65,6 +119,17 @@ function saveProject() {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(project));
|
||||
}
|
||||
|
||||
function loadExampleProject(exampleId) {
|
||||
const example = playgroundExamples.find((item) => item.id === exampleId) ?? starterProject;
|
||||
project.files = cloneFiles(example.files);
|
||||
project.activePath = example.activePath;
|
||||
exampleSelect.value = example.id;
|
||||
setActiveFile(project.activePath);
|
||||
output.textContent = '';
|
||||
output.classList.remove('error');
|
||||
execute();
|
||||
}
|
||||
|
||||
function normalizePath(path) {
|
||||
const parts = [];
|
||||
for (const part of String(path).replaceAll('\\', '/').split('/')) {
|
||||
@@ -75,30 +140,36 @@ function normalizePath(path) {
|
||||
return parts.join('/');
|
||||
}
|
||||
|
||||
function getEditorText() {
|
||||
return editor.state.doc.toString();
|
||||
}
|
||||
|
||||
function setEditorText(value) {
|
||||
editor.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: editor.state.doc.length,
|
||||
insert: value,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function setActiveFile(path) {
|
||||
const normalized = normalizePath(path);
|
||||
if (project.files[normalized] === undefined) return;
|
||||
if (project.activePath && project.files[project.activePath] !== undefined) {
|
||||
project.files[project.activePath] = getEditorText();
|
||||
}
|
||||
project.activePath = normalized;
|
||||
source.value = project.files[normalized];
|
||||
setEditorText(project.files[normalized]);
|
||||
activeFile.textContent = normalized;
|
||||
deleteFile.disabled = Object.keys(project.files).length <= 1;
|
||||
updateHighlight();
|
||||
syncHighlightScroll();
|
||||
renderFileTree();
|
||||
saveProject();
|
||||
}
|
||||
|
||||
function updateHighlight() {
|
||||
sourceHighlight.innerHTML = `${highlightDecodal(source.value)}\n`;
|
||||
}
|
||||
|
||||
function syncHighlightScroll() {
|
||||
sourceHighlight.scrollTop = source.scrollTop;
|
||||
sourceHighlight.scrollLeft = source.scrollLeft;
|
||||
}
|
||||
|
||||
function execute() {
|
||||
project.files[project.activePath] = source.value;
|
||||
project.files[project.activePath] = getEditorText();
|
||||
saveProject();
|
||||
const result = JSON.parse(evaluateProject(project.activePath, JSON.stringify(project.files)));
|
||||
output.textContent = result.ok ? result.output : result.error;
|
||||
@@ -165,6 +236,12 @@ try {
|
||||
}
|
||||
|
||||
run.addEventListener('click', execute);
|
||||
loadExample.addEventListener('click', () => {
|
||||
const example = playgroundExamples.find((item) => item.id === exampleSelect.value);
|
||||
if (!example) return;
|
||||
if (!confirm(`Load example "${example.title}"? This replaces the current virtual files.`)) return;
|
||||
loadExampleProject(example.id);
|
||||
});
|
||||
newFile.addEventListener('click', () => {
|
||||
const path = normalizePath(prompt('New virtual file path', 'schemas/types.dcdl') ?? '');
|
||||
if (!path) return;
|
||||
@@ -172,7 +249,7 @@ newFile.addEventListener('click', () => {
|
||||
setActiveFile(path);
|
||||
return;
|
||||
}
|
||||
project.files[path] = path.endsWith('.dcdl') ? '' : '// Decodal source\n';
|
||||
project.files[path] = 'value = "new";\n';
|
||||
setActiveFile(path);
|
||||
});
|
||||
deleteFile.addEventListener('click', () => {
|
||||
@@ -181,13 +258,3 @@ deleteFile.addEventListener('click', () => {
|
||||
delete project.files[project.activePath];
|
||||
setActiveFile(Object.keys(project.files).sort()[0]);
|
||||
});
|
||||
source.addEventListener('input', () => {
|
||||
project.files[project.activePath] = source.value;
|
||||
updateHighlight();
|
||||
syncHighlightScroll();
|
||||
saveProject();
|
||||
});
|
||||
source.addEventListener('scroll', syncHighlightScroll);
|
||||
source.addEventListener('keydown', (event) => {
|
||||
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') execute();
|
||||
});
|
||||
|
||||
+176
-29
@@ -89,10 +89,21 @@ a:hover {
|
||||
color: var(--topbar-link);
|
||||
}
|
||||
|
||||
.site-footer {
|
||||
align-items: center;
|
||||
border-top: 1px solid var(--border);
|
||||
color: var(--subtle);
|
||||
display: flex;
|
||||
font-size: 0.9rem;
|
||||
gap: 14px;
|
||||
justify-content: center;
|
||||
padding: 15px 24px;
|
||||
}
|
||||
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 300px minmax(0, 1fr);
|
||||
min-height: calc(100vh - 56px);
|
||||
min-height: calc(100vh - 104px);
|
||||
}
|
||||
|
||||
.playground-layout {
|
||||
@@ -281,7 +292,30 @@ main.playground {
|
||||
.playground-actions {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.example-picker {
|
||||
align-items: center;
|
||||
color: var(--muted);
|
||||
display: flex;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
gap: 6px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.example-picker select {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text);
|
||||
font: inherit;
|
||||
min-width: 180px;
|
||||
padding: 7px 10px;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
button {
|
||||
@@ -396,43 +430,26 @@ button:disabled {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.editor-wrap {
|
||||
.code-editor {
|
||||
background: var(--editor-bg);
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.editor-wrap pre,
|
||||
.editor-wrap textarea {
|
||||
border: 0;
|
||||
box-sizing: border-box;
|
||||
font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||
inset: 0;
|
||||
margin: 0;
|
||||
overflow: auto;
|
||||
padding: 12px;
|
||||
position: absolute;
|
||||
tab-size: 2;
|
||||
white-space: pre;
|
||||
.code-editor .cm-editor {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.editor-wrap pre {
|
||||
color: var(--editor-text);
|
||||
pointer-events: none;
|
||||
.code-editor .cm-line {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.editor-wrap textarea {
|
||||
background: transparent;
|
||||
caret-color: var(--editor-text);
|
||||
color: transparent;
|
||||
outline: none;
|
||||
resize: none;
|
||||
width: 100%;
|
||||
.code-editor .cm-activeLine {
|
||||
background: rgb(59 130 246 / 0.08);
|
||||
}
|
||||
|
||||
.editor-wrap textarea::selection {
|
||||
background: var(--selection);
|
||||
.code-editor .cm-activeLineGutter {
|
||||
background: rgb(59 130 246 / 0.12);
|
||||
}
|
||||
|
||||
.output-pane pre {
|
||||
@@ -452,6 +469,130 @@ button:disabled {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.frontpage {
|
||||
max-width: 1120px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.hero {
|
||||
padding: 5rem 0 4rem;
|
||||
}
|
||||
|
||||
.hero h1 {
|
||||
font-size: clamp(2.4rem, 6vw, 5rem);
|
||||
line-height: 0.95;
|
||||
letter-spacing: -0.06em;
|
||||
margin: 0;
|
||||
max-width: 950px;
|
||||
}
|
||||
|
||||
.hero-copy {
|
||||
color: var(--muted);
|
||||
font-size: 1.2rem;
|
||||
line-height: 1.7;
|
||||
max-width: 760px;
|
||||
margin: 1.5rem 0 0;
|
||||
}
|
||||
|
||||
.hero-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.9rem;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.button {
|
||||
border-radius: 999px;
|
||||
font-weight: 700;
|
||||
padding: 0.8rem 1.15rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.button.primary {
|
||||
background: var(--link);
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.button.secondary {
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.home-packages {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 18px;
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 1.4rem;
|
||||
}
|
||||
|
||||
.home-packages h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.package-links {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.package-links a {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
display: block;
|
||||
padding: 1rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.package-links span {
|
||||
color: var(--muted);
|
||||
display: block;
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
|
||||
.package-links strong {
|
||||
color: var(--text);
|
||||
display: block;
|
||||
font-size: 0.95rem;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.home-grid {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.home-card,
|
||||
.home-example {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 18px;
|
||||
padding: 1.4rem;
|
||||
}
|
||||
|
||||
.home-card h2,
|
||||
.home-example h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.home-card p:last-child,
|
||||
.home-example p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.home-example {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
|
||||
}
|
||||
|
||||
.home-example pre {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.layout {
|
||||
grid-template-columns: 1fr;
|
||||
@@ -461,7 +602,13 @@ button:disabled {
|
||||
border-right: 0;
|
||||
max-height: 260px;
|
||||
}
|
||||
.playground-shell {
|
||||
.playground-shell,
|
||||
.home-grid,
|
||||
.home-example,
|
||||
.package-links {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.hero {
|
||||
padding-top: 3rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# Decodal
|
||||
|
||||
Decodal is a small deterministic DSL for describing, composing, validating, and materializing structured data.
|
||||
|
||||
It is designed around a lightweight Rust library:
|
||||
|
||||
- host-supplied imports through `SourceLoader`
|
||||
- no filesystem access in the library core
|
||||
- concrete and abstract values with constraints and defaults
|
||||
- deterministic expression evaluation
|
||||
- optional regex support behind a Cargo feature
|
||||
- browser playground support through WebAssembly
|
||||
|
||||
## Library crate
|
||||
|
||||
Embedded hosts should depend on `decodal` and provide imports with a `SourceLoader`.
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
decodal = "0.1"
|
||||
```
|
||||
|
||||
## Derive support
|
||||
|
||||
For embedded Rust applications, Decodal can generate a schema and typed decoder from a Rust struct with the `derive` feature.
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
decodal = { version = "0.1", features = ["derive"] }
|
||||
```
|
||||
|
||||
```rust
|
||||
use decodal::{Decodal, DecodalDecode, DecodalSchema, Engine};
|
||||
|
||||
#[derive(Decodal)]
|
||||
struct Service {
|
||||
name: String,
|
||||
#[decodal(gt = 443, default = 8443)]
|
||||
port: i64,
|
||||
#[decodal(rename = "feature.enable", default = true)]
|
||||
feature_enabled: bool,
|
||||
}
|
||||
```
|
||||
|
||||
The derive implements:
|
||||
|
||||
- `DecodalSchema`, which produces a host schema for `Engine::bind_global`
|
||||
- `DecodalDecode`, which converts materialized `Data` into the Rust struct
|
||||
|
||||
## CLI
|
||||
|
||||
A standalone CLI is kept in this repository as the `decodal-cli` workspace package.
|
||||
It builds a `decodal` binary, but it is not the primary crates.io package.
|
||||
|
||||
Run a Decodal file from the repository:
|
||||
|
||||
```sh
|
||||
cargo run -q -p decodal-cli -- examples/advanced/main.dcdl
|
||||
```
|
||||
|
||||
Enable optional regex support when needed:
|
||||
|
||||
```sh
|
||||
cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
|
||||
```
|
||||
|
||||
## Web playground
|
||||
|
||||
The static documentation site and browser playground live under:
|
||||
|
||||
```text
|
||||
site/decodal-site/
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of:
|
||||
|
||||
- Apache License, Version 2.0
|
||||
- MIT license
|
||||
|
||||
at your option.
|
||||
+7
-6
@@ -9,12 +9,13 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
||||
|
||||
export interface InitOutput {
|
||||
readonly memory: WebAssembly.Memory;
|
||||
readonly evaluate: (a: number, b: number, c: number) => void;
|
||||
readonly evaluateProject: (a: number, b: number, c: number, d: number, e: number) => void;
|
||||
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||
readonly __wbindgen_export: (a: number, b: number) => number;
|
||||
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
||||
readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
|
||||
readonly evaluate: (a: number, b: number) => [number, number];
|
||||
readonly evaluateProject: (a: number, b: number, c: number, d: number) => [number, number];
|
||||
readonly __wbindgen_externrefs: WebAssembly.Table;
|
||||
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
||||
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
||||
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
||||
readonly __wbindgen_start: () => void;
|
||||
}
|
||||
|
||||
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
||||
|
||||
@@ -8,18 +8,14 @@ export function evaluate(source) {
|
||||
let deferred2_0;
|
||||
let deferred2_1;
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
||||
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.evaluate(retptr, ptr0, len0);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
deferred2_0 = r0;
|
||||
deferred2_1 = r1;
|
||||
return getStringFromWasm0(r0, r1);
|
||||
const ret = wasm.evaluate(ptr0, len0);
|
||||
deferred2_0 = ret[0];
|
||||
deferred2_1 = ret[1];
|
||||
return getStringFromWasm0(ret[0], ret[1]);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
|
||||
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,25 +28,30 @@ export function evaluateProject(entry, files_json) {
|
||||
let deferred3_0;
|
||||
let deferred3_1;
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passStringToWasm0(entry, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
||||
const ptr0 = passStringToWasm0(entry, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passStringToWasm0(files_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
||||
const ptr1 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
wasm.evaluateProject(retptr, ptr0, len0, ptr1, len1);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
deferred3_0 = r0;
|
||||
deferred3_1 = r1;
|
||||
return getStringFromWasm0(r0, r1);
|
||||
const ret = wasm.evaluateProject(ptr0, len0, ptr1, len1);
|
||||
deferred3_0 = ret[0];
|
||||
deferred3_1 = ret[1];
|
||||
return getStringFromWasm0(ret[0], ret[1]);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
||||
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
||||
}
|
||||
}
|
||||
function __wbg_get_imports() {
|
||||
const import0 = {
|
||||
__proto__: null,
|
||||
__wbindgen_init_externref_table: function() {
|
||||
const table = wasm.__wbindgen_externrefs;
|
||||
const offset = table.grow(4);
|
||||
table.set(0, undefined);
|
||||
table.set(offset + 0, undefined);
|
||||
table.set(offset + 1, null);
|
||||
table.set(offset + 2, true);
|
||||
table.set(offset + 3, false);
|
||||
},
|
||||
};
|
||||
return {
|
||||
__proto__: null,
|
||||
@@ -58,14 +59,6 @@ function __wbg_get_imports() {
|
||||
};
|
||||
}
|
||||
|
||||
let cachedDataViewMemory0 = null;
|
||||
function getDataViewMemory0() {
|
||||
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
||||
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
||||
}
|
||||
return cachedDataViewMemory0;
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
return decodeText(ptr >>> 0, len);
|
||||
}
|
||||
@@ -149,8 +142,8 @@ function __wbg_finalize_init(instance, module) {
|
||||
wasmInstance = instance;
|
||||
wasm = instance.exports;
|
||||
wasmModule = module;
|
||||
cachedDataViewMemory0 = null;
|
||||
cachedUint8ArrayMemory0 = null;
|
||||
wasm.__wbindgen_start();
|
||||
return wasm;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
+7
-6
@@ -1,9 +1,10 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const evaluate: (a: number, b: number, c: number) => void;
|
||||
export const evaluateProject: (a: number, b: number, c: number, d: number, e: number) => void;
|
||||
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||
export const __wbindgen_export: (a: number, b: number) => number;
|
||||
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
||||
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|
||||
export const evaluate: (a: number, b: number) => [number, number];
|
||||
export const evaluateProject: (a: number, b: number, c: number, d: number) => [number, number];
|
||||
export const __wbindgen_externrefs: WebAssembly.Table;
|
||||
export const __wbindgen_malloc: (a: number, b: number) => number;
|
||||
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
||||
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
||||
export const __wbindgen_start: () => void;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@hare/decodal-wasm",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"exports": "./decodal_wasm.js",
|
||||
"publish": {
|
||||
"include": [
|
||||
"README.md",
|
||||
"decodal_wasm.js",
|
||||
"decodal_wasm.d.ts",
|
||||
"decodal_wasm_bg.wasm",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
{
|
||||
"name": "decodal-wasm",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"description": "WebAssembly wrapper for evaluating Decodal in browser playgrounds.",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.hareworks.net/Hare/Decodal"
|
||||
},
|
||||
"files": [
|
||||
"decodal_wasm_bg.wasm",
|
||||
"decodal_wasm.js",
|
||||
@@ -11,5 +17,11 @@
|
||||
"types": "decodal_wasm.d.ts",
|
||||
"sideEffects": [
|
||||
"./snippets/*"
|
||||
],
|
||||
"keywords": [
|
||||
"decodal",
|
||||
"wasm",
|
||||
"dsl",
|
||||
"config"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user