Compare commits
66
Commits
main
...
46b2b3b1b6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46b2b3b1b6 | ||
|
|
5a05da6fe4 | ||
|
|
aa0f464320 | ||
|
|
fc1f3e0b25 | ||
|
|
8eac5c5cb4 | ||
|
|
59cb8f31e4 | ||
|
|
4eee2cd2c9 | ||
|
|
44b6041e60 | ||
|
|
a95afe0463 | ||
|
|
43ab6244ef | ||
|
|
1d4503b015 | ||
|
|
250e29e00c | ||
|
|
1080081cec | ||
|
|
43f692e75c | ||
|
|
5b26d071ca | ||
|
|
a653f0b7c6 | ||
|
|
384d17b539 | ||
|
|
09a84264ab | ||
|
|
0a8c261545 | ||
|
|
a8a46998a8 | ||
|
|
e4a9f80617 | ||
|
|
0e2a7b35d2 | ||
|
|
ac99c4cb4e | ||
|
|
22f6bc1ab9 | ||
|
|
16006d000a | ||
|
|
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 | ||
|
|
d8af980f7d | ||
|
|
a2a6dee025 | ||
|
|
cc5ab63922 | ||
|
|
8b3df21cfa | ||
|
|
01ad6dca52 | ||
|
|
6da0ec4c77 | ||
|
|
683151f6bd | ||
|
|
9e728fb634 | ||
|
|
2fe54bda62 | ||
|
|
3f7dd7c692 | ||
|
|
dc28cddbff | ||
|
|
aa6e5c51c1 | ||
|
|
4ab47e5719 | ||
|
|
19c9de1601 | ||
|
|
0e873fbd51 | ||
|
|
4020b7c2d5 |
@@ -3,3 +3,9 @@
|
||||
/.env
|
||||
/.yoi
|
||||
/result
|
||||
node_modules
|
||||
/dist
|
||||
site/decodal-site/dist
|
||||
|
||||
# Astro
|
||||
site/decodal-site/.astro
|
||||
|
||||
Generated
+234
-5
@@ -12,25 +12,114 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal"
|
||||
version = "0.1.0"
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5d6cac793997bd970000024b2934968efe83b382de4fdcf4fcb46b6ee4ad996"
|
||||
dependencies = [
|
||||
"decodal-core",
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-core"
|
||||
version = "0.1.0"
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "decodal"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal-derive",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-cli"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-derive"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-language-tools"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal",
|
||||
"serde_json",
|
||||
"tree-sitter",
|
||||
"tree-sitter-decodal",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "decodal-wasm"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"decodal",
|
||||
"serde_json",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.4"
|
||||
@@ -59,3 +148,143 @@ name = "regex-syntax"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.117"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter"
|
||||
version = "0.22.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter-decodal"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"tree-sitter",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.125"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ddb3f79143bced6de84270411622a2699cee572fc0875aeaf1e7867cf9fca1a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.125"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e21a184b13fb19e157296e2c46056aec9092264fab83e4ba59e68c61b323c3d"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.125"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fecefd9c35bd935a20fc3fc344b5f29138961e4f47fb03297d88f2587afb5ebd"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.125"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23939e44bb9a5d7576fa2b563dc2e136628f1224e88a8deed09e04858b77871f"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||
|
||||
+15
-7
@@ -2,12 +2,20 @@
|
||||
members = [
|
||||
"crates/decodal-core",
|
||||
"crates/decodal-cli",
|
||||
"crates/decodal-wasm",
|
||||
"crates/decodal-derive",
|
||||
"crates/decodal-language-tools",
|
||||
]
|
||||
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,19 +4,22 @@ use std::{
|
||||
process::ExitCode,
|
||||
};
|
||||
|
||||
use decodal_core::{Data, Diagnostic, DiagnosticKind, Engine, LoadedSource, SourceLoader, Span};
|
||||
use decodal::{
|
||||
Data, Diagnostic, DiagnosticKind, Engine, LoadedSource, SourceId, SourceLoader, Span,
|
||||
format_diagnostic_with,
|
||||
};
|
||||
|
||||
fn main() -> ExitCode {
|
||||
match run() {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(error) => {
|
||||
print_diagnostic(&error);
|
||||
eprintln!("{error}");
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), Diagnostic> {
|
||||
fn run() -> Result<(), String> {
|
||||
let mut args = env::args().skip(1);
|
||||
let first = args.next().unwrap_or_else(|| String::from("--help"));
|
||||
match first.as_str() {
|
||||
@@ -25,7 +28,7 @@ fn run() -> Result<(), Diagnostic> {
|
||||
Ok(())
|
||||
}
|
||||
"--version" | "-V" => {
|
||||
println!("Decodal {}", decodal_core::version());
|
||||
println!("Decodal {}", decodal::version());
|
||||
Ok(())
|
||||
}
|
||||
"check" => {
|
||||
@@ -51,12 +54,19 @@ fn run() -> Result<(), Diagnostic> {
|
||||
}
|
||||
}
|
||||
|
||||
fn materialize_path(path: &str) -> Result<Data, Diagnostic> {
|
||||
let root = read_root_source(path)?;
|
||||
fn materialize_path(path: &str) -> Result<Data, String> {
|
||||
let root = read_root_source(path).map_err(format_raw_diagnostic)?;
|
||||
let root_name = root.name.clone();
|
||||
let mut engine = Engine::new(FsLoader);
|
||||
let module = engine.add_root_source(root.key, root.name, &root.source)?;
|
||||
let value = engine.eval_module(module)?;
|
||||
engine.materialize(&value)
|
||||
let module = engine
|
||||
.add_root_source(root.key, root.name, &root.source)
|
||||
.map_err(|error| format_diagnostic_with_root(&error, &root_name))?;
|
||||
let value = engine
|
||||
.eval_module(module)
|
||||
.map_err(|error| engine.format_diagnostic(&error))?;
|
||||
engine
|
||||
.materialize(&value)
|
||||
.map_err(|error| engine.format_diagnostic(&error))
|
||||
}
|
||||
|
||||
fn read_root_source(path: &str) -> Result<LoadedSource, Diagnostic> {
|
||||
@@ -139,15 +149,12 @@ fn print_help() {
|
||||
println!(" decodal - Read DCDL source from stdin");
|
||||
}
|
||||
|
||||
fn print_diagnostic(error: &Diagnostic) {
|
||||
eprintln!(
|
||||
"error[{kind:?}] {source}:{start}..{end}: {message}",
|
||||
kind = error.kind,
|
||||
source = error.span.source.0,
|
||||
start = error.span.start,
|
||||
end = error.span.end,
|
||||
message = error.message,
|
||||
);
|
||||
fn format_diagnostic_with_root(error: &Diagnostic, root_name: &str) -> String {
|
||||
format_diagnostic_with(error, |source| (source == SourceId(0)).then_some(root_name))
|
||||
}
|
||||
|
||||
fn format_raw_diagnostic(error: Diagnostic) -> String {
|
||||
format_diagnostic_with(&error, |_| None)
|
||||
}
|
||||
|
||||
fn print_data(data: &Data, indent: usize) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -50,6 +50,9 @@ pub enum Expr {
|
||||
Ident(String),
|
||||
Object(Vec<Field>),
|
||||
Array(Vec<ExprId>),
|
||||
ArrayConstraint {
|
||||
item: ExprId,
|
||||
},
|
||||
Let {
|
||||
bindings: Vec<Field>,
|
||||
body: ExprId,
|
||||
@@ -71,6 +74,10 @@ pub enum Expr {
|
||||
scrutinee: ExprId,
|
||||
arms: Vec<MatchArm>,
|
||||
},
|
||||
Unary {
|
||||
op: UnaryOp,
|
||||
expr: ExprId,
|
||||
},
|
||||
Binary {
|
||||
op: BinaryOp,
|
||||
lhs: ExprId,
|
||||
@@ -117,8 +124,27 @@ pub enum Literal {
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum UnaryOp {
|
||||
Neg,
|
||||
Not,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BinaryOp {
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
Div,
|
||||
Concat,
|
||||
Equal,
|
||||
NotEqual,
|
||||
Greater,
|
||||
GreaterEqual,
|
||||
Less,
|
||||
LessEqual,
|
||||
LogicalAnd,
|
||||
LogicalOr,
|
||||
And,
|
||||
Patch,
|
||||
}
|
||||
|
||||
@@ -3,103 +3,190 @@ use alloc::{string::String, vec::Vec};
|
||||
use crate::{
|
||||
Diagnostic, DiagnosticKind, Span,
|
||||
ast::CompareOp,
|
||||
runtime::{Constraint, LiteralValue, PrimitiveType},
|
||||
runtime::{Constraint, ConstraintEntry, LiteralValue, PrimitiveType},
|
||||
};
|
||||
|
||||
pub fn normalize_constraints(
|
||||
constraints: Vec<Constraint>,
|
||||
constraints: Vec<ConstraintEntry>,
|
||||
span: Span,
|
||||
) -> crate::Result<Vec<Constraint>> {
|
||||
let mut primitive = None;
|
||||
let mut lower: Option<Bound> = None;
|
||||
let mut upper: Option<Bound> = None;
|
||||
) -> crate::Result<Vec<ConstraintEntry>> {
|
||||
let mut primitive: Option<(PrimitiveType, Span)> = None;
|
||||
let mut array_span: Option<Span> = None;
|
||||
let mut lower: Option<(Bound, Span)> = None;
|
||||
let mut upper: Option<(Bound, Span)> = None;
|
||||
let mut rest = Vec::new();
|
||||
|
||||
for constraint in constraints {
|
||||
match constraint {
|
||||
for entry in constraints {
|
||||
match entry.constraint {
|
||||
Constraint::Type(next) => match primitive {
|
||||
Some(current) if current != next => {
|
||||
Some((current, current_span)) if current != next => {
|
||||
return Err(Diagnostic::new(
|
||||
DiagnosticKind::Conflict,
|
||||
span,
|
||||
"primitive type constraints conflict",
|
||||
));
|
||||
)
|
||||
.with_label(current_span, "first primitive constraint")
|
||||
.with_label(entry.span, "conflicting primitive constraint"));
|
||||
}
|
||||
Some(_) => {}
|
||||
None => primitive = Some(next),
|
||||
None => primitive = Some((next, entry.span)),
|
||||
},
|
||||
Constraint::Compare(op, value) => {
|
||||
let number = Number::from_literal(&value).ok_or_else(|| {
|
||||
Diagnostic::new(
|
||||
DiagnosticKind::TypeMismatch,
|
||||
span,
|
||||
entry.span,
|
||||
"comparison constraints require numeric literals",
|
||||
)
|
||||
})?;
|
||||
match op {
|
||||
CompareOp::Gt => merge_lower(&mut lower, Bound::new(number, false)),
|
||||
CompareOp::Gte => merge_lower(&mut lower, Bound::new(number, true)),
|
||||
CompareOp::Lt => merge_upper(&mut upper, Bound::new(number, false)),
|
||||
CompareOp::Lte => merge_upper(&mut upper, Bound::new(number, true)),
|
||||
CompareOp::Gt => {
|
||||
merge_lower(&mut lower, (Bound::new(number, false), entry.span))
|
||||
}
|
||||
CompareOp::Gte => {
|
||||
merge_lower(&mut lower, (Bound::new(number, true), entry.span))
|
||||
}
|
||||
CompareOp::Lt => {
|
||||
merge_upper(&mut upper, (Bound::new(number, false), entry.span))
|
||||
}
|
||||
CompareOp::Lte => {
|
||||
merge_upper(&mut upper, (Bound::new(number, true), entry.span))
|
||||
}
|
||||
CompareOp::Eq => {
|
||||
merge_lower(&mut lower, Bound::new(number, true));
|
||||
merge_upper(&mut upper, Bound::new(number, true));
|
||||
merge_lower(&mut lower, (Bound::new(number, true), entry.span));
|
||||
merge_upper(&mut upper, (Bound::new(number, true), entry.span));
|
||||
}
|
||||
}
|
||||
}
|
||||
Constraint::Regex(pattern) => rest.push(Constraint::Regex(pattern)),
|
||||
Constraint::BuiltinPredicate(name) => rest.push(Constraint::BuiltinPredicate(name)),
|
||||
Constraint::Regex(pattern) => rest.push(ConstraintEntry {
|
||||
constraint: Constraint::Regex(pattern),
|
||||
span: entry.span,
|
||||
}),
|
||||
Constraint::ArrayItems(item) => {
|
||||
array_span.get_or_insert(entry.span);
|
||||
rest.push(ConstraintEntry {
|
||||
constraint: Constraint::ArrayItems(item),
|
||||
span: entry.span,
|
||||
});
|
||||
}
|
||||
Constraint::BuiltinPredicate(name) => rest.push(ConstraintEntry {
|
||||
constraint: Constraint::BuiltinPredicate(name),
|
||||
span: entry.span,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
if matches!(primitive, Some(PrimitiveType::String | PrimitiveType::Bool))
|
||||
if let (Some((_, primitive_span)), Some(array_span)) = (primitive, array_span) {
|
||||
return Err(Diagnostic::new(
|
||||
DiagnosticKind::Conflict,
|
||||
span,
|
||||
"array element constraints conflict with primitive type constraints",
|
||||
)
|
||||
.with_label(primitive_span, "primitive type constraint")
|
||||
.with_label(array_span, "array element constraint"));
|
||||
}
|
||||
|
||||
if let Some(array_span) = array_span
|
||||
&& (lower.is_some() || upper.is_some())
|
||||
{
|
||||
return Err(Diagnostic::new(
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
DiagnosticKind::Conflict,
|
||||
span,
|
||||
"numeric comparison constraints conflict with array element constraints",
|
||||
)
|
||||
.with_label(array_span, "array element constraint");
|
||||
if let Some((_, lower_span)) = lower {
|
||||
diagnostic = diagnostic.with_label(lower_span, "numeric comparison constraint");
|
||||
}
|
||||
if let Some((_, upper_span)) = upper {
|
||||
diagnostic = diagnostic.with_label(upper_span, "numeric comparison constraint");
|
||||
}
|
||||
return Err(diagnostic);
|
||||
}
|
||||
|
||||
if matches!(
|
||||
primitive,
|
||||
Some((PrimitiveType::String | PrimitiveType::Bool, _))
|
||||
) && (lower.is_some() || upper.is_some())
|
||||
{
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
DiagnosticKind::Conflict,
|
||||
span,
|
||||
"numeric comparison constraints conflict with non-numeric primitive type",
|
||||
));
|
||||
);
|
||||
if let Some((_, primitive_span)) = primitive {
|
||||
diagnostic = diagnostic.with_label(primitive_span, "non-numeric primitive constraint");
|
||||
}
|
||||
if let Some((_, lower_span)) = lower {
|
||||
diagnostic = diagnostic.with_label(lower_span, "numeric comparison constraint");
|
||||
}
|
||||
if let Some((_, upper_span)) = upper {
|
||||
diagnostic = diagnostic.with_label(upper_span, "numeric comparison constraint");
|
||||
}
|
||||
return Err(diagnostic);
|
||||
}
|
||||
|
||||
if primitive == Some(PrimitiveType::Int)
|
||||
if matches!(primitive, Some((PrimitiveType::Int, _)))
|
||||
&& lower
|
||||
.iter()
|
||||
.chain(upper.iter())
|
||||
.any(|bound| !matches!(bound.number, Number::Int(_)))
|
||||
.any(|(bound, _)| !matches!(bound.number, Number::Int(_)))
|
||||
{
|
||||
return Err(Diagnostic::new(
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
DiagnosticKind::Conflict,
|
||||
span,
|
||||
"Int comparison constraints must use integer literals",
|
||||
));
|
||||
);
|
||||
if let Some((_, primitive_span)) = primitive {
|
||||
diagnostic = diagnostic.with_label(primitive_span, "Int primitive constraint");
|
||||
}
|
||||
if let Some((bound, bound_span)) = lower {
|
||||
if !matches!(bound.number, Number::Int(_)) {
|
||||
diagnostic = diagnostic.with_label(bound_span, "non-integer comparison constraint");
|
||||
}
|
||||
}
|
||||
if let Some((bound, bound_span)) = upper {
|
||||
if !matches!(bound.number, Number::Int(_)) {
|
||||
diagnostic = diagnostic.with_label(bound_span, "non-integer comparison constraint");
|
||||
}
|
||||
}
|
||||
return Err(diagnostic);
|
||||
}
|
||||
|
||||
ensure_bounds_non_empty(primitive, lower, upper, span)?;
|
||||
|
||||
let mut normalized = Vec::new();
|
||||
if let Some(primitive) = primitive {
|
||||
normalized.push(Constraint::Type(primitive));
|
||||
if let Some((primitive, primitive_span)) = primitive {
|
||||
normalized.push(ConstraintEntry {
|
||||
constraint: Constraint::Type(primitive),
|
||||
span: primitive_span,
|
||||
});
|
||||
}
|
||||
if let Some(lower) = lower {
|
||||
normalized.push(Constraint::Compare(
|
||||
if lower.inclusive {
|
||||
CompareOp::Gte
|
||||
} else {
|
||||
CompareOp::Gt
|
||||
},
|
||||
lower.number.into_literal(),
|
||||
));
|
||||
if let Some((lower, lower_span)) = lower {
|
||||
normalized.push(ConstraintEntry {
|
||||
constraint: Constraint::Compare(
|
||||
if lower.inclusive {
|
||||
CompareOp::Gte
|
||||
} else {
|
||||
CompareOp::Gt
|
||||
},
|
||||
lower.number.into_literal(),
|
||||
),
|
||||
span: lower_span,
|
||||
});
|
||||
}
|
||||
if let Some(upper) = upper {
|
||||
normalized.push(Constraint::Compare(
|
||||
if upper.inclusive {
|
||||
CompareOp::Lte
|
||||
} else {
|
||||
CompareOp::Lt
|
||||
},
|
||||
upper.number.into_literal(),
|
||||
));
|
||||
if let Some((upper, upper_span)) = upper {
|
||||
normalized.push(ConstraintEntry {
|
||||
constraint: Constraint::Compare(
|
||||
if upper.inclusive {
|
||||
CompareOp::Lte
|
||||
} else {
|
||||
CompareOp::Lt
|
||||
},
|
||||
upper.number.into_literal(),
|
||||
),
|
||||
span: upper_span,
|
||||
});
|
||||
}
|
||||
normalized.extend(rest);
|
||||
Ok(normalized)
|
||||
@@ -147,18 +234,22 @@ impl Number {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_lower(current: &mut Option<Bound>, next: Bound) {
|
||||
fn merge_lower(current: &mut Option<(Bound, Span)>, next: (Bound, Span)) {
|
||||
match current {
|
||||
None => *current = Some(next),
|
||||
Some(current_bound) if is_stricter_lower(next, *current_bound) => *current_bound = next,
|
||||
Some((current_bound, _)) if is_stricter_lower(next.0, *current_bound) => {
|
||||
*current = Some(next)
|
||||
}
|
||||
Some(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_upper(current: &mut Option<Bound>, next: Bound) {
|
||||
fn merge_upper(current: &mut Option<(Bound, Span)>, next: (Bound, Span)) {
|
||||
match current {
|
||||
None => *current = Some(next),
|
||||
Some(current_bound) if is_stricter_upper(next, *current_bound) => *current_bound = next,
|
||||
Some((current_bound, _)) if is_stricter_upper(next.0, *current_bound) => {
|
||||
*current = Some(next)
|
||||
}
|
||||
Some(_) => {}
|
||||
}
|
||||
}
|
||||
@@ -178,28 +269,32 @@ fn is_stricter_upper(next: Bound, current: Bound) -> bool {
|
||||
}
|
||||
|
||||
fn ensure_bounds_non_empty(
|
||||
primitive: Option<PrimitiveType>,
|
||||
lower: Option<Bound>,
|
||||
upper: Option<Bound>,
|
||||
primitive: Option<(PrimitiveType, Span)>,
|
||||
lower: Option<(Bound, Span)>,
|
||||
upper: Option<(Bound, Span)>,
|
||||
span: Span,
|
||||
) -> crate::Result<()> {
|
||||
if primitive == Some(PrimitiveType::Int) {
|
||||
let min = lower.map(int_lower_bound).unwrap_or(i128::from(i64::MIN));
|
||||
let max = upper.map(int_upper_bound).unwrap_or(i128::from(i64::MAX));
|
||||
if matches!(primitive, Some((PrimitiveType::Int, _))) {
|
||||
let min = lower
|
||||
.map(|(bound, _)| int_lower_bound(bound))
|
||||
.unwrap_or(i128::from(i64::MIN));
|
||||
let max = upper
|
||||
.map(|(bound, _)| int_upper_bound(bound))
|
||||
.unwrap_or(i128::from(i64::MAX));
|
||||
if min > max {
|
||||
return Err(empty_numeric_bounds(span));
|
||||
return Err(empty_numeric_bounds(span, lower, upper));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let (Some(lower), Some(upper)) = (lower, upper) {
|
||||
let lower_value = lower.number.as_f64();
|
||||
let upper_value = upper.number.as_f64();
|
||||
if let (Some((lower_bound, _)), Some((upper_bound, _))) = (lower, upper) {
|
||||
let lower_value = lower_bound.number.as_f64();
|
||||
let upper_value = upper_bound.number.as_f64();
|
||||
if lower_value > upper_value {
|
||||
return Err(empty_numeric_bounds(span));
|
||||
return Err(empty_numeric_bounds(span, lower, upper));
|
||||
}
|
||||
if lower_value == upper_value && !(lower.inclusive && upper.inclusive) {
|
||||
return Err(empty_numeric_bounds(span));
|
||||
if lower_value == upper_value && !(lower_bound.inclusive && upper_bound.inclusive) {
|
||||
return Err(empty_numeric_bounds(span, lower, upper));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -227,12 +322,23 @@ fn int_upper_bound(bound: Bound) -> i128 {
|
||||
}
|
||||
}
|
||||
|
||||
fn empty_numeric_bounds(span: Span) -> Diagnostic {
|
||||
Diagnostic::new(
|
||||
fn empty_numeric_bounds(
|
||||
span: Span,
|
||||
lower: Option<(Bound, Span)>,
|
||||
upper: Option<(Bound, Span)>,
|
||||
) -> Diagnostic {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
DiagnosticKind::Conflict,
|
||||
span,
|
||||
String::from("numeric comparison constraints have an empty intersection"),
|
||||
)
|
||||
);
|
||||
if let Some((_, lower_span)) = lower {
|
||||
diagnostic = diagnostic.with_label(lower_span, "lower bound constraint");
|
||||
}
|
||||
if let Some((_, upper_span)) = upper {
|
||||
diagnostic = diagnostic.with_label(upper_span, "upper bound constraint");
|
||||
}
|
||||
diagnostic
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -240,13 +346,20 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::runtime::LiteralValue;
|
||||
|
||||
fn entry(constraint: Constraint) -> ConstraintEntry {
|
||||
ConstraintEntry {
|
||||
constraint,
|
||||
span: Span::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detects_primitive_conflict() {
|
||||
assert!(
|
||||
normalize_constraints(
|
||||
alloc::vec![
|
||||
Constraint::Type(PrimitiveType::Int),
|
||||
Constraint::Type(PrimitiveType::String),
|
||||
entry(Constraint::Type(PrimitiveType::Int)),
|
||||
entry(Constraint::Type(PrimitiveType::String)),
|
||||
],
|
||||
Span::default(),
|
||||
)
|
||||
@@ -259,9 +372,9 @@ mod tests {
|
||||
assert!(
|
||||
normalize_constraints(
|
||||
alloc::vec![
|
||||
Constraint::Type(PrimitiveType::Int),
|
||||
Constraint::Compare(CompareOp::Gt, LiteralValue::Int(10)),
|
||||
Constraint::Compare(CompareOp::Lt, LiteralValue::Int(11)),
|
||||
entry(Constraint::Type(PrimitiveType::Int)),
|
||||
entry(Constraint::Compare(CompareOp::Gt, LiteralValue::Int(10))),
|
||||
entry(Constraint::Compare(CompareOp::Lt, LiteralValue::Int(5))),
|
||||
],
|
||||
Span::default(),
|
||||
)
|
||||
@@ -270,15 +383,16 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_regex_constraints_without_intersection_check() {
|
||||
let constraints = normalize_constraints(
|
||||
alloc::vec![
|
||||
Constraint::Regex(String::from("^a$")),
|
||||
Constraint::Regex(String::from("^b$")),
|
||||
],
|
||||
Span::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(constraints.len(), 2);
|
||||
fn detects_non_integer_int_bound() {
|
||||
assert!(
|
||||
normalize_constraints(
|
||||
alloc::vec![
|
||||
entry(Constraint::Type(PrimitiveType::Int)),
|
||||
entry(Constraint::Compare(CompareOp::Gt, LiteralValue::Float(1.5))),
|
||||
],
|
||||
Span::default(),
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use alloc::string::String;
|
||||
use alloc::{string::String, vec::Vec};
|
||||
|
||||
use crate::span::Span;
|
||||
|
||||
@@ -9,6 +9,13 @@ pub struct Diagnostic {
|
||||
pub kind: DiagnosticKind,
|
||||
pub span: Span,
|
||||
pub message: String,
|
||||
pub labels: Vec<DiagnosticLabel>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct DiagnosticLabel {
|
||||
pub span: Span,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl Diagnostic {
|
||||
@@ -17,12 +24,21 @@ impl Diagnostic {
|
||||
kind,
|
||||
span,
|
||||
message: message.into(),
|
||||
labels: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn syntax(span: Span, message: impl Into<String>) -> Self {
|
||||
Self::new(DiagnosticKind::Syntax, span, message)
|
||||
}
|
||||
|
||||
pub fn with_label(mut self, span: Span, message: impl Into<String>) -> Self {
|
||||
self.labels.push(DiagnosticLabel {
|
||||
span,
|
||||
message: message.into(),
|
||||
});
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
||||
@@ -10,6 +10,11 @@ pub enum HostValue {
|
||||
Float(f64),
|
||||
Bool(bool),
|
||||
Array(Vec<HostValue>),
|
||||
ArrayConstraint {
|
||||
item: Box<HostValue>,
|
||||
constraints: Vec<Constraint>,
|
||||
default: Option<Box<HostValue>>,
|
||||
},
|
||||
Object(Vec<HostField>),
|
||||
Abstract {
|
||||
constraints: Vec<Constraint>,
|
||||
@@ -63,6 +68,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 +96,14 @@ impl HostValue {
|
||||
Self::abstract_with_constraint(Constraint::Type(PrimitiveType::Bool))
|
||||
}
|
||||
|
||||
pub fn array_of(item: HostValue) -> Self {
|
||||
Self::ArrayConstraint {
|
||||
item: Box::new(item),
|
||||
constraints: Vec::new(),
|
||||
default: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn builtin_predicate(name: impl Into<String>) -> Self {
|
||||
Self::abstract_with_constraint(Constraint::BuiltinPredicate(name.into()))
|
||||
}
|
||||
@@ -93,6 +118,7 @@ impl HostValue {
|
||||
pub fn with_constraint(mut self, constraint: Constraint) -> Self {
|
||||
match &mut self {
|
||||
Self::Abstract { constraints, .. } => constraints.push(constraint),
|
||||
Self::ArrayConstraint { constraints, .. } => constraints.push(constraint),
|
||||
_ => {
|
||||
self = Self::Abstract {
|
||||
constraints: alloc::vec![constraint],
|
||||
@@ -127,6 +153,22 @@ impl HostValue {
|
||||
|
||||
pub fn default(self, value: HostValue) -> Result<Self> {
|
||||
match self {
|
||||
Self::ArrayConstraint {
|
||||
item,
|
||||
constraints,
|
||||
default: None,
|
||||
} => Ok(Self::ArrayConstraint {
|
||||
item,
|
||||
constraints,
|
||||
default: Some(Box::new(value)),
|
||||
}),
|
||||
Self::ArrayConstraint {
|
||||
default: Some(_), ..
|
||||
} => Err(Diagnostic::new(
|
||||
DiagnosticKind::DefaultConflict,
|
||||
Span::default(),
|
||||
"host value already has a default",
|
||||
)),
|
||||
Self::Abstract {
|
||||
constraints,
|
||||
default: None,
|
||||
@@ -162,3 +204,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));
|
||||
}
|
||||
}
|
||||
|
||||
+957
-92
File diff suppressed because it is too large
Load Diff
@@ -32,10 +32,21 @@ pub enum TokenKind {
|
||||
Semicolon,
|
||||
Comma,
|
||||
Dot,
|
||||
Ellipsis,
|
||||
Colon,
|
||||
Equal,
|
||||
EqualEqual,
|
||||
Bang,
|
||||
BangEqual,
|
||||
Arrow,
|
||||
Amp,
|
||||
AmpAmp,
|
||||
PipePipe,
|
||||
Plus,
|
||||
PlusPlus,
|
||||
Minus,
|
||||
Star,
|
||||
Slash,
|
||||
SlashSlash,
|
||||
Gt,
|
||||
Gte,
|
||||
@@ -52,6 +63,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)
|
||||
}
|
||||
@@ -67,9 +79,13 @@ impl<'a> Lexer<'a> {
|
||||
|
||||
pub fn tokenize(mut self) -> Result<Vec<Token>> {
|
||||
let mut tokens = Vec::new();
|
||||
let mut previous = None;
|
||||
loop {
|
||||
let token = self.next_token()?;
|
||||
let token = self.next_token(previous.as_ref())?;
|
||||
let is_eof = token.kind == TokenKind::Eof;
|
||||
if !is_eof {
|
||||
previous = Some(token.kind.clone());
|
||||
}
|
||||
tokens.push(token);
|
||||
if is_eof {
|
||||
return Ok(tokens);
|
||||
@@ -77,8 +93,12 @@ impl<'a> Lexer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn next_token(&mut self) -> Result<Token> {
|
||||
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 {
|
||||
@@ -122,7 +142,18 @@ impl<'a> Lexer<'a> {
|
||||
}
|
||||
b'.' => {
|
||||
self.pos += 1;
|
||||
TokenKind::Dot
|
||||
if self.consume(b'.') {
|
||||
if self.consume(b'.') {
|
||||
TokenKind::Ellipsis
|
||||
} else {
|
||||
return Err(Diagnostic::syntax(
|
||||
self.span(start, self.pos),
|
||||
"expected third '.' in ellipsis",
|
||||
));
|
||||
}
|
||||
} else {
|
||||
TokenKind::Dot
|
||||
}
|
||||
}
|
||||
b':' => {
|
||||
self.pos += 1;
|
||||
@@ -134,16 +165,57 @@ impl<'a> Lexer<'a> {
|
||||
}
|
||||
b'&' => {
|
||||
self.pos += 1;
|
||||
TokenKind::Amp
|
||||
if self.consume(b'&') {
|
||||
TokenKind::AmpAmp
|
||||
} else {
|
||||
TokenKind::Amp
|
||||
}
|
||||
}
|
||||
b'|' => {
|
||||
self.pos += 1;
|
||||
if self.consume(b'|') {
|
||||
TokenKind::PipePipe
|
||||
} else {
|
||||
return Err(Diagnostic::syntax(
|
||||
self.span(start, self.pos),
|
||||
"expected '|' after '|'",
|
||||
));
|
||||
}
|
||||
}
|
||||
b'+' => {
|
||||
self.pos += 1;
|
||||
if self.consume(b'+') {
|
||||
TokenKind::PlusPlus
|
||||
} else {
|
||||
TokenKind::Plus
|
||||
}
|
||||
}
|
||||
b'-' => {
|
||||
self.pos += 1;
|
||||
TokenKind::Minus
|
||||
}
|
||||
b'*' => {
|
||||
self.pos += 1;
|
||||
TokenKind::Star
|
||||
}
|
||||
b'=' => {
|
||||
self.pos += 1;
|
||||
if self.consume(b'>') {
|
||||
TokenKind::Arrow
|
||||
} else if self.consume(b'=') {
|
||||
TokenKind::EqualEqual
|
||||
} else {
|
||||
TokenKind::Equal
|
||||
}
|
||||
}
|
||||
b'!' => {
|
||||
self.pos += 1;
|
||||
if self.consume(b'=') {
|
||||
TokenKind::BangEqual
|
||||
} else {
|
||||
TokenKind::Bang
|
||||
}
|
||||
}
|
||||
b'>' => {
|
||||
self.pos += 1;
|
||||
if self.consume(b'=') {
|
||||
@@ -164,6 +236,8 @@ impl<'a> Lexer<'a> {
|
||||
self.pos += 1;
|
||||
if self.consume(b'/') {
|
||||
TokenKind::SlashSlash
|
||||
} else if previous.is_some_and(token_can_end_expr) {
|
||||
TokenKind::Slash
|
||||
} else {
|
||||
self.lex_regex(start)?
|
||||
}
|
||||
@@ -341,6 +415,23 @@ fn is_ident_continue(c: u8) -> bool {
|
||||
c.is_ascii_alphanumeric() || c == b'_'
|
||||
}
|
||||
|
||||
fn token_can_end_expr(kind: &TokenKind) -> bool {
|
||||
matches!(
|
||||
kind,
|
||||
TokenKind::Ident(_)
|
||||
| TokenKind::Int(_)
|
||||
| TokenKind::Float(_)
|
||||
| TokenKind::String(_)
|
||||
| TokenKind::Regex(_)
|
||||
| TokenKind::True
|
||||
| TokenKind::False
|
||||
| TokenKind::Underscore
|
||||
| TokenKind::RBrace
|
||||
| TokenKind::RBracket
|
||||
| TokenKind::RParen
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -353,4 +444,13 @@ mod tests {
|
||||
assert_eq!(tokens[3].kind, TokenKind::Amp);
|
||||
assert_eq!(tokens[4].kind, TokenKind::Gte);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tokenizes_array_constraint_ellipsis() {
|
||||
let tokens = Lexer::new("[...String]").tokenize().unwrap();
|
||||
assert_eq!(tokens[0].kind, TokenKind::LBracket);
|
||||
assert_eq!(tokens[1].kind, TokenKind::Ellipsis);
|
||||
assert!(matches!(tokens[2].kind, TokenKind::Ident(_)));
|
||||
assert_eq!(tokens[3].kind, TokenKind::RBracket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
pub use lexer::{Lexer, Token, TokenKind};
|
||||
pub use eval::{Engine, format_diagnostic_with};
|
||||
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")
|
||||
|
||||
@@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec};
|
||||
|
||||
use crate::{
|
||||
SourceId, Span,
|
||||
ast::{Ast, BinaryOp, CompareOp, Expr, ExprId, Field, Literal, MatchArm, Param},
|
||||
ast::{Ast, BinaryOp, CompareOp, Expr, ExprId, Field, Literal, MatchArm, Param, UnaryOp},
|
||||
diagnostic::{Diagnostic, Result},
|
||||
lexer::{Lexer, Token, TokenKind},
|
||||
};
|
||||
@@ -115,6 +115,110 @@ impl Parser {
|
||||
let rhs = self.parse_expr(r_bp)?;
|
||||
let span = self.ast.span(lhs).join(self.ast.span(rhs)).join(op_span);
|
||||
lhs = match kind {
|
||||
InfixKind::Add => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Add,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::Sub => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Sub,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::Mul => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Mul,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::Div => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Div,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::Concat => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Concat,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::Equal => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Equal,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::NotEqual => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::NotEqual,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::Greater => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Greater,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::GreaterEqual => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::GreaterEqual,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::Less => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Less,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::LessEqual => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::LessEqual,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::LogicalAnd => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::LogicalAnd,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::LogicalOr => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::LogicalOr,
|
||||
lhs,
|
||||
rhs,
|
||||
},
|
||||
span,
|
||||
),
|
||||
InfixKind::And => self.ast.push(
|
||||
Expr::Binary {
|
||||
op: BinaryOp::And,
|
||||
@@ -173,6 +277,28 @@ impl Parser {
|
||||
TokenKind::Let => self.parse_let(token.span),
|
||||
TokenKind::Match => self.parse_match(token.span),
|
||||
TokenKind::Import => self.parse_import(token.span),
|
||||
TokenKind::Minus => {
|
||||
let expr = self.parse_expr(17)?;
|
||||
let span = token.span.join(self.ast.span(expr));
|
||||
Ok(self.ast.push(
|
||||
Expr::Unary {
|
||||
op: UnaryOp::Neg,
|
||||
expr,
|
||||
},
|
||||
span,
|
||||
))
|
||||
}
|
||||
TokenKind::Bang => {
|
||||
let expr = self.parse_expr(17)?;
|
||||
let span = token.span.join(self.ast.span(expr));
|
||||
Ok(self.ast.push(
|
||||
Expr::Unary {
|
||||
op: UnaryOp::Not,
|
||||
expr,
|
||||
},
|
||||
span,
|
||||
))
|
||||
}
|
||||
TokenKind::Gt | TokenKind::Gte | TokenKind::Lt | TokenKind::Lte => {
|
||||
let op = match token.kind {
|
||||
TokenKind::Gt => CompareOp::Gt,
|
||||
@@ -181,7 +307,7 @@ impl Parser {
|
||||
TokenKind::Lte => CompareOp::Lte,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let value = self.parse_expr(8)?;
|
||||
let value = self.parse_expr(12)?;
|
||||
let span = token.span.join(self.ast.span(value));
|
||||
Ok(self.ast.push(Expr::CompareConstraint { op, value }, span))
|
||||
}
|
||||
@@ -212,6 +338,17 @@ impl Parser {
|
||||
}
|
||||
|
||||
fn parse_array_after_lbracket(&mut self, start_span: Span) -> Result<ExprId> {
|
||||
if self.consume_kind(&TokenKind::Ellipsis).is_some() {
|
||||
let item = self.parse_expr(0)?;
|
||||
let _ = self.consume_kind(&TokenKind::Comma);
|
||||
self.expect_kind(
|
||||
&TokenKind::RBracket,
|
||||
"expected ']' after array element constraint",
|
||||
)?;
|
||||
let span = start_span.join(self.previous_span());
|
||||
return Ok(self.ast.push(Expr::ArrayConstraint { item }, span));
|
||||
}
|
||||
|
||||
let mut items = Vec::new();
|
||||
if self.consume_kind(&TokenKind::RBracket).is_some() {
|
||||
return Ok(self
|
||||
@@ -406,6 +543,19 @@ impl Parser {
|
||||
TokenKind::Default => Some((InfixKind::Default, 1, 2)),
|
||||
TokenKind::SlashSlash => Some((InfixKind::Patch, 3, 4)),
|
||||
TokenKind::Amp => Some((InfixKind::And, 5, 6)),
|
||||
TokenKind::PipePipe => Some((InfixKind::LogicalOr, 7, 8)),
|
||||
TokenKind::AmpAmp => Some((InfixKind::LogicalAnd, 9, 10)),
|
||||
TokenKind::EqualEqual => Some((InfixKind::Equal, 11, 12)),
|
||||
TokenKind::BangEqual => Some((InfixKind::NotEqual, 11, 12)),
|
||||
TokenKind::Gt => Some((InfixKind::Greater, 11, 12)),
|
||||
TokenKind::Gte => Some((InfixKind::GreaterEqual, 11, 12)),
|
||||
TokenKind::Lt => Some((InfixKind::Less, 11, 12)),
|
||||
TokenKind::Lte => Some((InfixKind::LessEqual, 11, 12)),
|
||||
TokenKind::PlusPlus => Some((InfixKind::Concat, 12, 13)),
|
||||
TokenKind::Plus => Some((InfixKind::Add, 13, 14)),
|
||||
TokenKind::Minus => Some((InfixKind::Sub, 13, 14)),
|
||||
TokenKind::Star => Some((InfixKind::Mul, 15, 16)),
|
||||
TokenKind::Slash => Some((InfixKind::Div, 15, 16)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -498,6 +648,19 @@ impl Parser {
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum InfixKind {
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
Div,
|
||||
Concat,
|
||||
Equal,
|
||||
NotEqual,
|
||||
Greater,
|
||||
GreaterEqual,
|
||||
Less,
|
||||
LessEqual,
|
||||
LogicalAnd,
|
||||
LogicalOr,
|
||||
And,
|
||||
Patch,
|
||||
Default,
|
||||
@@ -522,4 +685,18 @@ mod tests {
|
||||
};
|
||||
assert_eq!(fields[0].path, ["feature", "enable"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_array_constraint() {
|
||||
let parsed = parse_source("[...(String & /^api-/)]").unwrap();
|
||||
let Expr::ArrayConstraint { item } = parsed.ast.get(parsed.root).expr else {
|
||||
panic!()
|
||||
};
|
||||
assert!(matches!(parsed.ast.get(item).expr, Expr::Binary { .. }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_array_constraint_without_element_constraint() {
|
||||
assert!(parse_source("[...]").is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use alloc::{string::String, vec::Vec};
|
||||
|
||||
use crate::{ExprId, ast::CompareOp};
|
||||
use crate::{ExprId, Span, ast::CompareOp};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct ModuleId(pub u32);
|
||||
@@ -37,6 +37,7 @@ pub struct ObjectValue {
|
||||
pub struct ObjectField {
|
||||
pub name: String,
|
||||
pub value: ThunkId,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -54,13 +55,20 @@ pub struct FunctionParam {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AbstractValue {
|
||||
pub constraints: Vec<Constraint>,
|
||||
pub constraints: Vec<ConstraintEntry>,
|
||||
pub default: Option<ThunkId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ConstraintEntry {
|
||||
pub constraint: Constraint,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Constraint {
|
||||
Type(PrimitiveType),
|
||||
ArrayItems(ThunkId),
|
||||
Compare(CompareOp, LiteralValue),
|
||||
Regex(String),
|
||||
BuiltinPredicate(String),
|
||||
@@ -108,6 +116,7 @@ pub struct EnvId(pub u32);
|
||||
pub struct Thunk {
|
||||
pub kind: ThunkKind,
|
||||
pub state: ThunkState,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -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> DecodalSchema for Vec<T> {
|
||||
fn decodal_schema() -> HostValue {
|
||||
HostValue::array_of(T::decodal_schema())
|
||||
}
|
||||
}
|
||||
|
||||
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,150 @@
|
||||
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>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Decodal)]
|
||||
struct Worker {
|
||||
name: String,
|
||||
#[decodal(default = true)]
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Decodal)]
|
||||
struct Fleet {
|
||||
workers: Vec<Worker>,
|
||||
}
|
||||
|
||||
#[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");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec_schema_rejects_invalid_element_before_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;
|
||||
tags = ["web", 1];
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let error = engine.eval_module(module).unwrap_err();
|
||||
assert!(
|
||||
error
|
||||
.labels
|
||||
.iter()
|
||||
.any(|label| label.message.contains("array element [1]"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec_schema_applies_nested_struct_defaults() {
|
||||
let mut engine = Engine::new(EmptyLoader);
|
||||
engine
|
||||
.bind_global("Fleet", Fleet::decodal_schema())
|
||||
.unwrap();
|
||||
let module = engine
|
||||
.add_root_source(
|
||||
"test",
|
||||
"test",
|
||||
r#"
|
||||
Fleet & {
|
||||
workers = [{ name = "api"; }];
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let value = engine.eval_module(module).unwrap();
|
||||
let data = engine.materialize(&value).unwrap();
|
||||
let fleet = Fleet::decodal_decode(&data).unwrap();
|
||||
assert_eq!(
|
||||
fleet,
|
||||
Fleet {
|
||||
workers: vec![Worker {
|
||||
name: "api".into(),
|
||||
enabled: true,
|
||||
}],
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
[package]
|
||||
name = "decodal-language-tools"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "Source-level language tooling for Decodal."
|
||||
keywords = ["decodal", "formatter", "lsp", "tree-sitter"]
|
||||
categories = ["development-tools", "text-processing"]
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
decodal = { version = "0.1.2", path = "../decodal-core" }
|
||||
serde_json.workspace = true
|
||||
tree-sitter = "0.22.6"
|
||||
tree-sitter-decodal = { path = "../../editors/tree-sitter-decodal" }
|
||||
wasm-bindgen.workspace = true
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = false
|
||||
@@ -0,0 +1,870 @@
|
||||
use std::{error::Error, fmt};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use tree_sitter::{Node, Parser, TreeCursor};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
const INDENT: usize = 4;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FormatError {
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl FormatError {
|
||||
fn new(message: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn message(&self) -> &str {
|
||||
&self.message
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FormatError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(&self.message)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for FormatError {}
|
||||
|
||||
pub fn format_source(source: &str) -> Result<String, FormatError> {
|
||||
decodal::parse_source(source)
|
||||
.map_err(|diagnostic| FormatError::new(format!("parse error: {}", diagnostic.message)))?;
|
||||
format_source_impl(source)
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn format_source_impl(source: &str) -> Result<String, FormatError> {
|
||||
let mut parser = Parser::new();
|
||||
parser
|
||||
.set_language(&tree_sitter_decodal::language())
|
||||
.map_err(|error| {
|
||||
FormatError::new(format!("failed to load tree-sitter grammar: {error}"))
|
||||
})?;
|
||||
let tree = parser
|
||||
.parse(source, None)
|
||||
.ok_or_else(|| FormatError::new("tree-sitter failed to parse source"))?;
|
||||
let root = tree.root_node();
|
||||
if root.has_error() {
|
||||
return Err(FormatError::new(
|
||||
"parse error: source contains tree-sitter errors",
|
||||
));
|
||||
}
|
||||
|
||||
let mut formatter = Formatter::new(source);
|
||||
let mut out = formatter.format_source_file(root);
|
||||
if !out.ends_with('\n') {
|
||||
out.push('\n');
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = formatSource)]
|
||||
pub fn format_source_json(source: &str) -> String {
|
||||
match format_source(source) {
|
||||
Ok(formatted) => serde_json::json!({ "ok": true, "source": formatted }).to_string(),
|
||||
Err(error) => serde_json::json!({ "ok": false, "error": error.message() }).to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn format_source_impl(source: &str) -> Result<String, FormatError> {
|
||||
Ok(LexicalFormatter::new(source).format())
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
struct LexicalFormatter<'a> {
|
||||
chars: core::iter::Peekable<core::str::Chars<'a>>,
|
||||
out: String,
|
||||
indent: usize,
|
||||
line_start: bool,
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
impl<'a> LexicalFormatter<'a> {
|
||||
fn new(source: &'a str) -> Self {
|
||||
Self {
|
||||
chars: source.chars().peekable(),
|
||||
out: String::new(),
|
||||
indent: 0,
|
||||
line_start: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn format(mut self) -> String {
|
||||
while let Some(ch) = self.chars.next() {
|
||||
match ch {
|
||||
' ' | '\t' | '\r' | '\n' => self.consume_whitespace(ch),
|
||||
'#' => self.write_comment(),
|
||||
'"' => self.write_string(),
|
||||
'{' => self.open_block('{'),
|
||||
'[' => self.open_block('['),
|
||||
'}' => self.close_block('}'),
|
||||
']' => self.close_block(']'),
|
||||
';' => self.end_statement(),
|
||||
',' => self.write_comma(),
|
||||
'.' => self.write_compact('.'),
|
||||
':' => self.write_spaced_operator(":"),
|
||||
'(' => self.write_compact('('),
|
||||
')' => self.write_compact(')'),
|
||||
'+' | '-' | '*' | '/' | '=' | '!' | '&' | '|' | '>' | '<' => {
|
||||
self.write_operator(ch)
|
||||
}
|
||||
_ => self.write_word(ch),
|
||||
}
|
||||
}
|
||||
self.trim_trailing_spaces();
|
||||
if !self.out.ends_with('\n') {
|
||||
self.out.push('\n');
|
||||
}
|
||||
self.out
|
||||
}
|
||||
|
||||
fn consume_whitespace(&mut self, ch: char) {
|
||||
if ch == '\n' && self.out.ends_with('\n') && !self.out.ends_with("\n\n") {
|
||||
self.out.push('\n');
|
||||
self.line_start = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn write_comment(&mut self) {
|
||||
if self.line_start {
|
||||
self.write_indent();
|
||||
} else {
|
||||
self.ensure_space();
|
||||
}
|
||||
self.out.push('#');
|
||||
for ch in self.chars.by_ref() {
|
||||
if ch == '\n' {
|
||||
break;
|
||||
}
|
||||
self.out.push(ch);
|
||||
}
|
||||
self.trim_trailing_spaces();
|
||||
self.out.push('\n');
|
||||
self.line_start = true;
|
||||
}
|
||||
|
||||
fn write_string(&mut self) {
|
||||
self.write_indent_if_needed();
|
||||
self.ensure_word_boundary();
|
||||
self.out.push('"');
|
||||
let mut escaped = false;
|
||||
for ch in self.chars.by_ref() {
|
||||
self.out.push(ch);
|
||||
if escaped {
|
||||
escaped = false;
|
||||
} else if ch == '\\' {
|
||||
escaped = true;
|
||||
} else if ch == '"' {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn open_block(&mut self, ch: char) {
|
||||
self.trim_trailing_spaces();
|
||||
self.out.push(' ');
|
||||
self.out.push(ch);
|
||||
self.out.push('\n');
|
||||
self.indent += INDENT;
|
||||
self.line_start = true;
|
||||
}
|
||||
|
||||
fn close_block(&mut self, ch: char) {
|
||||
self.trim_trailing_spaces();
|
||||
if !self.out.ends_with('\n') {
|
||||
self.out.push('\n');
|
||||
}
|
||||
self.indent = self.indent.saturating_sub(INDENT);
|
||||
self.write_indent();
|
||||
self.out.push(ch);
|
||||
self.line_start = false;
|
||||
}
|
||||
|
||||
fn end_statement(&mut self) {
|
||||
self.trim_trailing_spaces();
|
||||
self.out.push(';');
|
||||
self.out.push('\n');
|
||||
self.line_start = true;
|
||||
}
|
||||
|
||||
fn write_comma(&mut self) {
|
||||
self.trim_trailing_spaces();
|
||||
self.out.push(',');
|
||||
self.out.push(' ');
|
||||
self.line_start = false;
|
||||
}
|
||||
|
||||
fn write_operator(&mut self, ch: char) {
|
||||
let mut op = String::new();
|
||||
op.push(ch);
|
||||
if let Some(next) = self.chars.peek().copied() {
|
||||
let two_char = matches!(
|
||||
(ch, next),
|
||||
('=', '=')
|
||||
| ('!', '=')
|
||||
| ('>', '=')
|
||||
| ('<', '=')
|
||||
| ('+', '+')
|
||||
| ('/', '/')
|
||||
| ('&', '&')
|
||||
| ('|', '|')
|
||||
| ('=', '>')
|
||||
);
|
||||
if two_char {
|
||||
op.push(next);
|
||||
self.chars.next();
|
||||
}
|
||||
}
|
||||
self.write_spaced_operator(&op);
|
||||
}
|
||||
|
||||
fn write_spaced_operator(&mut self, op: &str) {
|
||||
self.trim_trailing_spaces();
|
||||
self.ensure_space();
|
||||
self.out.push_str(op);
|
||||
self.out.push(' ');
|
||||
self.line_start = false;
|
||||
}
|
||||
|
||||
fn write_compact(&mut self, ch: char) {
|
||||
self.trim_trailing_spaces();
|
||||
self.write_indent_if_needed();
|
||||
self.out.push(ch);
|
||||
self.line_start = false;
|
||||
}
|
||||
|
||||
fn write_word(&mut self, first: char) {
|
||||
self.write_indent_if_needed();
|
||||
self.ensure_word_boundary();
|
||||
self.out.push(first);
|
||||
while let Some(next) = self.chars.peek().copied() {
|
||||
if next.is_alphanumeric() || next == '_' {
|
||||
self.out.push(next);
|
||||
self.chars.next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.line_start = false;
|
||||
}
|
||||
|
||||
fn write_indent_if_needed(&mut self) {
|
||||
if self.line_start {
|
||||
self.write_indent();
|
||||
self.line_start = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn write_indent(&mut self) {
|
||||
for _ in 0..self.indent {
|
||||
self.out.push(' ');
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_word_boundary(&mut self) {
|
||||
let needs_space = self
|
||||
.out
|
||||
.chars()
|
||||
.last()
|
||||
.is_some_and(|ch| ch.is_alphanumeric() || matches!(ch, '_' | '"'));
|
||||
if needs_space {
|
||||
self.out.push(' ');
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_space(&mut self) {
|
||||
let needs_space = self
|
||||
.out
|
||||
.chars()
|
||||
.last()
|
||||
.is_some_and(|ch| !matches!(ch, ' ' | '\n' | '.' | '(' | '['));
|
||||
if needs_space {
|
||||
self.out.push(' ');
|
||||
}
|
||||
}
|
||||
|
||||
fn trim_trailing_spaces(&mut self) {
|
||||
while self.out.ends_with(' ') || self.out.ends_with('\t') {
|
||||
self.out.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
struct Formatter<'a> {
|
||||
source: &'a str,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl<'a> Formatter<'a> {
|
||||
fn new(source: &'a str) -> Self {
|
||||
Self { source }
|
||||
}
|
||||
|
||||
fn format_source_file(&mut self, node: Node<'a>) -> String {
|
||||
let mut out = String::new();
|
||||
let children = named_children(node);
|
||||
self.write_statement_list(&mut out, &children, 0);
|
||||
out
|
||||
}
|
||||
|
||||
fn write_statement_list(&mut self, out: &mut String, children: &[Node<'a>], indent: usize) {
|
||||
let mut pending_comments = Vec::new();
|
||||
let mut pending_blank = false;
|
||||
let mut previous_end = 0;
|
||||
let mut previous_statement_end_row = None;
|
||||
|
||||
for &child in children {
|
||||
let is_trailing_comment = child.kind() == "comment"
|
||||
&& previous_statement_end_row == Some(child.start_position().row);
|
||||
if previous_statement_end_row.is_some() && !is_trailing_comment {
|
||||
if !out.ends_with('\n') {
|
||||
out.push('\n');
|
||||
}
|
||||
previous_statement_end_row = None;
|
||||
}
|
||||
|
||||
if previous_end > 0 && has_blank_line(self.slice(previous_end, child.start_byte())) {
|
||||
pending_blank = true;
|
||||
}
|
||||
|
||||
if child.kind() == "comment" {
|
||||
if is_trailing_comment {
|
||||
if !out.ends_with(' ') {
|
||||
out.push(' ');
|
||||
}
|
||||
out.push_str(self.raw_trimmed(child));
|
||||
out.push('\n');
|
||||
previous_statement_end_row = None;
|
||||
} else {
|
||||
pending_comments.push(child);
|
||||
}
|
||||
previous_end = child.end_byte();
|
||||
continue;
|
||||
}
|
||||
|
||||
if pending_blank && !out.is_empty() && !out.ends_with("\n\n") {
|
||||
out.push('\n');
|
||||
}
|
||||
pending_blank = false;
|
||||
|
||||
for comment in pending_comments.drain(..) {
|
||||
write_indent(out, indent);
|
||||
out.push_str(self.raw_trimmed(comment));
|
||||
out.push('\n');
|
||||
}
|
||||
|
||||
write_indent(out, indent);
|
||||
self.write_statement(out, child, indent);
|
||||
previous_statement_end_row = Some(child.end_position().row);
|
||||
previous_end = child.end_byte();
|
||||
}
|
||||
|
||||
if previous_statement_end_row.is_some() && !out.ends_with('\n') {
|
||||
out.push('\n');
|
||||
}
|
||||
|
||||
if pending_blank && !out.is_empty() && !out.ends_with("\n\n") {
|
||||
out.push('\n');
|
||||
}
|
||||
for comment in pending_comments {
|
||||
write_indent(out, indent);
|
||||
out.push_str(self.raw_trimmed(comment));
|
||||
out.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
fn write_statement(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
match node.kind() {
|
||||
"field_definition" => {
|
||||
self.write_field_definition(out, node, indent);
|
||||
out.push(';');
|
||||
}
|
||||
_ => {
|
||||
self.write_expr(out, node, indent, 0);
|
||||
out.push(';');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn write_field_definition(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
if let Some(path) = node.child_by_field_name("path") {
|
||||
self.write_field_path(out, path);
|
||||
} else {
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
return;
|
||||
}
|
||||
out.push_str(" = ");
|
||||
if let Some(value) = node.child_by_field_name("value") {
|
||||
self.write_expr(out, value, indent, 0);
|
||||
}
|
||||
}
|
||||
|
||||
fn write_field_path(&mut self, out: &mut String, node: Node<'a>) {
|
||||
let identifiers: Vec<_> = named_children(node)
|
||||
.into_iter()
|
||||
.filter(|child| child.kind() == "identifier")
|
||||
.collect();
|
||||
if identifiers.is_empty() {
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
return;
|
||||
}
|
||||
for (index, identifier) in identifiers.into_iter().enumerate() {
|
||||
if index > 0 {
|
||||
out.push('.');
|
||||
}
|
||||
out.push_str(self.raw_trimmed(identifier));
|
||||
}
|
||||
}
|
||||
|
||||
fn write_expr(&mut self, out: &mut String, node: Node<'a>, indent: usize, parent_prec: u8) {
|
||||
if expression_contains_comment(node)
|
||||
&& !matches!(
|
||||
node.kind(),
|
||||
"object" | "array" | "array_constraint" | "let_expression" | "match_expression"
|
||||
)
|
||||
{
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
return;
|
||||
}
|
||||
|
||||
let prec = self.precedence(node);
|
||||
let parenthesize = prec < parent_prec;
|
||||
if parenthesize {
|
||||
out.push('(');
|
||||
}
|
||||
|
||||
match node.kind() {
|
||||
"literal" => {
|
||||
if let Some(child) = named_children(node).first().copied() {
|
||||
out.push_str(self.raw_trimmed(child));
|
||||
} else {
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
}
|
||||
}
|
||||
"identifier" | "string" | "integer" | "float" | "boolean" | "regex_literal" => {
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
}
|
||||
"comparison_constraint" => self.write_comparison_constraint(out, node, indent),
|
||||
"object" => self.write_object(out, node, indent),
|
||||
"array" => self.write_array(out, node, indent),
|
||||
"array_constraint" => self.write_array_constraint(out, node, indent),
|
||||
"let_expression" => self.write_let(out, node, indent),
|
||||
"function_expression" => self.write_function(out, node, indent),
|
||||
"match_expression" => self.write_match(out, node, indent),
|
||||
"import_expression" => self.write_import(out, node),
|
||||
"parenthesized_expression" => {
|
||||
out.push('(');
|
||||
if let Some(expr) = named_children(node)
|
||||
.into_iter()
|
||||
.find(|child| child.kind() != "comment")
|
||||
{
|
||||
self.write_expr(out, expr, indent, 0);
|
||||
}
|
||||
out.push(')');
|
||||
}
|
||||
"call_expression" => self.write_call(out, node, indent),
|
||||
"path_expression" => self.write_path(out, node, indent),
|
||||
"unary_expression" => self.write_unary(out, node, indent),
|
||||
"binary_expression" | "default_expression" => {
|
||||
self.write_binary_like(out, node, indent, prec)
|
||||
}
|
||||
_ => out.push_str(self.raw_trimmed(node)),
|
||||
}
|
||||
|
||||
if parenthesize {
|
||||
out.push(')');
|
||||
}
|
||||
}
|
||||
|
||||
fn write_object(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
let children = named_children(node);
|
||||
if children.is_empty() {
|
||||
out.push_str("{}");
|
||||
return;
|
||||
}
|
||||
out.push('{');
|
||||
out.push('\n');
|
||||
self.write_statement_list(out, &children, indent + INDENT);
|
||||
write_indent(out, indent);
|
||||
out.push('}');
|
||||
}
|
||||
|
||||
fn write_array(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
let children = named_children(node);
|
||||
if children.is_empty() {
|
||||
out.push_str("[]");
|
||||
return;
|
||||
}
|
||||
let has_comment = children.iter().any(|child| child.kind() == "comment");
|
||||
let inline = !has_comment && children.iter().all(|child| is_inline_expr(*child));
|
||||
if inline {
|
||||
out.push('[');
|
||||
for (index, child) in children.into_iter().enumerate() {
|
||||
if index > 0 {
|
||||
out.push_str(", ");
|
||||
}
|
||||
self.write_expr(out, child, indent, 0);
|
||||
}
|
||||
out.push(']');
|
||||
return;
|
||||
}
|
||||
|
||||
out.push('[');
|
||||
out.push('\n');
|
||||
let mut pending_comments = Vec::new();
|
||||
for child in children {
|
||||
if child.kind() == "comment" {
|
||||
pending_comments.push(child);
|
||||
continue;
|
||||
}
|
||||
for comment in pending_comments.drain(..) {
|
||||
write_indent(out, indent + INDENT);
|
||||
out.push_str(self.raw_trimmed(comment));
|
||||
out.push('\n');
|
||||
}
|
||||
write_indent(out, indent + INDENT);
|
||||
self.write_expr(out, child, indent + INDENT, 0);
|
||||
out.push_str(",\n");
|
||||
}
|
||||
for comment in pending_comments {
|
||||
write_indent(out, indent + INDENT);
|
||||
out.push_str(self.raw_trimmed(comment));
|
||||
out.push('\n');
|
||||
}
|
||||
write_indent(out, indent);
|
||||
out.push(']');
|
||||
}
|
||||
|
||||
fn write_array_constraint(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
out.push_str("[...");
|
||||
if let Some(element) = node.child_by_field_name("element") {
|
||||
self.write_expr(out, element, indent, 0);
|
||||
}
|
||||
out.push(']');
|
||||
}
|
||||
|
||||
fn write_let(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
let body = node.child_by_field_name("body");
|
||||
out.push_str("let");
|
||||
out.push('\n');
|
||||
let children: Vec<_> = named_children(node)
|
||||
.into_iter()
|
||||
.filter(|child| Some(*child) != body)
|
||||
.collect();
|
||||
self.write_statement_list(out, &children, indent + INDENT);
|
||||
write_indent(out, indent);
|
||||
out.push_str("in");
|
||||
if let Some(body) = body {
|
||||
out.push('\n');
|
||||
write_indent(out, indent + INDENT);
|
||||
self.write_expr(out, body, indent + INDENT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
fn write_function(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
let body = node.child_by_field_name("body");
|
||||
let params: Vec<_> = named_children(node)
|
||||
.into_iter()
|
||||
.filter(|child| child.kind() == "parameter")
|
||||
.collect();
|
||||
out.push('(');
|
||||
for (index, param) in params.into_iter().enumerate() {
|
||||
if index > 0 {
|
||||
out.push_str(", ");
|
||||
}
|
||||
self.write_parameter(out, param, indent);
|
||||
}
|
||||
out.push_str(") =>");
|
||||
if let Some(body) = body {
|
||||
if is_inline_expr(body) {
|
||||
out.push(' ');
|
||||
self.write_expr(out, body, indent, 0);
|
||||
} else {
|
||||
out.push('\n');
|
||||
write_indent(out, indent + INDENT);
|
||||
self.write_expr(out, body, indent + INDENT, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn write_parameter(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
if let Some(name) = node.child_by_field_name("name") {
|
||||
out.push_str(self.raw_trimmed(name));
|
||||
}
|
||||
if let Some(constraint) = node.child_by_field_name("constraint") {
|
||||
out.push_str(": ");
|
||||
self.write_expr(out, constraint, indent, 0);
|
||||
}
|
||||
}
|
||||
|
||||
fn write_match(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
out.push_str("match ");
|
||||
if let Some(scrutinee) = node.child_by_field_name("scrutinee") {
|
||||
self.write_expr(out, scrutinee, indent, 0);
|
||||
}
|
||||
out.push_str(" {");
|
||||
let children: Vec<_> = named_children(node)
|
||||
.into_iter()
|
||||
.filter(|child| child.kind() == "match_arm" || child.kind() == "comment")
|
||||
.collect();
|
||||
if !children.is_empty() {
|
||||
out.push('\n');
|
||||
self.write_match_arms(out, &children, indent + INDENT);
|
||||
write_indent(out, indent);
|
||||
}
|
||||
out.push('}');
|
||||
}
|
||||
|
||||
fn write_match_arms(&mut self, out: &mut String, children: &[Node<'a>], indent: usize) {
|
||||
let mut pending_comments = Vec::new();
|
||||
for &child in children {
|
||||
if child.kind() == "comment" {
|
||||
pending_comments.push(child);
|
||||
continue;
|
||||
}
|
||||
for comment in pending_comments.drain(..) {
|
||||
write_indent(out, indent);
|
||||
out.push_str(self.raw_trimmed(comment));
|
||||
out.push('\n');
|
||||
}
|
||||
write_indent(out, indent);
|
||||
if let Some(pattern) = child.child_by_field_name("pattern") {
|
||||
self.write_expr(out, pattern, indent, 0);
|
||||
}
|
||||
out.push_str(": ");
|
||||
if let Some(body) = child.child_by_field_name("body") {
|
||||
self.write_expr(out, body, indent, 0);
|
||||
}
|
||||
out.push_str(";\n");
|
||||
}
|
||||
for comment in pending_comments {
|
||||
write_indent(out, indent);
|
||||
out.push_str(self.raw_trimmed(comment));
|
||||
out.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
fn write_import(&mut self, out: &mut String, node: Node<'a>) {
|
||||
out.push_str("import ");
|
||||
if let Some(specifier) = node.child_by_field_name("specifier") {
|
||||
out.push_str(self.raw_trimmed(specifier));
|
||||
}
|
||||
}
|
||||
|
||||
fn write_call(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
let callee = node.child_by_field_name("function");
|
||||
if let Some(callee) = callee {
|
||||
self.write_expr(out, callee, indent, self.precedence(node));
|
||||
}
|
||||
out.push('(');
|
||||
let args: Vec<_> = named_children(node)
|
||||
.into_iter()
|
||||
.filter(|child| Some(*child) != callee && child.kind() != "comment")
|
||||
.collect();
|
||||
for (index, arg) in args.into_iter().enumerate() {
|
||||
if index > 0 {
|
||||
out.push_str(", ");
|
||||
}
|
||||
self.write_expr(out, arg, indent, 0);
|
||||
}
|
||||
out.push(')');
|
||||
}
|
||||
|
||||
fn write_path(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
if let Some(object) = node.child_by_field_name("object") {
|
||||
self.write_expr(out, object, indent, self.precedence(node));
|
||||
}
|
||||
out.push('.');
|
||||
if let Some(field) = node.child_by_field_name("field") {
|
||||
out.push_str(self.raw_trimmed(field));
|
||||
}
|
||||
}
|
||||
|
||||
fn write_unary(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
if let Some(operand) = node.child_by_field_name("operand") {
|
||||
let operator = self.slice(node.start_byte(), operand.start_byte()).trim();
|
||||
out.push_str(operator);
|
||||
self.write_expr(out, operand, indent, self.precedence(node));
|
||||
} else {
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
}
|
||||
}
|
||||
|
||||
fn write_comparison_constraint(&mut self, out: &mut String, node: Node<'a>, indent: usize) {
|
||||
if let Some(value) = node.child_by_field_name("value") {
|
||||
let operator = self.slice(node.start_byte(), value.start_byte()).trim();
|
||||
out.push_str(operator);
|
||||
out.push(' ');
|
||||
self.write_expr(out, value, indent, self.precedence(node));
|
||||
} else {
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
}
|
||||
}
|
||||
|
||||
fn write_binary_like(&mut self, out: &mut String, node: Node<'a>, indent: usize, prec: u8) {
|
||||
let left = node
|
||||
.child_by_field_name("left")
|
||||
.or_else(|| node.child_by_field_name("base"));
|
||||
let right = node
|
||||
.child_by_field_name("right")
|
||||
.or_else(|| node.child_by_field_name("fallback"));
|
||||
let (Some(left), Some(right)) = (left, right) else {
|
||||
out.push_str(self.raw_trimmed(node));
|
||||
return;
|
||||
};
|
||||
self.write_expr(out, left, indent, prec);
|
||||
out.push(' ');
|
||||
if node.kind() == "default_expression" {
|
||||
out.push_str("default");
|
||||
} else {
|
||||
out.push_str(self.slice(left.end_byte(), right.start_byte()).trim());
|
||||
}
|
||||
out.push(' ');
|
||||
self.write_expr(out, right, indent, prec + 1);
|
||||
}
|
||||
|
||||
fn precedence(&self, node: Node<'a>) -> u8 {
|
||||
match node.kind() {
|
||||
"default_expression" => 1,
|
||||
"binary_expression" => self.binary_precedence(node),
|
||||
"unary_expression" | "comparison_constraint" => 17,
|
||||
"call_expression" | "path_expression" => 19,
|
||||
_ => 20,
|
||||
}
|
||||
}
|
||||
|
||||
fn binary_precedence(&self, node: Node<'a>) -> u8 {
|
||||
let Some(left) = node.child_by_field_name("left") else {
|
||||
return 10;
|
||||
};
|
||||
let Some(right) = node.child_by_field_name("right") else {
|
||||
return 10;
|
||||
};
|
||||
match self.slice(left.end_byte(), right.start_byte()).trim() {
|
||||
"//" => 3,
|
||||
"&" => 5,
|
||||
"||" => 7,
|
||||
"&&" => 9,
|
||||
"==" | "!=" | ">" | ">=" | "<" | "<=" => 11,
|
||||
"++" => 12,
|
||||
"+" | "-" => 13,
|
||||
"*" | "/" => 15,
|
||||
_ => 10,
|
||||
}
|
||||
}
|
||||
|
||||
fn raw_trimmed(&self, node: Node<'a>) -> &'a str {
|
||||
self.slice(node.start_byte(), node.end_byte()).trim()
|
||||
}
|
||||
|
||||
fn slice(&self, start: usize, end: usize) -> &'a str {
|
||||
&self.source[start..end]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn named_children<'a>(node: Node<'a>) -> Vec<Node<'a>> {
|
||||
let mut cursor: TreeCursor<'a> = node.walk();
|
||||
node.named_children(&mut cursor).collect()
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn expression_contains_comment(node: Node<'_>) -> bool {
|
||||
if node.kind() == "comment" {
|
||||
return true;
|
||||
}
|
||||
named_children(node)
|
||||
.into_iter()
|
||||
.any(expression_contains_comment)
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn is_inline_expr(node: Node<'_>) -> bool {
|
||||
match node.kind() {
|
||||
"literal"
|
||||
| "identifier"
|
||||
| "string"
|
||||
| "integer"
|
||||
| "float"
|
||||
| "boolean"
|
||||
| "regex_literal"
|
||||
| "comparison_constraint"
|
||||
| "import_expression" => true,
|
||||
"path_expression"
|
||||
| "call_expression"
|
||||
| "unary_expression"
|
||||
| "binary_expression"
|
||||
| "default_expression"
|
||||
| "parenthesized_expression" => {
|
||||
!expression_contains_comment(node)
|
||||
&& named_children(node).into_iter().all(is_inline_expr)
|
||||
}
|
||||
"array" | "array_constraint" => {
|
||||
!expression_contains_comment(node)
|
||||
&& named_children(node).into_iter().all(is_inline_expr)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn has_blank_line(text: &str) -> bool {
|
||||
text.bytes().filter(|byte| *byte == b'\n').count() >= 2
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn write_indent(out: &mut String, indent: usize) {
|
||||
for _ in 0..indent {
|
||||
out.push(' ');
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn formats_fields_and_preserves_comments() {
|
||||
let source =
|
||||
"Server={\n# host\nhost=String default \"localhost\"; # trailing\n\nport=Int&>0;\n};";
|
||||
let formatted = format_source(source).unwrap();
|
||||
assert_eq!(
|
||||
formatted,
|
||||
"Server = {\n # host\n host = String default \"localhost\"; # trailing\n\n port = Int & > 0;\n};\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_arrays_and_match_comments() {
|
||||
let source = "result=match x{# c\n_: [1,{a=2;}];};";
|
||||
let formatted = format_source(source).unwrap();
|
||||
assert_eq!(
|
||||
formatted,
|
||||
"result = match x {\n # c\n _: [\n 1,\n {\n a = 2;\n },\n ];\n};\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_array_constraints() {
|
||||
let source = "tags=[...String];ports=[...(Int&>=1)];";
|
||||
let formatted = format_source(source).unwrap();
|
||||
assert_eq!(
|
||||
formatted,
|
||||
"tags = [...String];\nports = [...(Int & >= 1)];\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wasm_export_returns_json() {
|
||||
let output = format_source_json("value={a=1;};");
|
||||
assert!(output.contains("\"ok\":true"));
|
||||
assert!(output.contains("value = {\\n a = 1;\\n};\\n"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "decodal-wasm"
|
||||
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 = { version = "0.1.2", path = "../decodal-core" }
|
||||
serde_json.workspace = true
|
||||
wasm-bindgen.workspace = true
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = false
|
||||
@@ -0,0 +1,256 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use decodal::{
|
||||
Data, Diagnostic, DiagnosticKind, EmptyLoader, Engine, LoadedSource, SourceId, SourceLoader,
|
||||
Span, format_diagnostic_with,
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn evaluate(source: &str) -> String {
|
||||
encode_result(evaluate_inner(source))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = evaluateProject)]
|
||||
pub fn evaluate_project(entry: &str, files_json: &str) -> String {
|
||||
encode_result(evaluate_project_inner(entry, files_json))
|
||||
}
|
||||
|
||||
fn encode_result(result: Result<String, String>) -> String {
|
||||
match result {
|
||||
Ok(output) => format!("{{\"ok\":true,\"output\":{}}}", json_string(&output)),
|
||||
Err(error) => format!("{{\"ok\":false,\"error\":{}}}", json_string(&error)),
|
||||
}
|
||||
}
|
||||
|
||||
fn evaluate_inner(source: &str) -> Result<String, String> {
|
||||
let mut engine = Engine::new(EmptyLoader);
|
||||
let module = match engine.add_root_source("playground", "playground", source) {
|
||||
Ok(module) => module,
|
||||
Err(error) => return Err(format_diagnostic_with_root(&error, "playground")),
|
||||
};
|
||||
let value = match engine.eval_module(module) {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(engine.format_diagnostic(&error)),
|
||||
};
|
||||
let data = match engine.materialize(&value) {
|
||||
Ok(data) => data,
|
||||
Err(error) => return Err(engine.format_diagnostic(&error)),
|
||||
};
|
||||
Ok(format_data(&data, 0))
|
||||
}
|
||||
|
||||
fn evaluate_project_inner(entry: &str, files_json: &str) -> Result<String, String> {
|
||||
let raw_files: BTreeMap<String, String> = serde_json::from_str(files_json)
|
||||
.map_err(|error| format!("failed to read playground files: {error}"))?;
|
||||
let mut files = BTreeMap::new();
|
||||
for (path, source) in raw_files {
|
||||
let path = normalize_path(&path).ok_or_else(|| format!("invalid file path `{path}`"))?;
|
||||
files.insert(path, source);
|
||||
}
|
||||
|
||||
let entry = normalize_path(entry).ok_or_else(|| format!("invalid entry path `{entry}`"))?;
|
||||
let source = files
|
||||
.get(&entry)
|
||||
.cloned()
|
||||
.ok_or_else(|| format!("entry file `{entry}` was not found"))?;
|
||||
|
||||
let mut engine = Engine::new(VirtualLoader { files });
|
||||
let module = match engine.add_root_source(entry.clone(), entry.clone(), &source) {
|
||||
Ok(module) => module,
|
||||
Err(error) => return Err(format_diagnostic_with_root(&error, &entry)),
|
||||
};
|
||||
let value = match engine.eval_module(module) {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(engine.format_diagnostic(&error)),
|
||||
};
|
||||
let data = match engine.materialize(&value) {
|
||||
Ok(data) => data,
|
||||
Err(error) => return Err(engine.format_diagnostic(&error)),
|
||||
};
|
||||
Ok(format_data(&data, 0))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct VirtualLoader {
|
||||
files: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl SourceLoader for VirtualLoader {
|
||||
fn load(
|
||||
&mut self,
|
||||
current_key: Option<&str>,
|
||||
specifier: &str,
|
||||
) -> decodal::Result<LoadedSource> {
|
||||
let key = resolve_import(current_key, specifier).ok_or_else(|| {
|
||||
Diagnostic::new(
|
||||
DiagnosticKind::Import,
|
||||
Span::default(),
|
||||
format!("invalid import path `{specifier}`"),
|
||||
)
|
||||
})?;
|
||||
let source = self.files.get(&key).cloned().ok_or_else(|| {
|
||||
Diagnostic::new(
|
||||
DiagnosticKind::Import,
|
||||
Span::default(),
|
||||
format!("import `{specifier}` resolved to `{key}`, but that file does not exist"),
|
||||
)
|
||||
})?;
|
||||
Ok(LoadedSource {
|
||||
key: key.clone(),
|
||||
name: key,
|
||||
source,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_import(current_key: Option<&str>, specifier: &str) -> Option<String> {
|
||||
if specifier.starts_with('/') {
|
||||
return normalize_path(specifier);
|
||||
}
|
||||
|
||||
let mut base = String::new();
|
||||
if let Some(current_key) = current_key {
|
||||
if let Some((parent, _file)) = current_key.rsplit_once('/') {
|
||||
base.push_str(parent);
|
||||
base.push('/');
|
||||
}
|
||||
}
|
||||
base.push_str(specifier);
|
||||
normalize_path(&base)
|
||||
}
|
||||
|
||||
fn normalize_path(path: &str) -> Option<String> {
|
||||
let mut parts = Vec::new();
|
||||
let normalized = path.replace('\\', "/");
|
||||
for part in normalized.split('/') {
|
||||
match part {
|
||||
"" | "." => {}
|
||||
".." => {
|
||||
parts.pop()?;
|
||||
}
|
||||
part => parts.push(part),
|
||||
}
|
||||
}
|
||||
if parts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(parts.join("/"))
|
||||
}
|
||||
}
|
||||
|
||||
fn format_diagnostic_with_root(diagnostic: &decodal::Diagnostic, root_name: &str) -> String {
|
||||
format_diagnostic_with(diagnostic, |source| {
|
||||
(source == SourceId(0)).then_some(root_name)
|
||||
})
|
||||
}
|
||||
|
||||
fn format_data(data: &Data, indent: usize) -> String {
|
||||
match data {
|
||||
Data::String(value) => json_string(value),
|
||||
Data::Int(value) => value.to_string(),
|
||||
Data::Float(value) => value.to_string(),
|
||||
Data::Bool(value) => value.to_string(),
|
||||
Data::Array(items) => {
|
||||
if items.is_empty() {
|
||||
return String::from("[]");
|
||||
}
|
||||
let mut out = String::from("[\n");
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
out.push_str(&" ".repeat(indent + 2));
|
||||
out.push_str(&format_data(item, indent + 2));
|
||||
if index + 1 != items.len() {
|
||||
out.push(',');
|
||||
}
|
||||
out.push('\n');
|
||||
}
|
||||
out.push_str(&" ".repeat(indent));
|
||||
out.push(']');
|
||||
out
|
||||
}
|
||||
Data::Object(fields) => {
|
||||
if fields.is_empty() {
|
||||
return String::from("{}");
|
||||
}
|
||||
let mut out = String::from("{\n");
|
||||
for (index, field) in fields.iter().enumerate() {
|
||||
out.push_str(&" ".repeat(indent + 2));
|
||||
out.push_str(&json_string(&field.name));
|
||||
out.push_str(": ");
|
||||
out.push_str(&format_data(&field.value, indent + 2));
|
||||
if index + 1 != fields.len() {
|
||||
out.push(',');
|
||||
}
|
||||
out.push('\n');
|
||||
}
|
||||
out.push_str(&" ".repeat(indent));
|
||||
out.push('}');
|
||||
out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn json_string(value: &str) -> String {
|
||||
let mut out = String::from("\"");
|
||||
for ch in value.chars() {
|
||||
match ch {
|
||||
'"' => out.push_str("\\\""),
|
||||
'\\' => out.push_str("\\\\"),
|
||||
'\n' => out.push_str("\\n"),
|
||||
'\r' => out.push_str("\\r"),
|
||||
'\t' => out.push_str("\\t"),
|
||||
ch if ch.is_control() => {
|
||||
use core::fmt::Write;
|
||||
let _ = write!(out, "\\u{:04x}", ch as u32);
|
||||
}
|
||||
ch => out.push(ch),
|
||||
}
|
||||
}
|
||||
out.push('"');
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{evaluate_project_inner, normalize_path, resolve_import};
|
||||
|
||||
#[test]
|
||||
fn normalizes_virtual_paths() {
|
||||
assert_eq!(
|
||||
normalize_path("/schemas/../main.dcdl"),
|
||||
Some("main.dcdl".into())
|
||||
);
|
||||
assert_eq!(normalize_path("../main.dcdl"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_imports_relative_to_current_file() {
|
||||
assert_eq!(
|
||||
resolve_import(Some("schemas/service.dcdl"), "./types.dcdl"),
|
||||
Some("schemas/types.dcdl".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_project_imports() {
|
||||
let files = r#"{
|
||||
"main.dcdl":"let dep = import \"./schemas/service.dcdl\"; in dep.Service & { port = 9443; }",
|
||||
"schemas/service.dcdl":"Service = { name = String default \"api\"; port = Int & > 443 default 8443; }"
|
||||
}"#;
|
||||
let output = evaluate_project_inner("main.dcdl", files).unwrap();
|
||||
assert!(output.contains("\"port\": 9443"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_diagnostics_use_virtual_file_names() {
|
||||
let files = r#"{
|
||||
"main.dcdl":"let dep = import \"./schemas/service.dcdl\"; in dep.Service & { port = 80; }",
|
||||
"schemas/service.dcdl":"Service = { port = Int & > 443 default 8443; }"
|
||||
}"#;
|
||||
let error = evaluate_project_inner("main.dcdl", files).unwrap_err();
|
||||
assert!(error.contains("main.dcdl:"));
|
||||
assert!(error.contains("schemas/service.dcdl:"));
|
||||
assert!(!error.contains("source 0:"));
|
||||
assert!(!error.contains("source 1:"));
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,13 @@ pkgs.mkShell {
|
||||
cargo
|
||||
clippy
|
||||
git
|
||||
lld
|
||||
nodejs
|
||||
nixfmt
|
||||
rustc
|
||||
rustfmt
|
||||
tree-sitter
|
||||
wasm-pack
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
# 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/
|
||||
packages/decodal-wasm/
|
||||
```
|
||||
|
||||
The npm package is `decodal-wasm`.
|
||||
The JSR package is `@hare/decodal-wasm`.
|
||||
|
||||
The generated files in `packages/decodal-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.
|
||||
|
||||
## Language tools
|
||||
|
||||
Source-level tooling lives in the Rust language tools crate.
|
||||
This component is responsible for operations that must preserve source text details such as comments and whitespace.
|
||||
It is an internal crate used by the future Rust LSP and by the CodeMirror package's bundled formatter WebAssembly.
|
||||
|
||||
Important paths:
|
||||
|
||||
```text
|
||||
crates/decodal-language-tools/
|
||||
```
|
||||
|
||||
The current language tools crate exposes the formatter.
|
||||
Future LSP functionality should build on the same source-level tooling layer rather than on the runtime core.
|
||||
|
||||
## Web editor components
|
||||
|
||||
The Web playground editor uses CodeMirror 6 with a generated Lezer parser.
|
||||
This is the source of syntax highlighting, folding, indentation, editor syntax tree behavior, and the browser formatter command in the browser UI.
|
||||
|
||||
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
|
||||
packages/decodal-codemirror/src/format.js
|
||||
packages/decodal-codemirror/wasm/
|
||||
```
|
||||
|
||||
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 formatting and editor syntax: Lezer / CodeMirror
|
||||
- Rust LSP internals: `decodal-language-tools`
|
||||
- General editor syntax: Tree-sitter
|
||||
|
||||
This avoids having a separate token stream API whose behavior would have to be kept compatible with both runtime parsing and editor grammars.
|
||||
@@ -59,8 +59,9 @@ Config = MyConfig & {
|
||||
|
||||
## default の合成
|
||||
|
||||
初期方針では、`&` による異なる default 同士の合成は conflict とする。
|
||||
同じ default は同一候補として扱ってよい。
|
||||
`&` で片方だけが default を持つ場合、その default を保持する。
|
||||
同じ thunk 由来の default 同士は同一 default として保持する。
|
||||
異なる default 同士は conflict とする。
|
||||
|
||||
```text
|
||||
merge_default(None, None) -> None
|
||||
@@ -117,3 +118,9 @@ Abstract { constraints, default: None }
|
||||
|
||||
materialize は default を採用する唯一の段階である。
|
||||
通常評価中に明示値が得られた場合、default は採用されない。
|
||||
|
||||
## Diagnostic context
|
||||
|
||||
Composition and materialization keep source spans for object fields, constraints, defaults, and thunks where possible.
|
||||
When a conflict occurs, the diagnostic should identify the operation span and related participant spans, such as the left field, right field, constraint, or default value.
|
||||
For object materialization errors, diagnostics also include the field path being processed when known.
|
||||
|
||||
@@ -10,10 +10,20 @@ Diagnostic {
|
||||
kind: DiagnosticKind
|
||||
span: Span
|
||||
message: String
|
||||
notes: Vec<Note>
|
||||
labels: Vec<DiagnosticLabel>
|
||||
}
|
||||
|
||||
DiagnosticLabel {
|
||||
span: Span
|
||||
message: String
|
||||
}
|
||||
```
|
||||
|
||||
`span` は primary location を示す。
|
||||
表示時には `Span.source` を source id のまま出すのではなく、可能な限り file path や virtual file name に解決する。
|
||||
`labels` は同じ error に関係する追加 location を示す。
|
||||
合成や materialize の失敗では、衝突した constraint、value、default、または処理中 field path を label に含める。
|
||||
|
||||
代表的な diagnostic kind:
|
||||
|
||||
- syntax error
|
||||
@@ -38,6 +48,18 @@ Result<RuntimeValue, Diagnostic>
|
||||
|
||||
これにより、制約違反、未定義識別子、循環依存、import 失敗などが通常値として流れることを避ける。
|
||||
|
||||
## 合成と materialize の diagnostic
|
||||
|
||||
合成や materialize の失敗は、以下を示す。
|
||||
|
||||
1. どの段階で失敗したか: composition、patch、materialization
|
||||
2. どの field path を処理中だったか
|
||||
3. どの constraint、value、default が衝突したか
|
||||
4. なぜ合成または materialize できないか
|
||||
|
||||
例えば default が constraint を満たさない場合は、constraint の位置と default value の位置の両方を label として持つ。
|
||||
object field の合成で concrete value が衝突する場合は、左辺 field と右辺 field の位置を label として持つ。
|
||||
|
||||
## `try / catch` は core に入れない
|
||||
|
||||
汎用 `try / catch` は core に入れない。
|
||||
@@ -47,21 +69,6 @@ fallback は有限で明示的な仕組みに限定する。
|
||||
|
||||
- `default`: 未指定値の fallback。
|
||||
- `match`: 有限 pattern に基づく分岐。
|
||||
- optional import: ファイル不存在など、限定された失敗だけを fallback 可能にする候補。
|
||||
- optional field access: field 不在だけを fallback 可能にする候補。
|
||||
- union / tagged schema: 複数 schema の選択を明示的に表す将来候補。
|
||||
|
||||
## optional fallback の扱い
|
||||
|
||||
optional import や optional field access を導入する場合も、捕捉できる失敗は限定する。
|
||||
|
||||
例として optional import は、ファイル不存在だけを fallback 可能にし、parse error や import 先の制約違反は diagnostic として報告する方がよい。
|
||||
|
||||
```text
|
||||
optional import:
|
||||
file not found -> fallback
|
||||
parse error -> diagnostic
|
||||
eval error -> diagnostic
|
||||
```
|
||||
|
||||
この方針により、fallback は通常の値選択として扱い、エラー内容に依存した実行時分岐は避ける。
|
||||
Decodal は `unknown` / `any` を持たないため、field 不在や未解決 identifier を fallback 可能な通常値として扱わない。
|
||||
それらは diagnostic として報告する。
|
||||
|
||||
@@ -24,7 +24,7 @@ Primitive type names such as `String`, `Int`, `Float`, and `Bool` are handled be
|
||||
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);
|
||||
|
||||
@@ -59,12 +59,16 @@ HostValue =
|
||||
Float
|
||||
Bool
|
||||
Array(Vec<HostValue>)
|
||||
ArrayConstraint { item, constraints, default }
|
||||
Object(Vec<HostField>)
|
||||
Abstract { constraints, default }
|
||||
```
|
||||
|
||||
When a host value is bound, the engine internalizes it into `RuntimeValue` and allocates value thunks for object fields, array items, and defaults.
|
||||
|
||||
`HostValue::array_of(item)` builds an array constraint with a required element schema.
|
||||
There is no host API for an unconstrained abstract array.
|
||||
|
||||
## Abstract host objects
|
||||
|
||||
A host-provided schema object is represented as a concrete object structure whose fields may contain abstract values.
|
||||
@@ -87,6 +91,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.
|
||||
|
||||
@@ -1,10 +1,43 @@
|
||||
# Features
|
||||
|
||||
Decodal keeps the embedded core small by making heavy functionality opt-in.
|
||||
Decodal は embedded use と小さい runtime を優先する。
|
||||
言語機能を追加するときは、値の合成・検証・materialization に直接必要なものを core に残し、重い依存や高度な推論は optional feature または外部 tooling に分ける。
|
||||
|
||||
## Core feature boundary
|
||||
|
||||
Core に入れる機能は、基本的に deterministic な value transformation に限る。
|
||||
|
||||
- arithmetic / logical / comparison operators
|
||||
- array concat
|
||||
- object / constraint composition
|
||||
- default materialization
|
||||
- pure function evaluation
|
||||
- host supplied import evaluation
|
||||
|
||||
Core に入れないものは以下である。
|
||||
|
||||
- filesystem / network / environment access
|
||||
- time / random
|
||||
- mutation
|
||||
- reflection or existence probing
|
||||
- arbitrary host function calls
|
||||
- symbolic constraint solving beyond simple normalization
|
||||
|
||||
未解決 identifier や missing field は `unknown` として流れず、diagnostic になる。
|
||||
この方針により、存在チェックや optional chaining のような dynamic object inspection は core language の対象外とする。
|
||||
|
||||
## Constraint reasoning
|
||||
|
||||
Constraint normalization は軽量な範囲に留める。
|
||||
primitive type conflict や明らかな numeric bound conflict は合成時に検出してよい。
|
||||
一方で、symbolic arithmetic、boolean algebra、regex intersection、array length dependent typing のような重い推論は行わない。
|
||||
|
||||
評価済みの concrete value に対する検証は runtime / materialization で行う。
|
||||
静的に完全な型検査フェーズを増やすのではなく、parse、evaluate、compose、materialize の各段階で自然に分かる error を diagnostic として返す。
|
||||
|
||||
## Core defaults
|
||||
|
||||
`decodal-core` defaults to `std` only.
|
||||
`decodal` defaults to `std` only.
|
||||
|
||||
```toml
|
||||
[features]
|
||||
@@ -13,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
|
||||
|
||||
@@ -21,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.
|
||||
@@ -30,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.
|
||||
|
||||
@@ -14,6 +14,10 @@ RuntimeValue =
|
||||
`Concrete` は明示的な値である。
|
||||
`Abstract` は、まだ具体値に確定していない制約付きの値である。
|
||||
|
||||
Decodal は `unknown`、`any`、`null` のような「存在するが意味が未確定な値」を runtime value として持たない。
|
||||
識別子や field が解決できない場合は、その場で diagnostic になる。
|
||||
未解決値を後続の演算へ流して推論することはしない。
|
||||
|
||||
## ConcreteValue
|
||||
|
||||
```text
|
||||
@@ -32,7 +36,11 @@ object は concrete structure として扱う。
|
||||
|
||||
```text
|
||||
ObjectValue:
|
||||
fields: Map<Symbol, ThunkId>
|
||||
fields: Map<Symbol, ObjectField>
|
||||
|
||||
ObjectField:
|
||||
value: ThunkId
|
||||
span: Span
|
||||
```
|
||||
|
||||
例えば以下の schema object は、object 自体は concrete だが、field の値は abstract value になる。
|
||||
@@ -57,9 +65,14 @@ Concrete(Object {
|
||||
|
||||
```text
|
||||
AbstractValue {
|
||||
constraints: Vec<Constraint>
|
||||
constraints: Vec<ConstraintEntry>
|
||||
default: Option<ThunkId>
|
||||
}
|
||||
|
||||
ConstraintEntry {
|
||||
constraint: Constraint
|
||||
span: Span
|
||||
}
|
||||
```
|
||||
|
||||
`default` は `AbstractValue` にだけ存在する。
|
||||
@@ -88,6 +101,21 @@ port = 8000;
|
||||
Concrete(Int(8000))
|
||||
```
|
||||
|
||||
## Runtime scope
|
||||
|
||||
Decodal runtime は application runtime ではなく、pure value evaluator である。
|
||||
同じ source、同じ import sources、同じ host globals が与えられた場合、評価結果は決定的である。
|
||||
|
||||
runtime が扱う責務は以下に限る。
|
||||
|
||||
- expression を評価する。
|
||||
- thunk を必要に応じて force する。
|
||||
- concrete / abstract value を合成する。
|
||||
- materialize 時に constraint を検証する。
|
||||
|
||||
runtime は filesystem、network、environment variable、time、random、mutation を扱わない。
|
||||
core における import は host supplied source を受け取る境界であり、filesystem access ではない。
|
||||
|
||||
## Constraint
|
||||
|
||||
constraint は concrete value とは別の型として扱う。
|
||||
@@ -95,12 +123,16 @@ constraint は concrete value とは別の型として扱う。
|
||||
```text
|
||||
Constraint =
|
||||
Type(PrimitiveType)
|
||||
ArrayItems(ThunkId)
|
||||
Compare(Op, Literal)
|
||||
Regex(Pattern)
|
||||
BuiltinPredicate(Symbol)
|
||||
ObjectConstraint(...)
|
||||
```
|
||||
|
||||
`ArrayItems` は配列そのものの型と、すべての要素へ合成する schema thunk を表す。
|
||||
配列用の primitive type は持たず、抽象配列には必ず要素制約が必要である。
|
||||
|
||||
初期実装では、object の形は主に `Concrete(Object)` の field に `Abstract` を置くことで表現する。
|
||||
object 全体にかかる constraint は必要になった時点で追加する。
|
||||
|
||||
|
||||
@@ -84,5 +84,5 @@ module root や field は thunk として保持され、参照されたときだ
|
||||
関数引数は thunk として関数の environment に束縛する。
|
||||
関数本体で引数が参照されたときだけ force する。
|
||||
|
||||
任意の関数呼び出し結果をグローバルに memoize する必要はない。
|
||||
関数呼び出し結果そのものはグローバルには memoize しない。
|
||||
field に束縛された関数呼び出し結果は、その field thunk の評価結果として memoize される。
|
||||
|
||||
+167
-10
@@ -9,15 +9,164 @@ 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`, the Rust source crate `decodal-wasm`, and `decodal-language-tools` are not published to crates.io.
|
||||
The generated WebAssembly package under `packages/decodal-wasm/` is published to npm and JSR.
|
||||
The CodeMirror package bundles the generated formatter WebAssembly from `decodal-language-tools`.
|
||||
The project is dual licensed as `MIT OR Apache-2.0`.
|
||||
|
||||
```sh
|
||||
cargo publish -p decodal
|
||||
```
|
||||
|
||||
Publish `decodal-derive` first only when that crate has a new version:
|
||||
|
||||
```sh
|
||||
cargo publish -p decodal-derive
|
||||
```
|
||||
|
||||
Before publishing, run:
|
||||
|
||||
```sh
|
||||
cargo fmt --check
|
||||
cargo test
|
||||
cargo check -p decodal --no-default-features
|
||||
cargo publish -p decodal --dry-run
|
||||
```
|
||||
|
||||
If `decodal-derive` changed, also run `cargo publish -p decodal-derive --dry-run`.
|
||||
|
||||
## Web site and playground
|
||||
|
||||
The Astro documentation site and browser playground are kept in:
|
||||
|
||||
```text
|
||||
site/decodal-site/
|
||||
```
|
||||
|
||||
The site imports Markdown files from `doc/manual/souce/` and renders them as mdBook-style pages.
|
||||
The playground loads `decodal-wasm` for evaluation and `decodal-codemirror` for editor features and source formatting.
|
||||
|
||||
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
|
||||
packages/decodal-wasm/decodal_wasm.js
|
||||
packages/decodal-wasm/decodal_wasm_bg.wasm
|
||||
packages/decodal-codemirror/wasm/decodal_language_tools.js
|
||||
packages/decodal-codemirror/wasm/decodal_language_tools_bg.wasm
|
||||
crates/decodal-wasm/src/lib.rs
|
||||
crates/decodal-language-tools/src/lib.rs
|
||||
```
|
||||
|
||||
Build the WebAssembly packages before building the site:
|
||||
|
||||
```sh
|
||||
cd site/decodal-site
|
||||
npm install
|
||||
npm run build:wasm
|
||||
npm run build
|
||||
```
|
||||
|
||||
`npm run build:wasm` builds both generated WebAssembly packages.
|
||||
`npm run build:runtime` writes generated runtime files into `packages/decodal-wasm/`.
|
||||
`npm run build:tools` writes generated language tools files into `packages/decodal-codemirror/wasm/`.
|
||||
|
||||
These generated files are committed so the site can be built without requiring every consumer to regenerate the wasm packages first.
|
||||
|
||||
Publish the generated WebAssembly package from its package directory:
|
||||
|
||||
```sh
|
||||
cd packages/decodal-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
|
||||
cd site/decodal-site
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Deploy the static site to Cloudflare Pages with Wrangler direct upload:
|
||||
|
||||
```sh
|
||||
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` 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
|
||||
CLOUDFLARE_PROJECT_NAME=my-pages-project npm run deploy
|
||||
```
|
||||
|
||||
If the committed WASM package must be regenerated before deploy, use:
|
||||
|
||||
```sh
|
||||
npm run deploy:wasm
|
||||
```
|
||||
|
||||
## Tree-sitter grammar
|
||||
@@ -64,16 +213,22 @@ 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
|
||||
|
||||
The Nix development shell includes Rust tooling, Node.js, and Tree-sitter CLI tooling.
|
||||
The Nix development shell includes Rust tooling, Node.js, Tree-sitter CLI tooling, and wasm-pack tooling.
|
||||
|
||||
```sh
|
||||
nix develop
|
||||
@@ -87,5 +242,7 @@ The shell provides:
|
||||
- `clippy`
|
||||
- `node`
|
||||
- `npm`
|
||||
- `wasm-pack`
|
||||
- `lld`
|
||||
- `tree-sitter`
|
||||
- `nixfmt`
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -124,6 +124,19 @@ String & /^a$/ & /^b$/
|
||||
Host = IPv4Address;
|
||||
```
|
||||
|
||||
## 配列制約
|
||||
|
||||
配列制約には要素制約が必須であり、`[...T]` と書く。
|
||||
|
||||
```dcdl
|
||||
Names = [...String];
|
||||
PositiveInts = [...(Int & > 0)];
|
||||
```
|
||||
|
||||
複数の配列制約を `&` で合成した場合、各 concrete 要素へすべての要素制約を合成する。
|
||||
要素が object schema の場合は、その schema に含まれる default も各要素へ適用される。
|
||||
要素制約のない `Array` primitive type は存在しない。
|
||||
|
||||
## default
|
||||
|
||||
`default` は制約ではない。
|
||||
@@ -188,11 +201,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,37 @@ disabled_config = NewConfig & {
|
||||
enabled_config = NewConfig;
|
||||
```
|
||||
|
||||
## 関数と文字列生成
|
||||
## 配列スキーマ
|
||||
|
||||
```dcdl
|
||||
Services = [...{
|
||||
name = String;
|
||||
port = Int default 8080;
|
||||
}];
|
||||
|
||||
Services & [
|
||||
{ name = "api"; },
|
||||
{ name = "worker"; port = 9000; },
|
||||
]
|
||||
```
|
||||
|
||||
抽象配列には要素制約が必須である。
|
||||
この例では、1 番目の要素の `port` は `8080` に materialize される。
|
||||
|
||||
## 関数と制約
|
||||
|
||||
```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
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Arithmetic Expression
|
||||
|
||||
Decodal supports arithmetic over concrete numeric values.
|
||||
|
||||
```dcdl
|
||||
{
|
||||
workers = 2 + 2;
|
||||
timeout = 30.0 / 2;
|
||||
port = 8000 + 80;
|
||||
negative = -1;
|
||||
}
|
||||
```
|
||||
|
||||
## Operators
|
||||
|
||||
- `+` addition
|
||||
- `-` subtraction
|
||||
- `*` multiplication
|
||||
- `/` division
|
||||
- unary `-` negation
|
||||
|
||||
`*` and `/` bind tighter than `+` and `-`.
|
||||
Parentheses can be used to make grouping explicit.
|
||||
|
||||
```dcdl
|
||||
2 + 3 * 4 # 14
|
||||
(2 + 3) * 4 # 20
|
||||
```
|
||||
|
||||
## Numeric behavior
|
||||
|
||||
Arithmetic requires concrete `Int` or `Float` operands.
|
||||
`Int + Int`, `Int - Int`, and `Int * Int` produce `Int` when no overflow occurs.
|
||||
Mixed `Int` / `Float` arithmetic produces `Float`.
|
||||
Division always produces `Float`.
|
||||
|
||||
Division by zero and integer overflow are evaluation errors.
|
||||
|
||||
Arithmetic expressions can be used anywhere a concrete numeric expression is expected, including defaults and numeric constraints.
|
||||
|
||||
```dcdl
|
||||
port = Int & > 4000 + 42 default 8080;
|
||||
```
|
||||
@@ -7,9 +7,61 @@ array expression は、順序付きの値の列を表す。
|
||||
["a", "b", "c"]
|
||||
```
|
||||
|
||||
## 未確定事項
|
||||
配列リテラルは concrete value であり、要素型を揃える必要はない。
|
||||
|
||||
- 配列要素の制約表現。
|
||||
- 異種配列を許可するか。
|
||||
- `//` による patch を右辺置換だけにするか。
|
||||
- append / prepend / remove などの操作を提供するか。
|
||||
```dcdl
|
||||
["api", 8080, true]
|
||||
```
|
||||
|
||||
## Array constraint
|
||||
|
||||
配列制約は `[` の直後に ellipsis を置き、その後へ要素制約を記述する。
|
||||
|
||||
```dcdl
|
||||
Names = [...String];
|
||||
Ports = [...(Int & >= 1 & <= 65535)];
|
||||
```
|
||||
|
||||
`[...T]` は、すべての要素が `T` を満たす長さ 0 以上の配列を表す。
|
||||
空配列は任意の配列制約を満たす。
|
||||
|
||||
```dcdl
|
||||
[...String] & []
|
||||
[...String] & ["api", "worker"]
|
||||
```
|
||||
|
||||
要素制約は object schema にもできる。
|
||||
要素 schema の default は、配列へ制約を合成するときに各要素へ適用される。
|
||||
|
||||
```dcdl
|
||||
Services = [...{
|
||||
name = String;
|
||||
enabled = Bool default true;
|
||||
}];
|
||||
|
||||
Services & [{ name = "api"; }]
|
||||
```
|
||||
|
||||
要素制約のない抽象配列型は提供しない。
|
||||
旧来の `Array` primitive type は使用できず、`[...T]` の `T` は必須である。
|
||||
`[String]` は配列制約ではなく、未解決の `String` 制約を 1 要素に持つ concrete array になる。
|
||||
長さ制約、位置別の tuple 制約、unique 制約は現在サポートしない。
|
||||
|
||||
## Array concat
|
||||
|
||||
`++` は concrete array 同士を連結する。
|
||||
|
||||
```dcdl
|
||||
base = ["read", "write"];
|
||||
extra = ["admin"];
|
||||
roles = base ++ extra;
|
||||
```
|
||||
|
||||
`roles` は以下と同じ値になる。
|
||||
|
||||
```dcdl
|
||||
["read", "write", "admin"]
|
||||
```
|
||||
|
||||
`++` は配列要素を変換しない。
|
||||
左辺の要素の後に右辺の要素が並ぶ。
|
||||
|
||||
@@ -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) に置く。
|
||||
|
||||
@@ -11,6 +11,7 @@ Expr
|
||||
├─ path reference
|
||||
├─ object
|
||||
├─ array
|
||||
├─ array constraint
|
||||
├─ function
|
||||
├─ function call
|
||||
├─ let
|
||||
|
||||
@@ -4,12 +4,10 @@ let expression は、ローカル束縛を作る。
|
||||
|
||||
```dcdl
|
||||
let
|
||||
part = {
|
||||
greet = "Hello";
|
||||
target = "World";
|
||||
};
|
||||
base = 8000;
|
||||
offset = 80;
|
||||
in
|
||||
"${part.greet}! ${part.target}"
|
||||
base + offset
|
||||
```
|
||||
|
||||
## 評価
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Logical and Comparison Expressions
|
||||
|
||||
Decodal supports boolean logic over concrete `Bool` values and comparison over concrete scalar values.
|
||||
|
||||
```dcdl
|
||||
{
|
||||
is_prod = env == "prod";
|
||||
high_port = port > 9000;
|
||||
enabled = is_prod && high_port;
|
||||
disabled = !enabled;
|
||||
}
|
||||
```
|
||||
|
||||
## Logical operators
|
||||
|
||||
- `!expr` negates a concrete `Bool`.
|
||||
- `lhs && rhs` returns boolean AND.
|
||||
- `lhs || rhs` returns boolean OR.
|
||||
|
||||
`&&` and `||` short-circuit: the right-hand side is evaluated only when needed.
|
||||
Logical operands must evaluate to concrete `Bool` values.
|
||||
|
||||
## Comparison operators
|
||||
|
||||
- `==`
|
||||
- `!=`
|
||||
- `<`
|
||||
- `<=`
|
||||
- `>`
|
||||
- `>=`
|
||||
|
||||
`==` and `!=` compare concrete scalar values: `String`, `Bool`, `Int`, and `Float`.
|
||||
`Int` and `Float` can be compared to each other numerically.
|
||||
|
||||
Ordering operators `<`, `<=`, `>`, and `>=` compare concrete numeric values only.
|
||||
They are separate from prefix comparison constraints such as `> 443`.
|
||||
|
||||
```dcdl
|
||||
port = Int & > 443 default 9443;
|
||||
is_high = port > 9000;
|
||||
```
|
||||
@@ -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,113 @@
|
||||
# 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_constraint
|
||||
| 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 } , [ "," ] ] , "]" ;
|
||||
array_constraint = "[" , "..." , 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
|
||||
|
||||
|
||||
@@ -1,6 +1,79 @@
|
||||
# 合成演算子
|
||||
# 演算子
|
||||
|
||||
この章では、`&` と `//` の意味を定義する。
|
||||
この章では、Decodal の演算子の意味を定義する。
|
||||
|
||||
## 演算子一覧
|
||||
|
||||
| 演算子 | 形 | 種類 | 対象 | 結果 / 意味 |
|
||||
|---|---|---|---|---|
|
||||
| `.` | `object.field` | field reference | object / abstract object | field value |
|
||||
| call | `fn(arg)` | function call | function | function result |
|
||||
| `!` | `!expr` | unary logical | concrete `Bool` | concrete `Bool` |
|
||||
| `-` | `-expr` | unary arithmetic | concrete `Int` / `Float` | negated number |
|
||||
| `*` | `lhs * rhs` | arithmetic | concrete `Int` / `Float` | numeric product |
|
||||
| `/` | `lhs / rhs` | arithmetic | concrete `Int` / `Float` | `Float` quotient |
|
||||
| `+` | `lhs + rhs` | arithmetic | concrete `Int` / `Float` | numeric sum |
|
||||
| `-` | `lhs - rhs` | arithmetic | concrete `Int` / `Float` | numeric difference |
|
||||
| `++` | `lhs ++ rhs` | array concat | concrete arrays | concatenated array |
|
||||
| `==` | `lhs == rhs` | equality | concrete scalar | concrete `Bool` |
|
||||
| `!=` | `lhs != rhs` | equality | concrete scalar | concrete `Bool` |
|
||||
| `<` | `lhs < rhs` | ordering | concrete `Int` / `Float` | concrete `Bool` |
|
||||
| `<=` | `lhs <= rhs` | ordering | concrete `Int` / `Float` | concrete `Bool` |
|
||||
| `>` | `lhs > rhs` | ordering | concrete `Int` / `Float` | concrete `Bool` |
|
||||
| `>=` | `lhs >= rhs` | ordering | concrete `Int` / `Float` | concrete `Bool` |
|
||||
| `>` | `> value` | comparison constraint | numeric constraint value | abstract constraint |
|
||||
| `>=` | `>= value` | comparison constraint | numeric constraint value | abstract constraint |
|
||||
| `<` | `< value` | comparison constraint | numeric constraint value | abstract constraint |
|
||||
| `<=` | `<= value` | comparison constraint | numeric constraint value | abstract constraint |
|
||||
| `&&` | `lhs && rhs` | logical | concrete `Bool` | short-circuit AND |
|
||||
| `||` | `lhs || rhs` | logical | concrete `Bool` | short-circuit OR |
|
||||
| `&` | `lhs & rhs` | composition | value / constraint / object | constraint-preserving composition |
|
||||
| `//` | `lhs // rhs` | patch | object / value | right-biased structural patch |
|
||||
| `default` | `base default fallback` | default | abstract value | materialization fallback |
|
||||
|
||||
`concrete scalar` は `String`、`Bool`、`Int`、`Float` を指す。
|
||||
|
||||
## 優先順位
|
||||
|
||||
優先順位は高い順に以下である。
|
||||
|
||||
1. 関数呼び出しとフィールド参照
|
||||
2. unary `!` `-`
|
||||
3. `*` `/`
|
||||
4. `+` `-`
|
||||
5. `++`
|
||||
6. `==` `!=` `<` `<=` `>` `>=`
|
||||
7. `&&`
|
||||
8. `||`
|
||||
9. `&`
|
||||
10. `//`
|
||||
11. `default`
|
||||
|
||||
同じ優先順位の二項演算子は左結合である。
|
||||
`default` は右結合である。
|
||||
|
||||
## Arithmetic operators
|
||||
|
||||
`+` `-` `*` `/` は具体的な `Int` / `Float` に対する四則演算である。
|
||||
詳しくは [Arithmetic Expression](./expression/arithmetic.md) を参照する。
|
||||
|
||||
## Array concat operator
|
||||
|
||||
`++` は concrete array 同士を連結する演算子である。
|
||||
要素は変換されず、左辺の要素の後に右辺の要素が並ぶ。
|
||||
|
||||
```dcdl
|
||||
["read", "write"] ++ ["admin"]
|
||||
```
|
||||
|
||||
## Logical and comparison operators
|
||||
|
||||
`!` `&&` `||` は concrete `Bool` に対する論理演算である。
|
||||
`&&` と `||` は短絡評価される。
|
||||
|
||||
`==` `!=` は concrete scalar value を比較する。
|
||||
`<` `<=` `>` `>=` は concrete numeric value を比較する。
|
||||
詳しくは [Logical and Comparison Expressions](./expression/logical-and-comparison.md) を参照する。
|
||||
|
||||
## `&`: 制約合成
|
||||
|
||||
@@ -110,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,22 +105,23 @@ import
|
||||
default
|
||||
true
|
||||
false
|
||||
rec
|
||||
```
|
||||
|
||||
`rec` の扱いは未確定である。
|
||||
|
||||
## 演算子
|
||||
|
||||
主要な演算子は以下である。
|
||||
|
||||
```text
|
||||
& 制約合成
|
||||
// patch 合成
|
||||
default fallback 指定
|
||||
=> 関数
|
||||
. フィールド参照 / ドットパス定義
|
||||
+ - * / 四則演算
|
||||
++ 配列結合
|
||||
! && || 論理演算
|
||||
== != < <= > >= 比較式
|
||||
& 制約合成
|
||||
// patch 合成
|
||||
default fallback 指定
|
||||
=> 関数
|
||||
. フィールド参照 / ドットパス定義
|
||||
... 配列の要素制約
|
||||
```
|
||||
|
||||
演算子の優先順位は未確定である。
|
||||
詳細は [合成演算子](./operators.md) で定義する。
|
||||
演算子の優先順位は [合成演算子](./operators.md) で定義する。
|
||||
|
||||
@@ -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,11 @@ name = String;
|
||||
retry = Int default 3;
|
||||
ratio = Float;
|
||||
enable = Bool default true;
|
||||
tags = [...String];
|
||||
```
|
||||
|
||||
現在の primitive type は `String`、`Int`、`Float`、`Bool` である。
|
||||
配列は primitive type ではなく、必須の要素制約を持つ `[...T]` で表現する。
|
||||
各型の個別仕様へのリンクは [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,175 @@
|
||||
@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 |
|
||||
ArrayConstraint |
|
||||
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 }
|
||||
ArrayConstraint { LBracket Ellipsis 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 { "." }
|
||||
Ellipsis { "..." }
|
||||
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.
|
||||
@@ -74,3 +74,111 @@ base // {
|
||||
body: (literal (string)))
|
||||
(match_arm
|
||||
body: (literal (string))))))))
|
||||
|
||||
==================
|
||||
Arithmetic
|
||||
==================
|
||||
{
|
||||
value = 1 + 2 * 3;
|
||||
grouped = (1 + 2) / -3;
|
||||
}
|
||||
---
|
||||
|
||||
(source_file
|
||||
(object
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (binary_expression
|
||||
left: (literal (integer))
|
||||
right: (binary_expression
|
||||
left: (literal (integer))
|
||||
right: (literal (integer)))))
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (binary_expression
|
||||
left: (parenthesized_expression
|
||||
(binary_expression
|
||||
left: (literal (integer))
|
||||
right: (literal (integer))))
|
||||
right: (unary_expression
|
||||
operand: (literal (integer)))))))
|
||||
|
||||
==================
|
||||
Logical and comparison
|
||||
==================
|
||||
{
|
||||
enabled = env == "prod" && replicas > 1;
|
||||
disabled = !enabled || false;
|
||||
}
|
||||
---
|
||||
|
||||
(source_file
|
||||
(object
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (binary_expression
|
||||
left: (binary_expression
|
||||
left: (identifier)
|
||||
right: (literal (string)))
|
||||
right: (binary_expression
|
||||
left: (identifier)
|
||||
right: (literal (integer)))))
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (binary_expression
|
||||
left: (unary_expression
|
||||
operand: (identifier))
|
||||
right: (literal (boolean))))))
|
||||
|
||||
==================
|
||||
Array concat
|
||||
==================
|
||||
{
|
||||
roles = ["read"] ++ ["write", "admin"];
|
||||
ports = [8000 + 80] ++ [9443];
|
||||
}
|
||||
---
|
||||
|
||||
(source_file
|
||||
(object
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (binary_expression
|
||||
left: (array
|
||||
(literal (string)))
|
||||
right: (array
|
||||
(literal (string))
|
||||
(literal (string)))))
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (binary_expression
|
||||
left: (array
|
||||
(binary_expression
|
||||
left: (literal (integer))
|
||||
right: (literal (integer))))
|
||||
right: (array
|
||||
(literal (integer)))))))
|
||||
|
||||
==================
|
||||
Array constraints
|
||||
==================
|
||||
{
|
||||
tags = [...String];
|
||||
ports = [...(Int & >= 1),];
|
||||
}
|
||||
---
|
||||
|
||||
(source_file
|
||||
(object
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (array_constraint
|
||||
element: (identifier)))
|
||||
(field_definition
|
||||
path: (field_path (identifier))
|
||||
value: (array_constraint
|
||||
element: (parenthesized_expression
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (comparison_constraint
|
||||
value: (integer))))))))
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
// Tree-sitter implementation of the canonical EBNF grammar in
|
||||
// doc/manual/souce/language/grammar.md.
|
||||
|
||||
const PREC = {
|
||||
DEFAULT: 1,
|
||||
PATCH: 2,
|
||||
AND: 3,
|
||||
CALL: 7,
|
||||
PATH: 8,
|
||||
COMPOSE: 3,
|
||||
OR: 4,
|
||||
LOGICAL_AND: 5,
|
||||
COMPARE: 6,
|
||||
CONCAT: 7,
|
||||
ADD: 8,
|
||||
MUL: 9,
|
||||
UNARY: 10,
|
||||
CALL: 11,
|
||||
PATH: 12,
|
||||
};
|
||||
|
||||
function commaSep(rule) {
|
||||
@@ -44,6 +54,7 @@ module.exports = grammar({
|
||||
$.regex_literal,
|
||||
$.comparison_constraint,
|
||||
$.object,
|
||||
$.array_constraint,
|
||||
$.array,
|
||||
$.let_expression,
|
||||
$.function_expression,
|
||||
@@ -52,6 +63,7 @@ module.exports = grammar({
|
||||
$.parenthesized_expression,
|
||||
$.call_expression,
|
||||
$.path_expression,
|
||||
$.unary_expression,
|
||||
$.binary_expression,
|
||||
$.default_expression,
|
||||
),
|
||||
@@ -105,6 +117,14 @@ module.exports = grammar({
|
||||
']',
|
||||
),
|
||||
|
||||
array_constraint: $ => seq(
|
||||
'[',
|
||||
'...',
|
||||
field('element', $._expression),
|
||||
optional(','),
|
||||
']',
|
||||
),
|
||||
|
||||
let_expression: $ => seq(
|
||||
'let',
|
||||
repeat(seq($.field_definition, ';')),
|
||||
@@ -159,13 +179,48 @@ module.exports = grammar({
|
||||
field('field', $.identifier),
|
||||
)),
|
||||
|
||||
comparison_constraint: $ => prec(6, seq(
|
||||
comparison_constraint: $ => prec.right(PREC.UNARY + 1, seq(
|
||||
field('operator', choice('>', '>=', '<', '<=')),
|
||||
field('value', choice($.integer, $.float)),
|
||||
field('value', $._expression),
|
||||
)),
|
||||
|
||||
unary_expression: $ => prec(PREC.UNARY, seq(
|
||||
field('operator', choice('-', '!')),
|
||||
field('operand', $._expression),
|
||||
)),
|
||||
|
||||
binary_expression: $ => choice(
|
||||
prec.left(PREC.AND, seq(
|
||||
prec.left(PREC.OR, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', token(prec(2, '||'))),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.LOGICAL_AND, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', token(prec(2, '&&'))),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.COMPARE, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', choice('==', '!=', '>', '>=', '<', '<=')),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.CONCAT, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', token(prec(2, '++'))),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.ADD, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', choice('+', '-')),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.MUL, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', choice('*', '/')),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
prec.left(PREC.COMPOSE, seq(
|
||||
field('left', $._expression),
|
||||
field('operator', '&'),
|
||||
field('right', $._expression),
|
||||
|
||||
@@ -17,6 +17,17 @@
|
||||
[
|
||||
"&"
|
||||
"//"
|
||||
"+"
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"++"
|
||||
"..."
|
||||
"&&"
|
||||
"||"
|
||||
"!"
|
||||
"=="
|
||||
"!="
|
||||
"=>"
|
||||
"="
|
||||
">"
|
||||
|
||||
+340
-8
@@ -95,6 +95,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "object"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "array_constraint"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "array"
|
||||
@@ -127,6 +131,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "path_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "unary_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "binary_expression"
|
||||
@@ -423,6 +431,43 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"array_constraint": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "..."
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "element",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
},
|
||||
"let_expression": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
@@ -712,7 +757,7 @@
|
||||
},
|
||||
"call_expression": {
|
||||
"type": "PREC_LEFT",
|
||||
"value": 7,
|
||||
"value": 11,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
@@ -782,7 +827,7 @@
|
||||
},
|
||||
"path_expression": {
|
||||
"type": "PREC_LEFT",
|
||||
"value": 8,
|
||||
"value": 12,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
@@ -810,8 +855,8 @@
|
||||
}
|
||||
},
|
||||
"comparison_constraint": {
|
||||
"type": "PREC",
|
||||
"value": 6,
|
||||
"type": "PREC_RIGHT",
|
||||
"value": 11,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
@@ -843,19 +888,44 @@
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "value",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"unary_expression": {
|
||||
"type": "PREC",
|
||||
"value": 10,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "integer"
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "float"
|
||||
"type": "STRING",
|
||||
"value": "!"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operand",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -863,6 +933,268 @@
|
||||
"binary_expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 4,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "||"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 5,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "&&"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 6,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "=="
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "!="
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ">"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ">="
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "<"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "<="
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 7,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "STRING",
|
||||
"value": "++"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 8,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 9,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "left",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "operator",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "/"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "right",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 3,
|
||||
|
||||
+468
-2
@@ -11,6 +11,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -66,10 +70,94 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"element": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "comparison_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "default_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "import_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "let_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "match_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "parenthesized_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "path_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true,
|
||||
@@ -82,6 +170,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -137,6 +229,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -144,13 +240,65 @@
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "!=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "&",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "&&",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "*",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "+",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "++",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "-",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "/",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "//",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "<",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "<=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "==",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ">",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ">=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "||",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -162,6 +310,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -217,6 +369,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -239,6 +395,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -294,6 +454,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -306,6 +470,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -361,6 +529,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -396,11 +568,71 @@
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "float",
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "comparison_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "default_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "import_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "let_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "match_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "parenthesized_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "path_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
@@ -419,6 +651,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -474,6 +710,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -485,6 +725,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -540,6 +784,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -567,6 +815,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -622,6 +874,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -654,6 +910,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -709,6 +969,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -752,6 +1016,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -807,6 +1075,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -861,6 +1133,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -916,6 +1192,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -931,6 +1211,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -986,6 +1270,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1003,6 +1291,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -1058,6 +1350,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1100,6 +1396,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -1155,6 +1455,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1182,6 +1486,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -1237,6 +1545,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1263,6 +1575,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -1318,6 +1634,10 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1335,6 +1655,10 @@
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
@@ -1394,14 +1718,124 @@
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"operand": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "array_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "comparison_constraint",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "default_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "import_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "let_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "match_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "parenthesized_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "path_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "regex_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"operator": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "!",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "-",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "!",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "!=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "&",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "&&",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "(",
|
||||
"named": false
|
||||
@@ -1410,14 +1844,38 @@
|
||||
"type": ")",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "*",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "+",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "++",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "-",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ".",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "...",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "/",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "//",
|
||||
"named": false
|
||||
@@ -1442,6 +1900,10 @@
|
||||
"type": "=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "==",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "=>",
|
||||
"named": false
|
||||
@@ -1522,6 +1984,10 @@
|
||||
"type": "{",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "||",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "}",
|
||||
"named": false
|
||||
|
||||
Generated
+8634
-2846
File diff suppressed because it is too large
Load Diff
@@ -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`.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
workers = 2 + 2;
|
||||
memory_gib = 1.5 * 4;
|
||||
port = 9000 + 443;
|
||||
timeout_seconds = 30 / 2;
|
||||
negative_offset = -3;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
base_roles = ["read", "write"];
|
||||
extra_roles = ["admin"];
|
||||
roles = ["read", "write"] ++ ["admin"];
|
||||
ports = [8000 + 80] ++ [9000 + 443];
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
let
|
||||
Service = {
|
||||
name = String;
|
||||
enabled = Bool default true;
|
||||
};
|
||||
Services = [...Service];
|
||||
in
|
||||
Services & [
|
||||
{ name = "api"; },
|
||||
{ name = "worker"; enabled = false; },
|
||||
]
|
||||
@@ -0,0 +1,11 @@
|
||||
let
|
||||
env = "prod";
|
||||
replicas = 3;
|
||||
in
|
||||
{
|
||||
is_prod = env == "prod";
|
||||
scaled = replicas > 1;
|
||||
enabled = env == "prod" && replicas > 1;
|
||||
disabled = !(env == "prod" && replicas > 1);
|
||||
safe = env != "dev" || replicas >= 1;
|
||||
}
|
||||
@@ -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,74 @@
|
||||
# decodal-codemirror
|
||||
|
||||
CodeMirror 6 language support for Decodal.
|
||||
|
||||
This package provides the Lezer parser metadata, highlighting tags, indentation rules, block folding, and formatter command used by the Decodal Web playground.
|
||||
It does not include the Decodal runtime 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.
|
||||
|
||||
## Formatting
|
||||
|
||||
The formatter is exposed as a separate subpath so plain syntax highlighting does not force callers to initialize WebAssembly.
|
||||
|
||||
```js
|
||||
import {
|
||||
formatDecodal,
|
||||
formatDecodalCommand,
|
||||
initDecodalFormatter,
|
||||
} from 'decodal-codemirror/format';
|
||||
import formatterWasm from 'decodal-codemirror/wasm/decodal_language_tools_bg.wasm?url';
|
||||
|
||||
await initDecodalFormatter(formatterWasm);
|
||||
|
||||
const result = formatDecodal('Server={port=Int default 8080;};');
|
||||
if (result.ok) console.log(result.source);
|
||||
|
||||
formatDecodalCommand(view);
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "@hare/decodal-codemirror",
|
||||
"version": "0.1.5",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": "./src/mod.ts",
|
||||
"./format": "./src/format.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@codemirror/language": "npm:@codemirror/language@^6.12.4",
|
||||
"@codemirror/view": "npm:@codemirror/view@^6.43.6",
|
||||
"@lezer/highlight": "npm:@lezer/highlight@^1.2.3",
|
||||
"@lezer/lr": "npm:@lezer/lr@^1.4.10"
|
||||
},
|
||||
"publish": {
|
||||
"include": [
|
||||
"README.md",
|
||||
"src/mod.ts",
|
||||
"src/format.ts",
|
||||
"src/decodal.js",
|
||||
"src/decodal.d.ts",
|
||||
"src/decodal.js.d.ts",
|
||||
"src/format.js",
|
||||
"src/format.d.ts",
|
||||
"src/format.js.d.ts",
|
||||
"src/decodal-parser-jsr.js",
|
||||
"src/decodal-parser.js",
|
||||
"src/decodal-parser.terms.js",
|
||||
"wasm/decodal_language_tools.js",
|
||||
"wasm/decodal_language_tools.d.ts",
|
||||
"wasm/decodal_language_tools_bg.wasm",
|
||||
"wasm/decodal_language_tools_bg.wasm.d.ts",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
{
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.5",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.5",
|
||||
"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"
|
||||
},
|
||||
"./format": {
|
||||
"types": "./src/format.d.ts",
|
||||
"import": "./src/format.js"
|
||||
},
|
||||
"./parser": "./src/decodal-parser.js",
|
||||
"./terms": "./src/decodal-parser.terms.js",
|
||||
"./wasm/decodal_language_tools_bg.wasm": "./wasm/decodal_language_tools_bg.wasm"
|
||||
},
|
||||
"types": "./src/decodal.d.ts",
|
||||
"files": [
|
||||
"README.md",
|
||||
"src/",
|
||||
"wasm/decodal_language_tools.js",
|
||||
"wasm/decodal_language_tools.d.ts",
|
||||
"wasm/decodal_language_tools_bg.wasm",
|
||||
"wasm/decodal_language_tools_bg.wasm.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"decodal",
|
||||
"codemirror",
|
||||
"lezer"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@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 ed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[$]$^$e$f$g$k$l$m$n$o$p$q#VZORTVW]kr!P!T!U!V!X!Y!Z![!]!^!_!h!m!n!q!t#c#l#q#x#{#|$P$T$W$X$Y$Z$[$]$^$e$f$g$k$l$m$n$o$p$q#VYORTVW]kr!P!T!U!V!X!Y!Z![!]!^!_!h!m!n!q!t#c#l#q#x#{#|$P$T$W$X$Y$Z$[$]$^$e$f$g$k$l$m$n$o$p$qRwUR{VQyVV#h!o#i#yQ#p!tV$R#|$T$WX#n!t#|$T$WR!Q[R!w!PQ!XaQ$Z$aR$k$iQkOR!akSmPoR!cmQ!eqR#^!eQ!itS#d!i#rR#r!uQvUR!lvQ!pyR#j!pQ#}#pR$U#}",
|
||||
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 ArrayConstraint LBracket Ellipsis Comma RBracket Array 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: 87,
|
||||
skippedNodes: [0,1],
|
||||
repeatNodeCount: 7,
|
||||
tokenData: "=c~R!PX^$Upq$Uqr$yrs%Wst&zvw'cxy'pyz'uz{'z{|(P|}(^}!O(c!O!P(h!P!Q({!Q![+c![!]+|!]!^,R!^!_,W!_!`,e!`!a,z!c!}-X!}#O-j#P#Q-o#R#S-t#T#W-X#W#X.X#X#Y-X#Y#Z1i#Z#]-X#]#^3y#^#`-X#`#a7]#a#b8p#b#h-X#h#i;Q#i#o-X#o#p<|#p#q=R#q#r=^#y#z$U$f$g$U#BY#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#T#X-X#X#Y<i#Y#o-X~<pSj~U~!Q![-X!c!}-X#R#S-X#T#o-X~=ROs~~=UP#p#q=X~=^O!l~~=cOu~",
|
||||
tokenizers: [0, 1],
|
||||
topRules: {"Source":[0,2]},
|
||||
tokenPrec: 2497
|
||||
})
|
||||
@@ -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: "8fQYQPOOO#nQPO'#CaOOQO'#Cr'#CrO$wQPO'#CyO&UQPO'#DOO&^QQO'#DXO&hQPO'#DYO&pQPO'#CqO$wQPO'#DeO&zQPO'#DjOOQO'#Cq'#CqOOQO'#Cp'#CpO'PQPO'#CoO$wQPO'#CoOOQO'#Cn'#CnO)iQPO'#CmO.[QPO'#ClO0`QPO'#CkOOQO'#Cj'#CjO2WQPO'#CiO3{QPO'#ChO5mQPO'#CgO7XQPO'#CfOOQO'#Ce'#CeO7cQPO'#C`O7hQPO'#C_OOQO'#D|'#D|QYQPOOO8{QPO'#D}O9QQPO,58{OOQO,59e,59eO9YQPO'#CaOOQO,59j,59jO9bQPO,59jO$wQPO,59nOOQO,59s,59sO9jQPO,59sO9rQPO'#EQO9wQPO'#D[O:PQPO,59tO:UQPO'#CqO:cQPO'#D`O:kQQO,59xO:pQPO,59xO:uQPO,59]O:zQPO,5:POOQO,5:U,5:UO;PQPO'#DlOOQO,59[,59[O;WQPO,59[OOQO,59Z,59ZO$wQPO,59YO$wQPO,59XO$wQPO,59WOOQO'#Dt'#DtO$wQPO,59VO$wQPO,59UO$wQPO,59TO$wQPO,59SO$wQPO,59RO$wQPO,59QO$wQPO,58zOOQO,58y,58yOOQO-E7z-E7zOOQO,5:i,5:iOOQO-E7{-E7{O;]QPO1G/UO;eQPO1G/UOOQO1G/U1G/UO;mQPO1G/YO;uQPO1G/_O;|QPO1G/_OOQO1G/_1G/_OOQO,5:l,5:lOOQO-E8O-E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!z!UR#T$X#Q^ORTVWkr!P!U!V!X!Y!Z![!]!^!_!h!m!n!q!t#c#l#q#x#{#|$P$T$W$X$Y$Z$[$]$^$e$f$g$k$l$m$n$o$p$qQ!S]R!y!T#V[ORTVW]kr!P!T!U!V!X!Y!Z![!]!^!_!h!m!n!q!t#c#l#q#x#{#|$P$T$W$X$Y$Z$[$]$^$e$f$g$k$l$m$n$o$p$q#VZORTVW]kr!P!T!U!V!X!Y!Z![!]!^!_!h!m!n!q!t#c#l#q#x#{#|$P$T$W$X$Y$Z$[$]$^$e$f$g$k$l$m$n$o$p$q#VYORTVW]kr!P!T!U!V!X!Y!Z![!]!^!_!h!m!n!q!t#c#l#q#x#{#|$P$T$W$X$Y$Z$[$]$^$e$f$g$k$l$m$n$o$p$qRwUR{VQyVV#h!o#i#yQ#p!tV$R#|$T$WX#n!t#|$T$WR!Q[R!w!PQ!XaQ$Z$aR$k$iQkOR!akSmPoR!cmQ!eqR#^!eQ!itS#d!i#rR#r!uQvUR!lvQ!pyR#j!pQ#}#pR$U#}",
|
||||
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 ArrayConstraint LBracket Ellipsis Comma RBracket Array 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: 87,
|
||||
skippedNodes: [0,1],
|
||||
repeatNodeCount: 7,
|
||||
tokenData: "=c~R!PX^$Upq$Uqr$yrs%Wst&zvw'cxy'pyz'uz{'z{|(P|}(^}!O(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ZUU~!Q![-X!c!}-X#R#S-X#T#[-X#[#]:m#]#o-X~:tS!Y~U~!Q![-X!c!}-X#R#S-X#T#o-X~;VUU~!Q![-X!c!}-X#R#S-X#T#f-X#f#g;i#g#o-X~;nUU~!Q![-X!c!}-X#R#S-X#T#i-X#i#j<Q#j#o-X~<VUU~!Q![-X!c!}-X#R#S-X#T#X-X#X#Y<i#Y#o-X~<pSj~U~!Q![-X!c!}-X#R#S-X#T#o-X~=ROs~~=UP#p#q=X~=^O!l~~=cOu~",
|
||||
tokenizers: [0, 1],
|
||||
topRules: {"Source":[0,2]},
|
||||
tokenPrec: 2497
|
||||
})
|
||||
@@ -0,0 +1,79 @@
|
||||
// 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,
|
||||
ArrayConstraint = 38,
|
||||
LBracket = 39,
|
||||
Ellipsis = 40,
|
||||
Comma = 41,
|
||||
RBracket = 42,
|
||||
Array = 43,
|
||||
LetExpression = 44,
|
||||
Let = 45,
|
||||
FieldDefinitionList = 46,
|
||||
In = 47,
|
||||
FunctionExpression = 48,
|
||||
LParen = 49,
|
||||
ParameterList = 50,
|
||||
Parameter = 51,
|
||||
Colon = 52,
|
||||
RParen = 53,
|
||||
Arrow = 54,
|
||||
MatchExpression = 55,
|
||||
Match = 56,
|
||||
MatchArm = 57,
|
||||
Pattern = 58,
|
||||
Underscore = 59,
|
||||
ImportExpression = 60,
|
||||
Import = 61,
|
||||
CallSuffix = 62,
|
||||
ArgumentList = 63,
|
||||
Bang = 64,
|
||||
Minus = 65,
|
||||
Star = 66,
|
||||
Slash = 67,
|
||||
Plus = 68,
|
||||
PlusPlus = 69,
|
||||
CompareOperator = 70,
|
||||
EqualEqual = 71,
|
||||
BangEqual = 72,
|
||||
AmpAmp = 73,
|
||||
PipePipe = 74,
|
||||
Amp = 75,
|
||||
SlashSlash = 76,
|
||||
Default = 77
|
||||
+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,75 @@
|
||||
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 Ellipsis 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,
|
||||
ArrayConstraint: 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('[', ']'),
|
||||
ArrayConstraint: 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;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import type { EditorView } from '@codemirror/view';
|
||||
|
||||
export interface FormatSuccess {
|
||||
ok: true;
|
||||
source: string;
|
||||
}
|
||||
|
||||
export interface FormatFailure {
|
||||
ok: false;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export type FormatResult = FormatSuccess | FormatFailure;
|
||||
|
||||
export declare function initDecodalFormatter(moduleOrPath?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module): Promise<void>;
|
||||
export declare function formatDecodal(source: string): FormatResult;
|
||||
export declare function formatDecodalCommand(view: EditorView): boolean;
|
||||
@@ -0,0 +1,28 @@
|
||||
import initLanguageTools, { formatSource } from '../wasm/decodal_language_tools.js';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
export async function initDecodalFormatter(moduleOrPath) {
|
||||
await initLanguageTools(moduleOrPath);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
export function formatDecodal(source) {
|
||||
if (!initialized) {
|
||||
return { ok: false, error: 'Decodal formatter is not initialized' };
|
||||
}
|
||||
return JSON.parse(formatSource(source));
|
||||
}
|
||||
|
||||
export function formatDecodalCommand(view) {
|
||||
const result = formatDecodal(view.state.doc.toString());
|
||||
if (!result.ok) return false;
|
||||
view.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: view.state.doc.length,
|
||||
insert: result.source,
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import type { EditorView } from '@codemirror/view';
|
||||
|
||||
export interface FormatSuccess {
|
||||
ok: true;
|
||||
source: string;
|
||||
}
|
||||
|
||||
export interface FormatFailure {
|
||||
ok: false;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export type FormatResult = FormatSuccess | FormatFailure;
|
||||
|
||||
export declare function initDecodalFormatter(moduleOrPath?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module): Promise<void>;
|
||||
export declare function formatDecodal(source: string): FormatResult;
|
||||
export declare function formatDecodalCommand(view: EditorView): boolean;
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Decodal source formatting helpers for CodeMirror integrations.
|
||||
*
|
||||
* The formatter is backed by WebAssembly generated from the internal Rust
|
||||
* `decodal-language-tools` crate. Call {@link initDecodalFormatter} once before
|
||||
* using {@link formatDecodal} or {@link formatDecodalCommand}.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import type { EditorView } from 'npm:@codemirror/view@^6.43.6';
|
||||
import initLanguageTools, { formatSource } from '../wasm/decodal_language_tools.js';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
/** Successful formatter result. */
|
||||
export interface FormatSuccess {
|
||||
/** Indicates that formatting succeeded. */
|
||||
ok: true;
|
||||
/** The formatted Decodal source text. */
|
||||
source: string;
|
||||
}
|
||||
|
||||
/** Failed formatter result. */
|
||||
export interface FormatFailure {
|
||||
/** Indicates that formatting failed. */
|
||||
ok: false;
|
||||
/** Human-readable formatter error. */
|
||||
error: string;
|
||||
}
|
||||
|
||||
/** Result returned by {@link formatDecodal}. */
|
||||
export type FormatResult = FormatSuccess | FormatFailure;
|
||||
|
||||
/**
|
||||
* Initialize the bundled Decodal formatter WebAssembly module.
|
||||
*
|
||||
* Bundlers such as Vite should pass the package wasm asset URL explicitly:
|
||||
*
|
||||
* ```ts
|
||||
* import wasmUrl from 'decodal-codemirror/wasm/decodal_language_tools_bg.wasm?url';
|
||||
* await initDecodalFormatter(wasmUrl);
|
||||
* ```
|
||||
*
|
||||
* @param moduleOrPath - Optional WebAssembly module, bytes, response, URL, or
|
||||
* request accepted by wasm-bindgen's generated initializer.
|
||||
*/
|
||||
export async function initDecodalFormatter(
|
||||
moduleOrPath?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module,
|
||||
): Promise<void> {
|
||||
await initLanguageTools(moduleOrPath);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a complete Decodal source document.
|
||||
*
|
||||
* @param source - Source text to format.
|
||||
* @returns Either formatted source text or an error message.
|
||||
*/
|
||||
export function formatDecodal(source: string): FormatResult {
|
||||
if (!initialized) {
|
||||
return { ok: false, error: 'Decodal formatter is not initialized' };
|
||||
}
|
||||
return JSON.parse(formatSource(source)) as FormatResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* CodeMirror command that formats the whole document in-place.
|
||||
*
|
||||
* @param view - The editor view whose document should be formatted.
|
||||
* @returns `true` when the document was formatted, otherwise `false`.
|
||||
*/
|
||||
export function formatDecodalCommand(view: EditorView): boolean {
|
||||
const result = formatDecodal(view.state.doc.toString());
|
||||
if (!result.ok) return false;
|
||||
view.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: view.state.doc.length,
|
||||
insert: result.source,
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* CodeMirror 6 language support for Decodal.
|
||||
*
|
||||
* This module exports the Decodal language extension, parser metadata, and the
|
||||
* bundled highlight style used by the official Decodal playground. Add
|
||||
* {@link decodal} to a CodeMirror extension set to enable highlighting,
|
||||
* indentation, and folding for Decodal documents.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
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 Ellipsis 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,
|
||||
ArrayConstraint: 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('[', ']'),
|
||||
ArrayConstraint: 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;
|
||||
};
|
||||
}
|
||||
|
||||
/** Decodal LR language definition for CodeMirror 6. */
|
||||
export const decodalLanguage: LRLanguage = LRLanguage.define({
|
||||
parser: parserWithMetadata,
|
||||
languageData: {
|
||||
commentTokens: { line: '#' },
|
||||
closeBrackets: { brackets: ['(', '[', '{', '"'] },
|
||||
},
|
||||
});
|
||||
|
||||
/** Default Decodal highlight style used by the playground. */
|
||||
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' },
|
||||
]);
|
||||
|
||||
/** Options for {@link decodal}. */
|
||||
export interface DecodalOptions {
|
||||
/** Include the bundled {@link decodalHighlightStyle}. Defaults to `true`. */
|
||||
highlight?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create CodeMirror language support for Decodal.
|
||||
*
|
||||
* @param options - Optional language support options.
|
||||
* @returns A CodeMirror extension bundle containing the Decodal language and,
|
||||
* unless disabled, the default highlight style.
|
||||
*/
|
||||
export function decodal(options: DecodalOptions = {}): LanguageSupport {
|
||||
const { highlight = true } = options;
|
||||
return new LanguageSupport(
|
||||
decodalLanguage,
|
||||
highlight ? [syntaxHighlighting(decodalHighlightStyle)] : [],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
# wasm-pack output is committed as part of decodal-codemirror.
|
||||
@@ -0,0 +1,38 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function formatSource(source: string): string;
|
||||
|
||||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||
|
||||
export interface InitOutput {
|
||||
readonly memory: WebAssembly.Memory;
|
||||
readonly formatSource: (a: number, b: 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;
|
||||
|
||||
/**
|
||||
* Instantiates the given `module`, which can either be bytes or
|
||||
* a precompiled `WebAssembly.Module`.
|
||||
*
|
||||
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {InitOutput}
|
||||
*/
|
||||
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
||||
|
||||
/**
|
||||
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
||||
* for everything else, calls `WebAssembly.instantiate` directly.
|
||||
*
|
||||
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {Promise<InitOutput>}
|
||||
*/
|
||||
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
||||
@@ -0,0 +1,209 @@
|
||||
/* @ts-self-types="./decodal_language_tools.d.ts" */
|
||||
|
||||
/**
|
||||
* @param {string} source
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatSource(source) {
|
||||
let deferred2_0;
|
||||
let deferred2_1;
|
||||
try {
|
||||
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ret = wasm.formatSource(ptr0, len0);
|
||||
deferred2_0 = ret[0];
|
||||
deferred2_1 = ret[1];
|
||||
return getStringFromWasm0(ret[0], ret[1]);
|
||||
} finally {
|
||||
wasm.__wbindgen_free(deferred2_0, deferred2_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,
|
||||
"./decodal_language_tools_bg.js": import0,
|
||||
};
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
return decodeText(ptr >>> 0, len);
|
||||
}
|
||||
|
||||
let cachedUint8ArrayMemory0 = null;
|
||||
function getUint8ArrayMemory0() {
|
||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8ArrayMemory0;
|
||||
}
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len, 1) >>> 0;
|
||||
|
||||
const mem = getUint8ArrayMemory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
||||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = cachedTextEncoder.encodeInto(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
||||
let numBytesDecoded = 0;
|
||||
function decodeText(ptr, len) {
|
||||
numBytesDecoded += len;
|
||||
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
||||
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
numBytesDecoded = len;
|
||||
}
|
||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
const cachedTextEncoder = new TextEncoder();
|
||||
|
||||
if (!('encodeInto' in cachedTextEncoder)) {
|
||||
cachedTextEncoder.encodeInto = function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
let wasmModule, wasmInstance, wasm;
|
||||
function __wbg_finalize_init(instance, module) {
|
||||
wasmInstance = instance;
|
||||
wasm = instance.exports;
|
||||
wasmModule = module;
|
||||
cachedUint8ArrayMemory0 = null;
|
||||
wasm.__wbindgen_start();
|
||||
return wasm;
|
||||
}
|
||||
|
||||
async function __wbg_load(module, imports) {
|
||||
if (typeof Response === 'function' && module instanceof Response) {
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||
try {
|
||||
return await WebAssembly.instantiateStreaming(module, imports);
|
||||
} catch (e) {
|
||||
const validResponse = module.ok && expectedResponseType(module.type);
|
||||
|
||||
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
||||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
||||
|
||||
} else { throw e; }
|
||||
}
|
||||
}
|
||||
|
||||
const bytes = await module.arrayBuffer();
|
||||
return await WebAssembly.instantiate(bytes, imports);
|
||||
} else {
|
||||
const instance = await WebAssembly.instantiate(module, imports);
|
||||
|
||||
if (instance instanceof WebAssembly.Instance) {
|
||||
return { instance, module };
|
||||
} else {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
function expectedResponseType(type) {
|
||||
switch (type) {
|
||||
case 'basic': case 'cors': case 'default': return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function initSync(module) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module !== undefined) {
|
||||
if (Object.getPrototypeOf(module) === Object.prototype) {
|
||||
({module} = module)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
const imports = __wbg_get_imports();
|
||||
if (!(module instanceof WebAssembly.Module)) {
|
||||
module = new WebAssembly.Module(module);
|
||||
}
|
||||
const instance = new WebAssembly.Instance(module, imports);
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
async function __wbg_init(module_or_path) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module_or_path !== undefined) {
|
||||
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
||||
({module_or_path} = module_or_path)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
if (module_or_path === undefined) {
|
||||
module_or_path = new URL('decodal_language_tools_bg.wasm', import.meta.url);
|
||||
}
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
||||
module_or_path = fetch(module_or_path);
|
||||
}
|
||||
|
||||
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
export { initSync, __wbg_init as default };
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export const memory: WebAssembly.Memory;
|
||||
export const formatSource: (a: number, b: 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 @@
|
||||
# wasm-pack output is committed for the browser runtime package.
|
||||
@@ -0,0 +1,36 @@
|
||||
# decodal-wasm
|
||||
|
||||
WebAssembly runtime package for Decodal.
|
||||
|
||||
This package exposes the Decodal evaluator to browsers and other JavaScript runtimes that can load WebAssembly modules.
|
||||
It is generated from the Rust crate in `crates/decodal-wasm` with `wasm-pack` and is used by the official playground.
|
||||
|
||||
Use `decodal-codemirror` separately when you need CodeMirror 6 language support.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install decodal-wasm
|
||||
```
|
||||
|
||||
JSR:
|
||||
|
||||
```sh
|
||||
deno add jsr:@hare/decodal-wasm
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import init, { evaluateProject } from 'decodal-wasm';
|
||||
|
||||
await init();
|
||||
|
||||
const result = evaluateProject('main.dcdl', JSON.stringify({
|
||||
'main.dcdl': 'Server = { port = Int default 8080; };',
|
||||
}));
|
||||
|
||||
console.log(JSON.parse(result));
|
||||
```
|
||||
|
||||
The exported functions return JSON strings so callers can handle diagnostics and successful results without depending on Rust data structures.
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export function evaluate(source: string): string;
|
||||
|
||||
export function evaluateProject(entry: string, files_json: string): string;
|
||||
|
||||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||
|
||||
export interface InitOutput {
|
||||
readonly memory: WebAssembly.Memory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Instantiates the given `module`, which can either be bytes or
|
||||
* a precompiled `WebAssembly.Module`.
|
||||
*
|
||||
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {InitOutput}
|
||||
*/
|
||||
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
||||
|
||||
/**
|
||||
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
||||
* for everything else, calls `WebAssembly.instantiate` directly.
|
||||
*
|
||||
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
||||
*
|
||||
* @returns {Promise<InitOutput>}
|
||||
*/
|
||||
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
||||
@@ -0,0 +1,231 @@
|
||||
/* @ts-self-types="./decodal_wasm.d.ts" */
|
||||
|
||||
/**
|
||||
* @param {string} source
|
||||
* @returns {string}
|
||||
*/
|
||||
export function evaluate(source) {
|
||||
let deferred2_0;
|
||||
let deferred2_1;
|
||||
try {
|
||||
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ret = wasm.evaluate(ptr0, len0);
|
||||
deferred2_0 = ret[0];
|
||||
deferred2_1 = ret[1];
|
||||
return getStringFromWasm0(ret[0], ret[1]);
|
||||
} finally {
|
||||
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} entry
|
||||
* @param {string} files_json
|
||||
* @returns {string}
|
||||
*/
|
||||
export function evaluateProject(entry, files_json) {
|
||||
let deferred3_0;
|
||||
let deferred3_1;
|
||||
try {
|
||||
const ptr0 = passStringToWasm0(entry, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passStringToWasm0(files_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
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_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,
|
||||
"./decodal_wasm_bg.js": import0,
|
||||
};
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
return decodeText(ptr >>> 0, len);
|
||||
}
|
||||
|
||||
let cachedUint8ArrayMemory0 = null;
|
||||
function getUint8ArrayMemory0() {
|
||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8ArrayMemory0;
|
||||
}
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len, 1) >>> 0;
|
||||
|
||||
const mem = getUint8ArrayMemory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
||||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = cachedTextEncoder.encodeInto(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
||||
let numBytesDecoded = 0;
|
||||
function decodeText(ptr, len) {
|
||||
numBytesDecoded += len;
|
||||
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
||||
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
numBytesDecoded = len;
|
||||
}
|
||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
const cachedTextEncoder = new TextEncoder();
|
||||
|
||||
if (!('encodeInto' in cachedTextEncoder)) {
|
||||
cachedTextEncoder.encodeInto = function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
let wasmModule, wasmInstance, wasm;
|
||||
function __wbg_finalize_init(instance, module) {
|
||||
wasmInstance = instance;
|
||||
wasm = instance.exports;
|
||||
wasmModule = module;
|
||||
cachedUint8ArrayMemory0 = null;
|
||||
wasm.__wbindgen_start();
|
||||
return wasm;
|
||||
}
|
||||
|
||||
async function __wbg_load(module, imports) {
|
||||
if (typeof Response === 'function' && module instanceof Response) {
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||
try {
|
||||
return await WebAssembly.instantiateStreaming(module, imports);
|
||||
} catch (e) {
|
||||
const validResponse = module.ok && expectedResponseType(module.type);
|
||||
|
||||
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
||||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
||||
|
||||
} else { throw e; }
|
||||
}
|
||||
}
|
||||
|
||||
const bytes = await module.arrayBuffer();
|
||||
return await WebAssembly.instantiate(bytes, imports);
|
||||
} else {
|
||||
const instance = await WebAssembly.instantiate(module, imports);
|
||||
|
||||
if (instance instanceof WebAssembly.Instance) {
|
||||
return { instance, module };
|
||||
} else {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
function expectedResponseType(type) {
|
||||
switch (type) {
|
||||
case 'basic': case 'cors': case 'default': return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function initSync(module) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module !== undefined) {
|
||||
if (Object.getPrototypeOf(module) === Object.prototype) {
|
||||
({module} = module)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
const imports = __wbg_get_imports();
|
||||
if (!(module instanceof WebAssembly.Module)) {
|
||||
module = new WebAssembly.Module(module);
|
||||
}
|
||||
const instance = new WebAssembly.Instance(module, imports);
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
async function __wbg_init(module_or_path) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module_or_path !== undefined) {
|
||||
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
||||
({module_or_path} = module_or_path)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
if (module_or_path === undefined) {
|
||||
module_or_path = new URL('decodal_wasm_bg.wasm', import.meta.url);
|
||||
}
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
||||
module_or_path = fetch(module_or_path);
|
||||
}
|
||||
|
||||
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
export { initSync, __wbg_init as default };
|
||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user