Compare commits
252
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8ec265c1c | ||
|
|
b7c68da6de | ||
|
|
8d0adb3bb9 | ||
|
|
76f5eccddf | ||
|
|
5539ebde61 | ||
|
|
ae25b0044b | ||
|
|
1a026f69cb | ||
|
|
c5c5e885bf | ||
|
|
a26c1c31fb | ||
|
|
d33763be2e | ||
|
|
b7cfa9fbe6 | ||
|
|
960cc40886 | ||
|
|
c9a3c4693c | ||
|
|
76b267a886 | ||
|
|
119f93cf79 | ||
|
|
4112dcac3b | ||
|
|
80ff10503a | ||
|
|
f2257a4e81 | ||
|
|
8703ac4254 | ||
|
|
70a1fa332b | ||
|
|
7b94969379 | ||
|
|
357a25a859 | ||
|
|
7af6416921 | ||
|
|
827b674be2 | ||
|
|
87bc8a0d69 | ||
|
|
aba8badd90 | ||
|
|
224b367ff1 | ||
|
|
9da4a50ef5 | ||
|
|
2fcb8c3831 | ||
|
|
702af9da3b | ||
|
|
7688599504 | ||
|
|
70e6eb6276 | ||
|
|
197afbfb35 | ||
|
|
0878b9f0b9 | ||
|
|
b28591f9e6 | ||
|
|
0c8dc53617 | ||
|
|
cc7bc49efe | ||
|
|
959f786dc8 | ||
|
|
da819c22f6 | ||
|
|
d408d01002 | ||
|
|
856c9dfdfa | ||
|
|
812fa5d540 | ||
|
|
b55b35623b | ||
|
|
ff38c809e7 | ||
|
|
64418cb52d | ||
|
|
674b809586 | ||
|
|
6b14ab0308 | ||
|
|
b86b4831ce | ||
|
|
949135bd3b | ||
|
|
c30d686eb5 | ||
|
|
47e62f96d9 | ||
|
|
b856450cc1 | ||
|
|
3ed17e007f | ||
|
|
bffc9f073b | ||
|
|
318480f0b5 | ||
|
|
1a469689a7 | ||
|
|
6d7beb20ca | ||
|
|
5f7dcc859c | ||
|
|
7febf84cd8 | ||
|
|
93eb467814 | ||
|
|
0e27344012 | ||
|
|
8f820bfb50 | ||
|
|
0031fb7152 | ||
|
|
28a7658ce7 | ||
|
|
67b60a9e4f | ||
|
|
16bca21981 | ||
|
|
349f9ba59e | ||
|
|
3620f0432a | ||
|
|
69e5ab2a5e | ||
|
|
bcefabe2d2 | ||
|
|
551f14f81e | ||
|
|
a5ccd9651a | ||
|
|
9d051c68e9 | ||
|
|
fd7455c71e | ||
|
|
1e191cf3c8 | ||
|
|
6412daa514 | ||
|
|
1b4c925f9f | ||
|
|
bfd768a162 | ||
|
|
ffe868e0cd | ||
|
|
8343740b11 | ||
|
|
4e98257438 | ||
|
|
95ae7b8d52 | ||
|
|
e30722dde3 | ||
|
|
eb84103ed6 | ||
|
|
49a3186d26 | ||
|
|
670835a5e7 | ||
|
|
2b43e0c004 | ||
|
|
11e408cc17 | ||
|
|
5e8946a126 | ||
|
|
6b314dabf4 | ||
|
|
c5d8c12c14 | ||
|
|
d1330500b2 | ||
|
|
a88ff4c8dd | ||
|
|
5648c1da61 | ||
|
|
de1784f914 | ||
|
|
aa948a50cb | ||
|
|
f9f86fcc67 | ||
|
|
907d9d7f9d | ||
|
|
1d4473906f | ||
|
|
7fe91b8e36 | ||
|
|
94e113d227 | ||
|
|
c566ac9a54 | ||
|
|
5fa3e77b8f | ||
|
|
e270ec727e | ||
|
|
e89f5e805c | ||
|
|
dd647afd59 | ||
|
|
46c6f5ffdd | ||
|
|
212d5d69b5 | ||
|
|
a893f9a12d | ||
|
|
77f35e0517 | ||
|
|
1bcbca00b8 | ||
|
|
c7529412f4 | ||
|
|
9b632fcc0e | ||
|
|
4742fbebf7 | ||
|
|
82d748224f | ||
|
|
16f169cdb0 | ||
|
|
2a95ad4eb0 | ||
|
|
33fae13c8a | ||
|
|
23cf00975d | ||
|
|
2c67d4e316 | ||
|
|
bfaaa4006b | ||
|
|
50c98cf5f7 | ||
|
|
020eebdaba | ||
|
|
675e357297 | ||
|
|
6a0011c009 | ||
|
|
95f253c0ce | ||
|
|
b802c51369 | ||
|
|
0bd8bc2f03 | ||
|
|
13480b2c54 | ||
|
|
c9030809fd | ||
|
|
60e5995dc6 | ||
|
|
c621a1bb8d | ||
|
|
58a79ad2ef | ||
|
|
490509cb14 | ||
|
|
bdca96212c | ||
|
|
e3d885e22d | ||
|
|
6917d36ac4 | ||
|
|
90de040ae8 | ||
|
|
9d024b7e25 | ||
|
|
50b05b6def | ||
|
|
2c426c78c6 | ||
|
|
47b179b782 | ||
|
|
5174cc34ee | ||
|
|
b188ef0eb2 | ||
|
|
3619f0e7dc | ||
|
|
ced2d47977 | ||
|
|
a6e52b0191 | ||
|
|
32c411ba78 | ||
|
|
1a80fe074b | ||
|
|
cbd060149d | ||
|
|
e6bf1e0d2c | ||
|
|
0c6723e967 | ||
|
|
b22c0e8527 | ||
|
|
6346ffc771 | ||
|
|
efe32d8e5f | ||
|
|
c6b9588f4d | ||
|
|
216c61228c | ||
|
|
3aba4a359b | ||
|
|
fa2c0b2658 | ||
|
|
0bb7146d13 | ||
|
|
3c5b030bdd | ||
|
|
6c7692208d | ||
|
|
8c89f9ff65 | ||
|
|
f9c5fb4ec8 | ||
|
|
527e450f9e | ||
|
|
459c4b1ee0 | ||
|
|
933f102680 | ||
|
|
6fbc2a086e | ||
|
|
80e17ffafb | ||
|
|
25f4b5470d | ||
|
|
cdb34984db | ||
|
|
9b04a17fdd | ||
|
|
626990216c | ||
|
|
78cac259f2 | ||
|
|
5912032dff | ||
|
|
00e10d1097 | ||
|
|
50fa660392 | ||
|
|
192769c8ad | ||
|
|
5920a9f236 | ||
|
|
d8d3b327dd | ||
|
|
5c732bb8d1 | ||
|
|
01532baf12 | ||
|
|
03f9794671 | ||
|
|
fd48d6c9c6 | ||
|
|
ef7ccc5aed | ||
|
|
23f726fd41 | ||
|
|
a6ad375c58 | ||
|
|
e4eeb20a2c | ||
|
|
5bdcd40edb | ||
|
|
c1cb9bd7bf | ||
|
|
e416af3403 | ||
|
|
3b0a450895 | ||
|
|
8cd16f4c4f | ||
|
|
2a833c6cab | ||
|
|
950dded614 | ||
|
|
43b6e95b12 | ||
|
|
73d37b9f35 | ||
|
|
d3c1be859d | ||
|
|
e97b3cac8f | ||
|
|
380755bf83 | ||
|
|
e063d4c685 | ||
|
|
28d4d784f2 | ||
|
|
bb9ad547a3 | ||
|
|
6f7f11719d | ||
|
|
81d0286226 | ||
|
|
22b1b377f3 | ||
|
|
dfa5487031 | ||
|
|
2fb38b6974 | ||
|
|
476d984d4a | ||
|
|
d3b6e88b14 | ||
|
|
5916daaada | ||
|
|
e6c030e8c8 | ||
|
|
4e18f4530f | ||
|
|
460d296759 | ||
|
|
5a475f3b8a | ||
|
|
0c2746eefc | ||
|
|
f69c53d3fc | ||
|
|
dff77a8c01 | ||
|
|
1b1d38cdba | ||
|
|
3e25bf0456 | ||
|
|
910657c755 | ||
|
|
020dd3b76b | ||
|
|
0bf32b16cd | ||
|
|
65f4c5278d | ||
|
|
bbcc639331 | ||
|
|
ed4a505a6a | ||
|
|
0e6c73e85c | ||
|
|
205e2d9fd3 | ||
|
|
630528a843 | ||
|
|
39b15d4207 | ||
|
|
91bee0c4fc | ||
|
|
8b409f4ccf | ||
|
|
c7ada72029 | ||
|
|
bd066e05d1 | ||
|
|
093c281ea9 | ||
|
|
60bc1d2510 | ||
|
|
6f6c32b646 | ||
|
|
2d56cf1212 | ||
|
|
aa5640175f | ||
|
|
f98b9d7514 | ||
|
|
dc49cddc20 | ||
|
|
a6fb70eebf | ||
|
|
c51ff01ce8 | ||
|
|
cba78c2ac9 | ||
|
|
81061f26a5 | ||
|
|
3342893aab | ||
|
|
580c3297cb | ||
|
|
5eeaf8c35d | ||
|
|
a9fdfe4100 | ||
|
|
c6e34bbc70 | ||
|
|
27c6eb74c3 | ||
|
|
2ccec652da |
@@ -1,56 +0,0 @@
|
|||||||
name: Release Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
tag:
|
|
||||||
description: "Release tag to upload to (e.g. 0.1.0)"
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build (${{ matrix.os }})
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [windows-latest, ubuntu-latest, macos-latest]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
|
||||||
|
|
||||||
- name: Build release binary
|
|
||||||
run: cargo build --release
|
|
||||||
|
|
||||||
# --- Get release tag ---
|
|
||||||
- name: Get release tag
|
|
||||||
id: get_tag
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
TAG="${{ inputs.tag }}"
|
|
||||||
|
|
||||||
if [ "${{ github.event_name }}" = "release" ]; then
|
|
||||||
TAG="${{ github.event.release.tag_name }}"
|
|
||||||
elif [ -z "$TAG" ]; then
|
|
||||||
TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Upload to GitHub Release
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
tag_name: ${{ steps.get_tag.outputs.tag }}
|
|
||||||
files: |
|
|
||||||
target/release/mist*
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
+3
-2
@@ -26,5 +26,6 @@ target
|
|||||||
|
|
||||||
/target
|
/target
|
||||||
|
|
||||||
/test/build
|
**/build
|
||||||
/test/output.json
|
|
||||||
|
.mist/
|
||||||
|
|||||||
Generated
+837
-10
@@ -2,6 +2,40 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-trait"
|
||||||
|
version = "0.1.89"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "auto_impl"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ffdcb70bdbc4d478427380519163274ac86e52916e10f0a8889adf0f96d3fee7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block-buffer"
|
name = "block-buffer"
|
||||||
version = "0.10.4"
|
version = "0.10.4"
|
||||||
@@ -11,6 +45,45 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "1.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "camino"
|
||||||
|
version = "1.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cargo-platform"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd0061da739915fae12ea00e16397555ed4371a6bb285431aab930f61b0aa4ba"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cargo_metadata"
|
||||||
|
version = "0.23.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef987d17b0a113becdd19d3d0022d04d7ef41f9efe4f3fb63ac44ba61df3ade9"
|
||||||
|
dependencies = [
|
||||||
|
"camino",
|
||||||
|
"cargo-platform",
|
||||||
|
"semver",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.4"
|
version = "1.0.4"
|
||||||
@@ -26,6 +99,12 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@@ -36,6 +115,33 @@ dependencies = [
|
|||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dashmap"
|
||||||
|
version = "5.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"hashbrown",
|
||||||
|
"lock_api",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dashmap"
|
||||||
|
version = "6.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6361d5c062261c78a176addb82d4c821ae42bed6089de0e12603cd25de2059c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-utils",
|
||||||
|
"hashbrown",
|
||||||
|
"lock_api",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
@@ -46,6 +152,112 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "displaydoc"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "form_urlencoded"
|
||||||
|
version = "1.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
|
||||||
|
dependencies = [
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-channel"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-core"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-sink"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-task"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-util"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
|
"pin-project-lite",
|
||||||
|
"slab",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "generic-array"
|
name = "generic-array"
|
||||||
version = "0.14.7"
|
version = "0.14.7"
|
||||||
@@ -56,6 +268,121 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "httparse"
|
||||||
|
version = "1.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_collections"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"potential_utf",
|
||||||
|
"utf8_iter",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_locale_core"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"litemap",
|
||||||
|
"tinystr",
|
||||||
|
"writeable",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_normalizer"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4"
|
||||||
|
dependencies = [
|
||||||
|
"icu_collections",
|
||||||
|
"icu_normalizer_data",
|
||||||
|
"icu_properties",
|
||||||
|
"icu_provider",
|
||||||
|
"smallvec",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_normalizer_data"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_properties"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de"
|
||||||
|
dependencies = [
|
||||||
|
"icu_collections",
|
||||||
|
"icu_locale_core",
|
||||||
|
"icu_properties_data",
|
||||||
|
"icu_provider",
|
||||||
|
"zerotrie",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_properties_data"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_provider"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"icu_locale_core",
|
||||||
|
"writeable",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerotrie",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
|
||||||
|
dependencies = [
|
||||||
|
"idna_adapter",
|
||||||
|
"smallvec",
|
||||||
|
"utf8_iter",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna_adapter"
|
||||||
|
version = "1.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
|
||||||
|
dependencies = [
|
||||||
|
"icu_normalizer",
|
||||||
|
"icu_properties",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
@@ -64,9 +391,37 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.185"
|
version = "0.2.186"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f"
|
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "litemap"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
|
||||||
|
dependencies = [
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lsp-types"
|
||||||
|
version = "0.94.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c66bfd44a06ae10647fe3f8214762e9369fd4248df1350924b4ef9e770a85ea1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
@@ -75,17 +430,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mist"
|
name = "mio"
|
||||||
version = "0.0.1-alpha0"
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parser",
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mist-analyzer"
|
||||||
|
version = "0.0.2"
|
||||||
|
dependencies = [
|
||||||
|
"dashmap 6.2.1",
|
||||||
|
"mist-codegen",
|
||||||
|
"mist-parser",
|
||||||
|
"tokio",
|
||||||
|
"tower-lsp",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mist-codegen"
|
||||||
|
version = "0.1.1"
|
||||||
|
dependencies = [
|
||||||
|
"mist-parser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mist-lang"
|
||||||
|
version = "0.0.4-alpha0"
|
||||||
|
dependencies = [
|
||||||
|
"cargo_metadata",
|
||||||
|
"mist-analyzer",
|
||||||
|
"mist-codegen",
|
||||||
|
"mist-parser",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parser"
|
name = "mist-parser"
|
||||||
version = "0.1.0"
|
version = "0.1.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pest",
|
"pest",
|
||||||
"pest_derive",
|
"pest_derive",
|
||||||
@@ -93,6 +480,41 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.21.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "percent-encoding"
|
||||||
|
version = "2.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pest"
|
name = "pest"
|
||||||
version = "2.8.6"
|
version = "2.8.6"
|
||||||
@@ -136,6 +558,41 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project"
|
||||||
|
version = "1.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924"
|
||||||
|
dependencies = [
|
||||||
|
"pin-project-internal",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-internal"
|
||||||
|
version = "1.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-lite"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "potential_utf"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564"
|
||||||
|
dependencies = [
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.106"
|
version = "1.0.106"
|
||||||
@@ -154,6 +611,31 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.5.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.11.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.228"
|
version = "1.0.228"
|
||||||
@@ -197,6 +679,17 @@ dependencies = [
|
|||||||
"zmij",
|
"zmij",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_repr"
|
||||||
|
version = "0.1.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.9"
|
version = "0.10.9"
|
||||||
@@ -208,6 +701,44 @@ dependencies = [
|
|||||||
"digest",
|
"digest",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
|
||||||
|
dependencies = [
|
||||||
|
"errno",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slab"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.15.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "socket2"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stable_deref_trait"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.117"
|
version = "2.0.117"
|
||||||
@@ -220,10 +751,183 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "synstructure"
|
||||||
version = "1.19.0"
|
version = "0.13.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "2.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "2.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinystr"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.52.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"libc",
|
||||||
|
"mio",
|
||||||
|
"parking_lot",
|
||||||
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
|
"socket2",
|
||||||
|
"tokio-macros",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-macros"
|
||||||
|
version = "2.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-util"
|
||||||
|
version = "0.7.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-util",
|
||||||
|
"pin-project",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-layer"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-lsp"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d4ba052b54a6627628d9b3c34c176e7eda8359b7da9acd497b9f20998d118508"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"auto_impl",
|
||||||
|
"bytes",
|
||||||
|
"dashmap 5.5.3",
|
||||||
|
"futures",
|
||||||
|
"httparse",
|
||||||
|
"lsp-types",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
|
"tower",
|
||||||
|
"tower-lsp-macros",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-lsp-macros"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-service"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing"
|
||||||
|
version = "0.1.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
||||||
|
dependencies = [
|
||||||
|
"pin-project-lite",
|
||||||
|
"tracing-attributes",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-attributes"
|
||||||
|
version = "0.1.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-core"
|
||||||
|
version = "0.1.36"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ucd-trie"
|
name = "ucd-trie"
|
||||||
@@ -237,12 +941,135 @@ version = "1.0.24"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "url"
|
||||||
|
version = "2.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
||||||
|
dependencies = [
|
||||||
|
"form_urlencoded",
|
||||||
|
"idna",
|
||||||
|
"percent-encoding",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8_iter"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.1+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.61.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "writeable"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yoke"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca"
|
||||||
|
dependencies = [
|
||||||
|
"stable_deref_trait",
|
||||||
|
"yoke-derive",
|
||||||
|
"zerofrom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yoke-derive"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerofrom"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"
|
||||||
|
dependencies = [
|
||||||
|
"zerofrom-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerofrom-derive"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerotrie"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerovec"
|
||||||
|
version = "0.11.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239"
|
||||||
|
dependencies = [
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerovec-derive"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zmij"
|
name = "zmij"
|
||||||
version = "1.0.21"
|
version = "1.0.21"
|
||||||
|
|||||||
+47
-3
@@ -1,9 +1,53 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mist"
|
name = "mist-lang"
|
||||||
version = "0.0.1-alpha0"
|
version = "0.0.4-alpha0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
description = "The Mist programming language compiler"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
repository = "https://github.com/mist-go/mist"
|
||||||
|
readme = "README.md"
|
||||||
|
keywords = ["compiler", "language", "mist", "lang"]
|
||||||
|
categories = ["compilers", "command-line-interface", "development-tools", "development-tools::build-utils"]
|
||||||
|
default-run = "mist"
|
||||||
|
include = [
|
||||||
|
".mist/src/**",
|
||||||
|
"Cargo.toml",
|
||||||
|
"README.md",
|
||||||
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
mist-parser = { workspace = true }
|
||||||
|
mist-analyzer = { workspace = true }
|
||||||
|
mist-codegen = { workspace = true }
|
||||||
|
|
||||||
serde = { version = "1.0.228", features = ["serde_derive"] }
|
serde = { version = "1.0.228", features = ["serde_derive"] }
|
||||||
serde_json = "1.0.149"
|
serde_json = "1.0.149"
|
||||||
parser = { path = "./parser" }
|
cargo_metadata = "0.23.1"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"crates/parser",
|
||||||
|
"crates/analyzer",
|
||||||
|
"crates/codegen",
|
||||||
|
]
|
||||||
|
|
||||||
|
exclude = [
|
||||||
|
"mist-test",
|
||||||
|
]
|
||||||
|
|
||||||
|
[workspace.dependencies]
|
||||||
|
mist-parser = { path = "crates/parser", version = "0.1.5" }
|
||||||
|
mist-analyzer = { path = "crates/analyzer", version = "0.0.2" }
|
||||||
|
mist-codegen = { path = "crates/codegen", version = "0.1.1" }
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "mist"
|
||||||
|
path = ".mist/src/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "mist-header"
|
||||||
|
path = "src/_header.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "mist-analyzer"
|
||||||
|
path = ".mist/src/analyzer.rs"
|
||||||
|
|||||||
@@ -4,13 +4,9 @@
|
|||||||
Originally this readme was part of the Carbon Language project, licensed with Apache-2.0
|
Originally this readme was part of the Carbon Language project, licensed with Apache-2.0
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- <p align="center">
|
<p align="center">
|
||||||
<a href="#why-build-carbon">Why?</a> |
|
<a href="https://mist.selimaj.dev">Documentation</a>
|
||||||
<a href="#language-goals">Goals</a> |
|
</p>
|
||||||
<a href="#project-status">Status</a> |
|
|
||||||
<a href="#getting-started">Getting started</a> |
|
|
||||||
<a href="#join-us">Join us</a>
|
|
||||||
</p> -->
|
|
||||||
|
|
||||||
|
|
||||||
<img src="code.png" align="right" width="575" alt="">
|
<img src="code.png" align="right" width="575" alt="">
|
||||||
|
|||||||
Generated
+863
@@ -0,0 +1,863 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-trait"
|
||||||
|
version = "0.1.89"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "auto_impl"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ffdcb70bdbc4d478427380519163274ac86e52916e10f0a8889adf0f96d3fee7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "1.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dashmap"
|
||||||
|
version = "5.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"hashbrown",
|
||||||
|
"lock_api",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dashmap"
|
||||||
|
version = "6.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6361d5c062261c78a176addb82d4c821ae42bed6089de0e12603cd25de2059c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-utils",
|
||||||
|
"hashbrown",
|
||||||
|
"lock_api",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "displaydoc"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "form_urlencoded"
|
||||||
|
version = "1.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
|
||||||
|
dependencies = [
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-channel"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-core"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-sink"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-task"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-util"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
|
"pin-project-lite",
|
||||||
|
"slab",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "httparse"
|
||||||
|
version = "1.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_collections"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"potential_utf",
|
||||||
|
"utf8_iter",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_locale_core"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"litemap",
|
||||||
|
"tinystr",
|
||||||
|
"writeable",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_normalizer"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4"
|
||||||
|
dependencies = [
|
||||||
|
"icu_collections",
|
||||||
|
"icu_normalizer_data",
|
||||||
|
"icu_properties",
|
||||||
|
"icu_provider",
|
||||||
|
"smallvec",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_normalizer_data"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_properties"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de"
|
||||||
|
dependencies = [
|
||||||
|
"icu_collections",
|
||||||
|
"icu_locale_core",
|
||||||
|
"icu_properties_data",
|
||||||
|
"icu_provider",
|
||||||
|
"zerotrie",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_properties_data"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_provider"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"icu_locale_core",
|
||||||
|
"writeable",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerotrie",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
|
||||||
|
dependencies = [
|
||||||
|
"idna_adapter",
|
||||||
|
"smallvec",
|
||||||
|
"utf8_iter",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna_adapter"
|
||||||
|
version = "1.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
|
||||||
|
dependencies = [
|
||||||
|
"icu_normalizer",
|
||||||
|
"icu_properties",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.186"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "litemap"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
|
||||||
|
dependencies = [
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lsp-types"
|
||||||
|
version = "0.94.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c66bfd44a06ae10647fe3f8214762e9369fd4248df1350924b4ef9e770a85ea1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mio"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mist-analyzer"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"dashmap 6.2.1",
|
||||||
|
"tokio",
|
||||||
|
"tower-lsp",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.21.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "percent-encoding"
|
||||||
|
version = "2.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project"
|
||||||
|
version = "1.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924"
|
||||||
|
dependencies = [
|
||||||
|
"pin-project-internal",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-internal"
|
||||||
|
version = "1.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-lite"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "potential_utf"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564"
|
||||||
|
dependencies = [
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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 = "redox_syscall"
|
||||||
|
version = "0.5.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.11.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.228"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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.149"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
"zmij",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_repr"
|
||||||
|
version = "0.1.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
|
||||||
|
dependencies = [
|
||||||
|
"errno",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slab"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.15.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "socket2"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stable_deref_trait"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
||||||
|
|
||||||
|
[[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 = "synstructure"
|
||||||
|
version = "0.13.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinystr"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.52.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"libc",
|
||||||
|
"mio",
|
||||||
|
"parking_lot",
|
||||||
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
|
"socket2",
|
||||||
|
"tokio-macros",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-macros"
|
||||||
|
version = "2.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-util"
|
||||||
|
version = "0.7.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-util",
|
||||||
|
"pin-project",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-layer"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-lsp"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d4ba052b54a6627628d9b3c34c176e7eda8359b7da9acd497b9f20998d118508"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"auto_impl",
|
||||||
|
"bytes",
|
||||||
|
"dashmap 5.5.3",
|
||||||
|
"futures",
|
||||||
|
"httparse",
|
||||||
|
"lsp-types",
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
|
"tower",
|
||||||
|
"tower-lsp-macros",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-lsp-macros"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-service"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing"
|
||||||
|
version = "0.1.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
||||||
|
dependencies = [
|
||||||
|
"pin-project-lite",
|
||||||
|
"tracing-attributes",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-attributes"
|
||||||
|
version = "0.1.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-core"
|
||||||
|
version = "0.1.36"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "url"
|
||||||
|
version = "2.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
||||||
|
dependencies = [
|
||||||
|
"form_urlencoded",
|
||||||
|
"idna",
|
||||||
|
"percent-encoding",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8_iter"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.1+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.61.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "writeable"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yoke"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca"
|
||||||
|
dependencies = [
|
||||||
|
"stable_deref_trait",
|
||||||
|
"yoke-derive",
|
||||||
|
"zerofrom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yoke-derive"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerofrom"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"
|
||||||
|
dependencies = [
|
||||||
|
"zerofrom-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerofrom-derive"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerotrie"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerovec"
|
||||||
|
version = "0.11.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239"
|
||||||
|
dependencies = [
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerovec-derive"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zmij"
|
||||||
|
version = "1.0.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "mist-analyzer"
|
||||||
|
version = "0.0.2"
|
||||||
|
edition = "2024"
|
||||||
|
description = "The Mist programming language Analyzer LSP"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
repository = "https://github.com/mist-go/mist"
|
||||||
|
keywords = ["language-server", "language", "mist"]
|
||||||
|
categories = ["compilers"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
mist-parser = { workspace = true }
|
||||||
|
mist-codegen = { workspace = true }
|
||||||
|
|
||||||
|
dashmap = "6.2.1"
|
||||||
|
tokio = { version = "1.52.3", features = ["full", "macros", "rt", "rt-multi-thread"] }
|
||||||
|
tower-lsp = "0.20.0"
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
use tower_lsp::jsonrpc::Result;
|
||||||
|
use tower_lsp::lsp_types::*;
|
||||||
|
use tower_lsp::{Client, LanguageServer, LspService, Server};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Backend {
|
||||||
|
client: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tower_lsp::async_trait]
|
||||||
|
impl LanguageServer for Backend {
|
||||||
|
async fn initialize(&self, _: InitializeParams) -> Result<InitializeResult> {
|
||||||
|
let mut res = InitializeResult::default();
|
||||||
|
|
||||||
|
res.capabilities.completion_provider = Some(CompletionOptions {
|
||||||
|
resolve_provider: None,
|
||||||
|
trigger_characters: None,
|
||||||
|
all_commit_characters: None,
|
||||||
|
work_done_progress_options: WorkDoneProgressOptions {
|
||||||
|
work_done_progress: None,
|
||||||
|
},
|
||||||
|
completion_item: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn initialized(&self, _: InitializedParams) {
|
||||||
|
self.client
|
||||||
|
.log_message(MessageType::INFO, "server initialized!")
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn completion(&self, _params: CompletionParams) -> Result<Option<CompletionResponse>> {
|
||||||
|
self.client
|
||||||
|
.log_message(MessageType::INFO, "getting completion")
|
||||||
|
.await;
|
||||||
|
|
||||||
|
Ok(Some(CompletionResponse::Array(vec![
|
||||||
|
CompletionItem::new_simple("new".to_string(), "The new keyword".to_string()),
|
||||||
|
])))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn shutdown(&self) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
pub async fn start() {
|
||||||
|
let stdin = tokio::io::stdin();
|
||||||
|
let stdout = tokio::io::stdout();
|
||||||
|
|
||||||
|
let (service, socket) = LspService::new(|client| Backend { client });
|
||||||
|
Server::new(stdin, stdout, socket).serve(service).await;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "mist-codegen"
|
||||||
|
version = "0.1.1"
|
||||||
|
edition = "2024"
|
||||||
|
description = "The Mist programming language Rust code generator"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
repository = "https://github.com/mist-go/mist"
|
||||||
|
keywords = ["compiler", "language", "mist"]
|
||||||
|
categories = ["compilers"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
mist-parser = { workspace = true }
|
||||||
@@ -0,0 +1,250 @@
|
|||||||
|
use mist_parser::ast::*;
|
||||||
|
|
||||||
|
use crate::Context;
|
||||||
|
|
||||||
|
use crate::{GenRust, GetRust, RustCodegen};
|
||||||
|
|
||||||
|
impl GetRust for ExprPath {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
self.0
|
||||||
|
.iter()
|
||||||
|
.map(ExprPathSegment::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("::")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for ExprPathSegment {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"{}{}",
|
||||||
|
self.ident.get_rust(),
|
||||||
|
self.generics
|
||||||
|
.as_ref()
|
||||||
|
.map(|v| format!("::{}", v.get_rust()))
|
||||||
|
.unwrap_or_default()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for Literal {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
match self {
|
||||||
|
Self::Int(n) => cg.add(&n.to_string()),
|
||||||
|
Self::Float(n) => cg.add(&format!("{n:?}")),
|
||||||
|
Self::Bool(b) => cg.add(&b.to_string()),
|
||||||
|
Self::String(s) => cg.add(&format!("\"{s}\"")),
|
||||||
|
|
||||||
|
Self::Tuple(values) => {
|
||||||
|
cg.add("(");
|
||||||
|
|
||||||
|
for val in values {
|
||||||
|
val.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.add(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::Array(values) => {
|
||||||
|
cg.add("[");
|
||||||
|
|
||||||
|
for val in values {
|
||||||
|
val.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.add("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::ArrayRepeat(value, repeat) => {
|
||||||
|
cg.add("[");
|
||||||
|
value.gen_rust(ctx, cg);
|
||||||
|
cg.add("; ");
|
||||||
|
repeat.gen_rust(ctx, cg);
|
||||||
|
cg.add("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for Expression {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
let ensure_semicolon = if ctx.expr_ensure_semicolon {
|
||||||
|
ctx.expr_ensure_semicolon = false;
|
||||||
|
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Expression::Path(path) => cg.add(&path.get_rust()),
|
||||||
|
Expression::Literal(literal) => literal.gen_rust(ctx, cg),
|
||||||
|
Expression::Statement(stmt) => stmt.gen_rust(ctx, cg),
|
||||||
|
Expression::Fix {
|
||||||
|
initial,
|
||||||
|
prefixes,
|
||||||
|
postfixes,
|
||||||
|
} => {
|
||||||
|
cg.add(&prefixes.get_rust());
|
||||||
|
initial.gen_rust(ctx, cg);
|
||||||
|
cg.add(&Some(prefixes).get_rust());
|
||||||
|
for postfix in postfixes {
|
||||||
|
postfix.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Safely integrated to handle the tree structure built by the Pratt Parser
|
||||||
|
Expression::Binary { lhs, op, rhs } => {
|
||||||
|
lhs.gen_rust(ctx, cg);
|
||||||
|
cg.add(op);
|
||||||
|
rhs.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ensure_semicolon {
|
||||||
|
ctx.expr_ensure_semicolon = true;
|
||||||
|
|
||||||
|
if !self.is_block() {
|
||||||
|
cg.add(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Prefix {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Deref => "*",
|
||||||
|
Self::Ref => "&",
|
||||||
|
Self::RefMut => "&mut ",
|
||||||
|
Self::Not => "!",
|
||||||
|
Self::New(_) => "",
|
||||||
|
Self::Neg => "-",
|
||||||
|
}
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Vec<Prefix> {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
self.into_iter().map(Prefix::get_rust).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Option<&Vec<Prefix>> {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
if let Some(prefixes) = self {
|
||||||
|
prefixes
|
||||||
|
.into_iter()
|
||||||
|
.last()
|
||||||
|
.map(|p| match p {
|
||||||
|
Prefix::New(generics) => format!(
|
||||||
|
"::new{}",
|
||||||
|
generics
|
||||||
|
.clone()
|
||||||
|
.map(|v| format!("::{}", v.get_rust()))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
),
|
||||||
|
_ => String::new(),
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for Postfix {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
match self {
|
||||||
|
Postfix::FieldAccess(field, generics) => cg.add(&format!(
|
||||||
|
".{}{}",
|
||||||
|
field.get_rust(),
|
||||||
|
generics
|
||||||
|
.iter()
|
||||||
|
.map(|v| format!("::{}", v.get_rust()))
|
||||||
|
.collect::<String>()
|
||||||
|
)),
|
||||||
|
|
||||||
|
Postfix::Call(args) => {
|
||||||
|
cg.add("(");
|
||||||
|
|
||||||
|
for (i, arg) in args.iter().enumerate() {
|
||||||
|
if i > 0 {
|
||||||
|
cg.add(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
arg.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.add(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
Postfix::MacroCall(inner) => {
|
||||||
|
cg.add("!(");
|
||||||
|
cg.add(inner);
|
||||||
|
cg.add(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
Postfix::StructCall(fields) => {
|
||||||
|
cg.add("{");
|
||||||
|
|
||||||
|
for (name, expr) in fields {
|
||||||
|
cg.add(&name.get_rust());
|
||||||
|
cg.add(": ");
|
||||||
|
expr.gen_rust(ctx, cg);
|
||||||
|
cg.add(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.add("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Postfix::Index(idx) => {
|
||||||
|
cg.add("[");
|
||||||
|
idx.gen_rust(ctx, cg);
|
||||||
|
cg.add("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
Postfix::As(ty) => {
|
||||||
|
cg.add(" as ");
|
||||||
|
cg.add(&ty.get_rust());
|
||||||
|
}
|
||||||
|
|
||||||
|
Postfix::Try => cg.add("?"),
|
||||||
|
|
||||||
|
Postfix::Assign(cmp, expr) => {
|
||||||
|
cg.add(" ");
|
||||||
|
cg.add(cmp);
|
||||||
|
expr.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
Postfix::Increment => cg.add("+=1"),
|
||||||
|
Postfix::Decrement => cg.add("-=1"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Generics {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
if self.0.len() == 0 {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"<{}>",
|
||||||
|
self.0
|
||||||
|
.iter()
|
||||||
|
.map(Generic::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Generic {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Lifetime(name) => format!("'{}", name.get_rust()),
|
||||||
|
Self::Type(ty) => ty.get_rust(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
pub mod expr;
|
||||||
|
pub mod statement;
|
||||||
|
pub mod top_level;
|
||||||
|
|
||||||
|
use mist_parser::ast::*;
|
||||||
|
|
||||||
|
pub fn get_mutable(mutable: bool) -> String {
|
||||||
|
if mutable { "mut " } else { "" }.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Context {
|
||||||
|
pub expr_ensure_semicolon: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait GenRust {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait GetRust {
|
||||||
|
fn get_rust(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct RustCodegen {
|
||||||
|
output: String,
|
||||||
|
indent: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RustCodegen {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
output: String::new(),
|
||||||
|
indent: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn indent_str(&self) -> String {
|
||||||
|
" ".repeat(self.indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add(&mut self, s: &str) {
|
||||||
|
self.output.push_str(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn addln(&mut self, s: &str) {
|
||||||
|
self.add(s);
|
||||||
|
self.add("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_indented(&mut self, s: &str) {
|
||||||
|
let line = format!("{}{}", self.indent_str(), s);
|
||||||
|
self.add(&line);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_indentedln(&mut self, s: &str) {
|
||||||
|
let line = format!("{}{}\n", self.indent_str(), s);
|
||||||
|
self.add(&line);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate(&mut self, toplevels: Vec<TopLevel>) -> String {
|
||||||
|
let mut ctx = Context {
|
||||||
|
expr_ensure_semicolon: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
for tl in toplevels {
|
||||||
|
tl.gen_rust(&mut ctx, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.output.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ensure_brackets(&mut self, ctx: &mut Context, stmt: &Box<Statement>) {
|
||||||
|
match &**stmt {
|
||||||
|
Statement::Block(_) => stmt.gen_rust(ctx, self),
|
||||||
|
_ => {
|
||||||
|
self.add("{");
|
||||||
|
self.indent += 1;
|
||||||
|
stmt.gen_rust(ctx, self);
|
||||||
|
self.indent -= 1;
|
||||||
|
self.add("}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ensure_brackets_expr(&mut self, ctx: &mut Context, expr: &Expression) {
|
||||||
|
match expr {
|
||||||
|
Expression::Statement(stmt) => self.ensure_brackets(ctx, stmt),
|
||||||
|
_ => {
|
||||||
|
self.add("{");
|
||||||
|
self.indent += 1;
|
||||||
|
expr.gen_rust(ctx, self);
|
||||||
|
self.indent -= 1;
|
||||||
|
self.add("}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for Attribute {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
match self {
|
||||||
|
Self::Path(path) => cg.add(&path.get_rust()),
|
||||||
|
Self::NameValue { path, value } => {
|
||||||
|
cg.add(&format!("{} =", path.get_rust()));
|
||||||
|
value.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
Self::List { path, items } => {
|
||||||
|
cg.add(&path.get_rust());
|
||||||
|
for (i, item) in items.iter().enumerate() {
|
||||||
|
if i > 0 {
|
||||||
|
cg.add(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
item.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: GetRust> GetRust for Spanned<T> {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"/* {}:{} */ {}",
|
||||||
|
self.line,
|
||||||
|
self.column,
|
||||||
|
self.item.get_rust()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: GenRust> GenRust for Spanned<T> {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
cg.add_indentedln(&format!("/* {}:{} */", self.line, self.column));
|
||||||
|
cg.add_indented("");
|
||||||
|
self.item.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Path {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
self.0
|
||||||
|
.iter()
|
||||||
|
.map(Identifier::get_rust)
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("::")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for TypePostfix {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
TypePostfix::Ref => format!("&"),
|
||||||
|
TypePostfix::RefMut => format!("&mut "),
|
||||||
|
TypePostfix::RefLifetime(lifetime) => format!("&'{} ", lifetime.get_rust()),
|
||||||
|
TypePostfix::RefMutLifetime(lifetime) => format!("&'{} mut ", lifetime.get_rust()),
|
||||||
|
TypePostfix::Dyn => format!("dyn "),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Visibility {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Visibility::Public => "pub ".to_string(),
|
||||||
|
Visibility::PublicTarget(path) => format!("pub({}) ", path.get_rust()),
|
||||||
|
Visibility::Private => "".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for Identifier {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
self.0.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for TypeExpr {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
self.1
|
||||||
|
.iter()
|
||||||
|
.map(TypePostfix::get_rust)
|
||||||
|
.rev()
|
||||||
|
.collect::<String>()
|
||||||
|
+ &self.0.get_rust()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_static_type_path(path: &Path) -> String {
|
||||||
|
let rust_path = path.get_rust();
|
||||||
|
|
||||||
|
if rust_path == "void" {
|
||||||
|
format!("()")
|
||||||
|
} else {
|
||||||
|
rust_path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for TypeExprKind {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
TypeExprKind::Path(path) => get_static_type_path(path),
|
||||||
|
TypeExprKind::Lifetime(name) => format!("'{}", name.get_rust()),
|
||||||
|
TypeExprKind::PathParams(path, params) => {
|
||||||
|
format!(
|
||||||
|
"{}<{}>",
|
||||||
|
get_static_type_path(path),
|
||||||
|
params
|
||||||
|
.into_iter()
|
||||||
|
.map(|t| t.get_rust())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
TypeExprKind::Tuple(types) => format!(
|
||||||
|
"({})",
|
||||||
|
types
|
||||||
|
.into_iter()
|
||||||
|
.map(|t| t.get_rust())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for Pattern {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
match self {
|
||||||
|
Self::Id(id) => cg.add(&id.get_rust()),
|
||||||
|
Self::Path(path) => cg.add(&path.get_rust()),
|
||||||
|
Self::Literal(lit) => lit.gen_rust(ctx, cg),
|
||||||
|
|
||||||
|
Self::Struct(path, ids) => {
|
||||||
|
cg.add(&path.get_rust());
|
||||||
|
cg.add(" {");
|
||||||
|
for id in ids {
|
||||||
|
cg.add(&id.get_rust());
|
||||||
|
cg.add(",");
|
||||||
|
}
|
||||||
|
cg.add("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::NamedTuple(path, ids) => {
|
||||||
|
cg.add(&path.get_rust());
|
||||||
|
cg.add(" (");
|
||||||
|
for id in ids {
|
||||||
|
cg.add(&id.get_rust());
|
||||||
|
cg.add(",");
|
||||||
|
}
|
||||||
|
cg.add(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::Tuple(ids) => {
|
||||||
|
cg.add("(");
|
||||||
|
for id in ids {
|
||||||
|
cg.add(&id.get_rust());
|
||||||
|
cg.add(",");
|
||||||
|
}
|
||||||
|
cg.add(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
use mist_parser::ast::*;
|
||||||
|
|
||||||
|
use crate::{Context, get_mutable};
|
||||||
|
|
||||||
|
use crate::{GenRust, GetRust, RustCodegen};
|
||||||
|
|
||||||
|
impl GenRust for Block {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
cg.addln("{");
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
for stmt in &self.0 {
|
||||||
|
ctx.expr_ensure_semicolon = true;
|
||||||
|
stmt.gen_rust(ctx, cg);
|
||||||
|
cg.addln("");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(soft_return) = &self.1 {
|
||||||
|
ctx.expr_ensure_semicolon = false;
|
||||||
|
soft_return.gen_rust(ctx, cg);
|
||||||
|
cg.addln("");
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.add_indented("}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for Statement {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
match self {
|
||||||
|
Statement::Block(block) => block.gen_rust(ctx, cg),
|
||||||
|
|
||||||
|
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
||||||
|
cg.add("let ");
|
||||||
|
decl.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
if let Some(init) = init {
|
||||||
|
cg.add(" = ");
|
||||||
|
init.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::Match(expr, match_items) => {
|
||||||
|
cg.add("match ");
|
||||||
|
expr.gen_rust(ctx, cg);
|
||||||
|
cg.add(" {");
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
for (pat, body) in match_items {
|
||||||
|
for (i, p) in pat.iter().enumerate() {
|
||||||
|
cg.addln("");
|
||||||
|
cg.add_indented("");
|
||||||
|
if i > 0 {
|
||||||
|
cg.add(" | ");
|
||||||
|
}
|
||||||
|
|
||||||
|
p.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.add(" => ");
|
||||||
|
|
||||||
|
cg.ensure_brackets_expr(ctx, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.addln("");
|
||||||
|
cg.add_indented("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::If {
|
||||||
|
initial,
|
||||||
|
else_if,
|
||||||
|
else_branch,
|
||||||
|
} => {
|
||||||
|
cg.add("if ");
|
||||||
|
initial.condition.gen_rust(ctx, cg);
|
||||||
|
cg.add(" ");
|
||||||
|
cg.ensure_brackets_expr(ctx, &initial.body);
|
||||||
|
|
||||||
|
for else_if_branch in else_if {
|
||||||
|
cg.add("else if");
|
||||||
|
else_if_branch.condition.gen_rust(ctx, cg);
|
||||||
|
cg.add(" ");
|
||||||
|
cg.ensure_brackets_expr(ctx, &else_if_branch.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(else_br) = else_branch {
|
||||||
|
cg.add(" else ");
|
||||||
|
cg.ensure_brackets_expr(ctx, else_br);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::While(StatementBranch { condition, body }) => {
|
||||||
|
cg.add("while ");
|
||||||
|
condition.gen_rust(ctx, cg);
|
||||||
|
cg.add(" ");
|
||||||
|
cg.ensure_brackets_expr(ctx, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::Loop(body) => {
|
||||||
|
cg.add("loop ");
|
||||||
|
cg.ensure_brackets_expr(ctx, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::CStyleFor {
|
||||||
|
init,
|
||||||
|
condition,
|
||||||
|
update,
|
||||||
|
body,
|
||||||
|
} => {
|
||||||
|
cg.addln("{");
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
ctx.expr_ensure_semicolon = true;
|
||||||
|
|
||||||
|
cg.add_indented("");
|
||||||
|
|
||||||
|
init.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
cg.addln("");
|
||||||
|
|
||||||
|
cg.add_indented("while ");
|
||||||
|
|
||||||
|
ctx.expr_ensure_semicolon = false;
|
||||||
|
condition.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
cg.add(" ");
|
||||||
|
|
||||||
|
cg.add("{");
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
ctx.expr_ensure_semicolon = true;
|
||||||
|
|
||||||
|
body.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
update.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
cg.addln("");
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.add_indentedln("}");
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.add_indented("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::For {
|
||||||
|
mutable,
|
||||||
|
pattern,
|
||||||
|
iterator,
|
||||||
|
body,
|
||||||
|
} => {
|
||||||
|
cg.add("for ");
|
||||||
|
cg.add(&get_mutable(*mutable));
|
||||||
|
pattern.gen_rust(ctx, cg);
|
||||||
|
cg.add(" in ");
|
||||||
|
iterator.gen_rust(ctx, cg);
|
||||||
|
cg.ensure_brackets_expr(ctx, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::Return(expr) => {
|
||||||
|
cg.add("return ");
|
||||||
|
if let Some(expr) = expr {
|
||||||
|
expr.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::Break => cg.add_indentedln("break"),
|
||||||
|
Statement::Continue => cg.add_indentedln("continue"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for VarDecl {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
cg.add(&get_mutable(self.mutable));
|
||||||
|
|
||||||
|
self.name.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
cg.add(
|
||||||
|
&self
|
||||||
|
.type_
|
||||||
|
.as_ref()
|
||||||
|
.map(|t| format!(": {}", t.get_rust()))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,402 @@
|
|||||||
|
use mist_parser::ast::*;
|
||||||
|
|
||||||
|
use crate::Context;
|
||||||
|
|
||||||
|
use crate::{GenRust, GetRust, RustCodegen};
|
||||||
|
|
||||||
|
impl GetRust for GenericsDecl {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
if self.0.len() == 0 {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"<{}>",
|
||||||
|
self.0
|
||||||
|
.iter()
|
||||||
|
.map(|v| v.get_rust())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for GenericDecl {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
GenericDecl::Lifetime(name) => format!("'{}", name.get_rust()),
|
||||||
|
GenericDecl::Type(name, requirements) => {
|
||||||
|
name.get_rust()
|
||||||
|
+ &(if requirements.len() != 0 {
|
||||||
|
format!(
|
||||||
|
": {}",
|
||||||
|
requirements
|
||||||
|
.into_iter()
|
||||||
|
.map(TypeExpr::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("+")
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for ImplDecl {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
if let Some(trait_) = &self.trait_ {
|
||||||
|
cg.add_indentedln(&format!(
|
||||||
|
"impl{} {} for {} {{",
|
||||||
|
self.generics.get_rust(),
|
||||||
|
trait_.get_rust(),
|
||||||
|
self.target.get_rust()
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
cg.add_indentedln(&format!(
|
||||||
|
"impl{} {} {{",
|
||||||
|
self.generics.get_rust(),
|
||||||
|
self.target.get_rust()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
for method in &self.methods {
|
||||||
|
method.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.add_indentedln("}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for FunctionDecl {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
cg.add(&format!(
|
||||||
|
"{}fn {}{}(",
|
||||||
|
self.visibility.get_rust(),
|
||||||
|
self.name.get_rust(),
|
||||||
|
self.generics.get_rust(),
|
||||||
|
));
|
||||||
|
|
||||||
|
for (i, param) in self.params.0.iter().enumerate() {
|
||||||
|
if i > 0 {
|
||||||
|
cg.add(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
param.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.add(") -> ");
|
||||||
|
cg.add(&self.return_type.get_rust());
|
||||||
|
|
||||||
|
if let Some(body) = &self.body {
|
||||||
|
cg.add(" ");
|
||||||
|
body.gen_rust(ctx, cg);
|
||||||
|
} else {
|
||||||
|
cg.add(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for FieldDecl {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"{}{}: {},",
|
||||||
|
self.visibility.get_rust(),
|
||||||
|
self.name.get_rust(),
|
||||||
|
self.type_.get_rust()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for EnumItem {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Named(id) => id.get_rust(),
|
||||||
|
Self::Struct(id, s) => format!(
|
||||||
|
"{} {{{}}}",
|
||||||
|
id.get_rust(),
|
||||||
|
s.into_iter()
|
||||||
|
.map(|field| format!("{}: {}", field.name.get_rust(), field.type_.get_rust()))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
),
|
||||||
|
Self::Tuple(id, t) => format!(
|
||||||
|
"{} ({})",
|
||||||
|
id.get_rust(),
|
||||||
|
t.into_iter()
|
||||||
|
.map(TypeExpr::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for ParamList {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
for (i, param) in self.0.iter().enumerate() {
|
||||||
|
if i > 0 {
|
||||||
|
cg.add(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
param.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for TopLevel {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
if let TopLevelKind::ModAttribute = self.0.item {
|
||||||
|
for attr in &self.1 {
|
||||||
|
cg.add("#![");
|
||||||
|
attr.gen_rust(ctx, cg);
|
||||||
|
cg.addln("]");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for attr in &self.1 {
|
||||||
|
cg.add("#[");
|
||||||
|
attr.gen_rust(ctx, cg);
|
||||||
|
cg.addln("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.0.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for (&Vec<Spanned<FieldDeclStmt>>, &Spanned<ClassConstructor>) {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
cg.add_indented(&format!(
|
||||||
|
"{}fn new{}(",
|
||||||
|
self.1.item.visibility.get_rust(),
|
||||||
|
self.1.item.generics.get_rust()
|
||||||
|
));
|
||||||
|
|
||||||
|
self.1.item.params.gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
cg.addln(") -> Self {");
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
cg.add_indentedln("let mut this: Self = unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
||||||
|
|
||||||
|
for field in self.0 {
|
||||||
|
let comment = field.get_comment();
|
||||||
|
|
||||||
|
if let Some(init) = &field.item.init {
|
||||||
|
cg.add_indentedln(&comment);
|
||||||
|
|
||||||
|
cg.add_indentedln(&format!("this.{} = ", field.item.decl.name.get_rust()));
|
||||||
|
|
||||||
|
init.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.add_indented(&format!("this.constructor("));
|
||||||
|
|
||||||
|
for (i, param) in self.1.item.params.0.iter().enumerate() {
|
||||||
|
if i > 0 {
|
||||||
|
cg.add(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
param.name.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.addln(");");
|
||||||
|
|
||||||
|
cg.add_indentedln("this");
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.add_indentedln("}\n");
|
||||||
|
|
||||||
|
let mut constructor_params = vec![VarDecl {
|
||||||
|
mutable: false,
|
||||||
|
name: Pattern::Id(Identifier(String::from("self"))),
|
||||||
|
type_: Some(TypeExpr(
|
||||||
|
TypeExprKind::Path(Path(vec![Identifier(String::from("Self"))])),
|
||||||
|
vec![TypePostfix::RefMut],
|
||||||
|
)),
|
||||||
|
}];
|
||||||
|
|
||||||
|
constructor_params.append(&mut self.1.item.params.0.clone());
|
||||||
|
|
||||||
|
Spanned {
|
||||||
|
line: self.1.line,
|
||||||
|
column: self.1.column,
|
||||||
|
item: FunctionDecl {
|
||||||
|
visibility: self.1.item.visibility.clone(),
|
||||||
|
name: Identifier(String::from("constructor")),
|
||||||
|
generics: self.1.item.generics.clone(),
|
||||||
|
params: ParamList(constructor_params),
|
||||||
|
return_type: TypeExpr::no_px(TypeExprKind::Tuple(Vec::new())),
|
||||||
|
body: Some(self.1.item.body.clone()),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenRust for TopLevelKind {
|
||||||
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
|
match self {
|
||||||
|
Self::ModAttribute => {}
|
||||||
|
Self::Import(vis, path) => {
|
||||||
|
cg.addln(&format!("{}use {};", vis.get_rust(), path.get_rust()))
|
||||||
|
}
|
||||||
|
Self::Mod(vis, id) => cg.addln(&format!("{}mod {};", vis.get_rust(), id.get_rust())),
|
||||||
|
Self::FunctionDecl(decl) => decl.gen_rust(ctx, cg),
|
||||||
|
Self::ImplDecl(impl_) => impl_.gen_rust(ctx, cg),
|
||||||
|
Self::StructDecl {
|
||||||
|
visibility,
|
||||||
|
name,
|
||||||
|
generics,
|
||||||
|
fields,
|
||||||
|
} => {
|
||||||
|
cg.addln(&format!(
|
||||||
|
"{}struct {}{} {{",
|
||||||
|
visibility.get_rust(),
|
||||||
|
name.get_rust(),
|
||||||
|
generics.get_rust()
|
||||||
|
));
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
for field in fields {
|
||||||
|
cg.add_indentedln(&field.get_rust());
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.addln("}\n");
|
||||||
|
}
|
||||||
|
Self::EnumDecl {
|
||||||
|
visibility,
|
||||||
|
name,
|
||||||
|
generics,
|
||||||
|
fields,
|
||||||
|
} => {
|
||||||
|
cg.addln(&format!(
|
||||||
|
"{}enum {}{} {{",
|
||||||
|
visibility.get_rust(),
|
||||||
|
name.get_rust(),
|
||||||
|
generics.get_rust()
|
||||||
|
));
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
for field in fields {
|
||||||
|
cg.add_indentedln(&(field.get_rust() + ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.addln("}\n");
|
||||||
|
}
|
||||||
|
Self::TraitDecl {
|
||||||
|
visibility,
|
||||||
|
name,
|
||||||
|
generics,
|
||||||
|
requirements,
|
||||||
|
items,
|
||||||
|
} => {
|
||||||
|
cg.addln(&format!(
|
||||||
|
"{}trait {}{}{} {{",
|
||||||
|
visibility.get_rust(),
|
||||||
|
name.get_rust(),
|
||||||
|
generics.get_rust(),
|
||||||
|
if requirements.len() != 0 {
|
||||||
|
String::from(": ")
|
||||||
|
+ &requirements
|
||||||
|
.into_iter()
|
||||||
|
.map(TypeExpr::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("+")
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
for item in items {
|
||||||
|
item.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.addln("}\n");
|
||||||
|
}
|
||||||
|
Self::ClassDecl {
|
||||||
|
visibility,
|
||||||
|
name,
|
||||||
|
generics,
|
||||||
|
fields,
|
||||||
|
constructor,
|
||||||
|
items,
|
||||||
|
} => {
|
||||||
|
// Struct decl
|
||||||
|
cg.addln(&format!(
|
||||||
|
"{}struct {}{} {{",
|
||||||
|
visibility.get_rust(),
|
||||||
|
name.clone().get_rust(),
|
||||||
|
generics.clone().get_rust()
|
||||||
|
));
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
for field in fields.clone() {
|
||||||
|
cg.add_indentedln(&field.get_comment());
|
||||||
|
cg.add_indentedln(&field.item.decl.get_rust());
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.addln("}\n");
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
cg.addln(&format!(
|
||||||
|
"impl{} {}{} {{",
|
||||||
|
generics.clone().get_rust(),
|
||||||
|
name.clone().get_rust(),
|
||||||
|
format!(
|
||||||
|
"<{}>",
|
||||||
|
generics
|
||||||
|
.clone()
|
||||||
|
.0
|
||||||
|
.into_iter()
|
||||||
|
.map(|v| Generic::from(v).get_rust())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
));
|
||||||
|
cg.indent += 1;
|
||||||
|
|
||||||
|
let constructor_comment = constructor.get_comment();
|
||||||
|
|
||||||
|
cg.add_indentedln("#[allow(invalid_value)]");
|
||||||
|
cg.add_indentedln(&constructor_comment);
|
||||||
|
|
||||||
|
(fields, constructor).gen_rust(ctx, cg);
|
||||||
|
|
||||||
|
for item in items.clone() {
|
||||||
|
match item {
|
||||||
|
ClassItem::ImplDecl(_) => {}
|
||||||
|
ClassItem::Method(method) => method.gen_rust(ctx, cg),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cg.indent -= 1;
|
||||||
|
cg.addln("}\n");
|
||||||
|
|
||||||
|
for item in items {
|
||||||
|
match item {
|
||||||
|
ClassItem::ImplDecl(impl_) => {
|
||||||
|
let mut impl_ = impl_.clone();
|
||||||
|
|
||||||
|
impl_.item.trait_ = Some(impl_.item.target);
|
||||||
|
impl_.item.target =
|
||||||
|
TypeExpr(TypeExprKind::Path(Path(vec![name.clone()])), Vec::new());
|
||||||
|
|
||||||
|
impl_.gen_rust(ctx, cg);
|
||||||
|
}
|
||||||
|
ClassItem::Method(_) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "mist-parser"
|
||||||
|
version = "0.1.5"
|
||||||
|
edition = "2024"
|
||||||
|
description = "The Mist programming language parser"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
repository = "https://github.com/mist-go/mist"
|
||||||
|
keywords = ["compiler", "language", "mist"]
|
||||||
|
categories = ["compilers", "parser-implementations", "parsing"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pest = "2.8.6"
|
||||||
|
pest_derive = "2.8.6"
|
||||||
|
serde = { version = "1.0.228", features = ["serde_derive"] }
|
||||||
|
serde_json = "1.0.149"
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Expression {
|
||||||
|
Literal(Literal),
|
||||||
|
Path(ExprPath),
|
||||||
|
Statement(Box<Statement>),
|
||||||
|
Fix {
|
||||||
|
initial: Box<Expression>,
|
||||||
|
prefixes: Vec<Prefix>,
|
||||||
|
postfixes: Vec<Postfix>,
|
||||||
|
},
|
||||||
|
Binary {
|
||||||
|
lhs: Box<Expression>,
|
||||||
|
op: String,
|
||||||
|
rhs: Box<Expression>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Literal {
|
||||||
|
String(String),
|
||||||
|
Int(i64),
|
||||||
|
Float(f64),
|
||||||
|
Bool(bool),
|
||||||
|
Tuple(Vec<Expression>),
|
||||||
|
Array(Vec<Expression>),
|
||||||
|
ArrayRepeat(Box<Expression>, Box<Expression>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Pattern {
|
||||||
|
NamedTuple(Path, Vec<Identifier>),
|
||||||
|
Struct(Path, Vec<Identifier>),
|
||||||
|
Tuple(Vec<Identifier>),
|
||||||
|
Literal(Literal),
|
||||||
|
Path(Path),
|
||||||
|
Id(Identifier),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Postfix {
|
||||||
|
FieldAccess(Identifier, Option<Generics>),
|
||||||
|
Call(Vec<Expression>),
|
||||||
|
MacroCall(String),
|
||||||
|
StructCall(Vec<(Identifier, Expression)>),
|
||||||
|
Assign(String, Box<Expression>),
|
||||||
|
Index(Expression),
|
||||||
|
As(TypeExpr),
|
||||||
|
Increment,
|
||||||
|
Decrement,
|
||||||
|
Try,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Prefix {
|
||||||
|
Ref,
|
||||||
|
RefMut,
|
||||||
|
Deref,
|
||||||
|
New(Option<Generics>),
|
||||||
|
Not,
|
||||||
|
Neg,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct ExprPathSegment {
|
||||||
|
pub ident: Identifier,
|
||||||
|
pub generics: Option<Generics>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct ExprPath(pub Vec<ExprPathSegment>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct Generics(pub Vec<Generic>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Generic {
|
||||||
|
Lifetime(Identifier),
|
||||||
|
Type(TypeExpr),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Expression {
|
||||||
|
pub fn is_block(&self) -> bool {
|
||||||
|
if let Expression::Statement(stmt) = self {
|
||||||
|
stmt.is_block()
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
pub mod expr;
|
||||||
|
pub mod statement;
|
||||||
|
pub mod top_level;
|
||||||
|
|
||||||
|
pub use expr::*;
|
||||||
|
pub use statement::*;
|
||||||
|
pub use top_level::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct Path(pub Vec<Identifier>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct Identifier(pub String);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Default)]
|
||||||
|
pub struct ParamList(pub Vec<VarDecl>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct TypeExpr(pub TypeExprKind, pub Vec<TypePostfix>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum TypePostfix {
|
||||||
|
Ref,
|
||||||
|
RefMut,
|
||||||
|
RefLifetime(Identifier),
|
||||||
|
RefMutLifetime(Identifier),
|
||||||
|
Dyn,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum TypeExprKind {
|
||||||
|
Path(Path),
|
||||||
|
PathParams(Path, Vec<TypeExpr>),
|
||||||
|
Tuple(Vec<TypeExpr>),
|
||||||
|
Lifetime(Identifier),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct Spanned<T> {
|
||||||
|
pub line: usize,
|
||||||
|
pub column: usize,
|
||||||
|
pub item: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TypeExpr {
|
||||||
|
pub fn no_px(kind: TypeExprKind) -> Self {
|
||||||
|
Self(kind, Vec::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<GenericDecl> for Generic {
|
||||||
|
fn from(value: GenericDecl) -> Self {
|
||||||
|
match value {
|
||||||
|
GenericDecl::Lifetime(life) => Generic::Lifetime(life),
|
||||||
|
GenericDecl::Type(ty, _) => {
|
||||||
|
Generic::Type(TypeExpr(TypeExprKind::Path(Path(vec![ty])), Vec::new()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Spanned<T> {
|
||||||
|
pub fn get_comment(&self) -> String {
|
||||||
|
format!("/* {}:{} */", self.line, self.column)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Default)]
|
||||||
|
pub struct Block(
|
||||||
|
pub Vec<Spanned<Expression>>,
|
||||||
|
pub Option<Spanned<Expression>>,
|
||||||
|
);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Statement {
|
||||||
|
Block(Block),
|
||||||
|
If {
|
||||||
|
initial: StatementBranch,
|
||||||
|
else_if: Vec<StatementBranch>,
|
||||||
|
else_branch: Option<Box<Expression>>,
|
||||||
|
},
|
||||||
|
Loop(Expression),
|
||||||
|
While(StatementBranch),
|
||||||
|
CStyleFor {
|
||||||
|
init: Expression,
|
||||||
|
condition: Expression,
|
||||||
|
update: Expression,
|
||||||
|
body: Expression,
|
||||||
|
},
|
||||||
|
For {
|
||||||
|
mutable: bool,
|
||||||
|
pattern: Pattern,
|
||||||
|
iterator: Expression,
|
||||||
|
body: Box<Expression>,
|
||||||
|
},
|
||||||
|
Match(Expression, Vec<(Vec<Pattern>, Expression)>),
|
||||||
|
|
||||||
|
VarDecl(VarDeclStmt),
|
||||||
|
Return(Option<Expression>),
|
||||||
|
Break,
|
||||||
|
Continue,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct VarDecl {
|
||||||
|
pub mutable: bool,
|
||||||
|
pub name: Pattern,
|
||||||
|
pub type_: Option<TypeExpr>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct VarDeclStmt {
|
||||||
|
pub decl: VarDecl,
|
||||||
|
pub init: Option<Expression>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct StatementBranch {
|
||||||
|
pub condition: Expression,
|
||||||
|
pub body: Box<Expression>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Statement {
|
||||||
|
pub fn is_block(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Block(_) => true,
|
||||||
|
Self::If {
|
||||||
|
initial,
|
||||||
|
else_if,
|
||||||
|
else_branch,
|
||||||
|
} => {
|
||||||
|
else_branch
|
||||||
|
.as_ref()
|
||||||
|
.map(|v| v.is_block())
|
||||||
|
.unwrap_or_default()
|
||||||
|
|| else_if
|
||||||
|
.last()
|
||||||
|
.map(|b| b.body.is_block())
|
||||||
|
.unwrap_or_default()
|
||||||
|
|| initial.body.is_block()
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Visibility {
|
||||||
|
Public,
|
||||||
|
PublicTarget(Path),
|
||||||
|
Private,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Attribute {
|
||||||
|
/// #[test]
|
||||||
|
Path(Path),
|
||||||
|
|
||||||
|
/// #[name = "value"]
|
||||||
|
NameValue { path: Path, value: Literal },
|
||||||
|
|
||||||
|
/// #[derive(Clone, Copy)]
|
||||||
|
List { path: Path, items: Vec<Attribute> },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct TopLevel(pub Spanned<TopLevelKind>, pub Vec<Attribute>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum TopLevelKind {
|
||||||
|
ModAttribute,
|
||||||
|
Import(Visibility, Path),
|
||||||
|
Mod(Visibility, Identifier),
|
||||||
|
ImplDecl(ImplDecl),
|
||||||
|
TraitDecl {
|
||||||
|
visibility: Visibility,
|
||||||
|
name: Identifier,
|
||||||
|
generics: GenericsDecl,
|
||||||
|
requirements: Vec<TypeExpr>,
|
||||||
|
items: Vec<Spanned<FunctionDecl>>,
|
||||||
|
},
|
||||||
|
EnumDecl {
|
||||||
|
visibility: Visibility,
|
||||||
|
name: Identifier,
|
||||||
|
generics: GenericsDecl,
|
||||||
|
fields: Vec<Spanned<EnumItem>>,
|
||||||
|
},
|
||||||
|
StructDecl {
|
||||||
|
visibility: Visibility,
|
||||||
|
name: Identifier,
|
||||||
|
generics: GenericsDecl,
|
||||||
|
fields: Vec<Spanned<FieldDecl>>,
|
||||||
|
},
|
||||||
|
FunctionDecl(FunctionDecl),
|
||||||
|
ClassDecl {
|
||||||
|
visibility: Visibility,
|
||||||
|
name: Identifier,
|
||||||
|
generics: GenericsDecl,
|
||||||
|
fields: Vec<Spanned<FieldDeclStmt>>,
|
||||||
|
constructor: Spanned<ClassConstructor>,
|
||||||
|
items: Vec<ClassItem>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum ClassItem {
|
||||||
|
Method(Spanned<FunctionDecl>),
|
||||||
|
ImplDecl(Spanned<ImplDecl>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Default)]
|
||||||
|
pub struct GenericsDecl(pub Vec<GenericDecl>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum GenericDecl {
|
||||||
|
Lifetime(Identifier),
|
||||||
|
Type(Identifier, Vec<TypeExpr>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum EnumItem {
|
||||||
|
Named(Identifier),
|
||||||
|
Tuple(Identifier, Vec<TypeExpr>),
|
||||||
|
Struct(Identifier, Vec<FieldDecl>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct ClassConstructor {
|
||||||
|
pub visibility: Visibility,
|
||||||
|
pub generics: GenericsDecl,
|
||||||
|
pub params: ParamList,
|
||||||
|
pub body: Block,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct FunctionDecl {
|
||||||
|
pub visibility: Visibility,
|
||||||
|
pub name: Identifier,
|
||||||
|
pub generics: GenericsDecl,
|
||||||
|
pub params: ParamList,
|
||||||
|
pub return_type: TypeExpr,
|
||||||
|
pub body: Option<Block>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct ImplDecl {
|
||||||
|
pub generics: GenericsDecl,
|
||||||
|
pub target: TypeExpr,
|
||||||
|
pub trait_: Option<TypeExpr>,
|
||||||
|
pub methods: Vec<Spanned<FunctionDecl>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct FieldDecl {
|
||||||
|
pub visibility: Visibility,
|
||||||
|
pub type_: TypeExpr,
|
||||||
|
pub name: Identifier,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct FieldDeclStmt {
|
||||||
|
pub decl: FieldDecl,
|
||||||
|
pub init: Option<Expression>,
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
use pest::iterators::Pair;
|
||||||
|
|
||||||
|
use crate::Rule;
|
||||||
|
|
||||||
|
pub type AstResult<'a, T, ET = T> = Result<T, AstError<'a, ET>>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum ParseError<'a, T> {
|
||||||
|
PreAst(pest::error::Error<Rule>),
|
||||||
|
Ast(AstError<'a, T>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct AstError<'a, T> {
|
||||||
|
pub span: pest::Span<'a>,
|
||||||
|
pub error_code: ErrorCode,
|
||||||
|
pub error_message: String,
|
||||||
|
pub recovered: Option<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum ErrorCode {
|
||||||
|
InvalidStatement,
|
||||||
|
AstGenBug,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<pest::error::Error<Rule>> for ParseError<'_, T> {
|
||||||
|
fn from(value: pest::error::Error<Rule>) -> Self {
|
||||||
|
Self::PreAst(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> From<AstError<'a, T>> for ParseError<'a, T> {
|
||||||
|
fn from(value: AstError<'a, T>) -> Self {
|
||||||
|
Self::Ast(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, F> AstError<'a, F> {
|
||||||
|
pub fn get<T>(self) -> AstError<'a, T> {
|
||||||
|
AstError {
|
||||||
|
span: self.span,
|
||||||
|
error_code: self.error_code,
|
||||||
|
error_message: self.error_message,
|
||||||
|
recovered: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub fn bug_unimplemented<T>(pair: Pair<'a, Rule>) -> AstResult<'a, T, F> {
|
||||||
|
let loc = std::panic::Location::caller();
|
||||||
|
|
||||||
|
Err(Self {
|
||||||
|
span: pair.as_span(),
|
||||||
|
error_code: ErrorCode::AstGenBug,
|
||||||
|
error_message: format!(
|
||||||
|
"Possible bug, unimplemented: {:#?}, at {}:{}",
|
||||||
|
pair.as_rule(),
|
||||||
|
loc.file(),
|
||||||
|
loc.line(),
|
||||||
|
),
|
||||||
|
recovered: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait IntoErr<T, FA, FR> {
|
||||||
|
fn get(self) -> T;
|
||||||
|
fn get_map(self, m: impl Fn(FA) -> FR) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T, TE, TE2> IntoErr<AstResult<'a, T, TE2>, TE, TE2> for AstResult<'a, T, TE> {
|
||||||
|
fn get(self) -> AstResult<'a, T, TE2> {
|
||||||
|
self.map_err(AstError::get)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_map(self, m: impl Fn(TE) -> TE2) -> AstResult<'a, T, TE2> {
|
||||||
|
self.map_err(|e| AstError {
|
||||||
|
span: e.span,
|
||||||
|
error_code: e.error_code,
|
||||||
|
error_message: e.error_message,
|
||||||
|
recovered: e.recovered.map(m),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait GetLength {
|
||||||
|
fn len(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E> GetLength for Result<Vec<T>, E> {
|
||||||
|
fn len(&self) -> usize {
|
||||||
|
if let Ok(v) = self { v.len() } else { 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn collect_recovered<'a, T: Debug, ET>(
|
||||||
|
pairs: impl Iterator<Item = pest::iterators::Pair<'a, Rule>>,
|
||||||
|
) -> AstResult<'a, Vec<T>, Vec<T>>
|
||||||
|
where
|
||||||
|
T: TryFrom<pest::iterators::Pair<'a, Rule>, Error = AstError<'a, ET>>,
|
||||||
|
{
|
||||||
|
collect_recovered_map(pairs, T::try_from)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn collect_recovered_map<'a, T: Debug, F, ET>(
|
||||||
|
pairs: impl Iterator<Item = pest::iterators::Pair<'a, Rule>>,
|
||||||
|
f: F,
|
||||||
|
) -> AstResult<'a, Vec<T>, Vec<T>>
|
||||||
|
where
|
||||||
|
F: Fn(pest::iterators::Pair<'a, Rule>) -> AstResult<'a, T, ET>,
|
||||||
|
{
|
||||||
|
let mut items = Vec::new();
|
||||||
|
let mut last_error: Option<AstError<'a, ET>> = None;
|
||||||
|
|
||||||
|
for pair in pairs {
|
||||||
|
match f(pair) {
|
||||||
|
Ok(item) => items.push(item),
|
||||||
|
Err(e) => {
|
||||||
|
last_error = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match last_error {
|
||||||
|
Some(ast_err) => Err(AstError {
|
||||||
|
span: ast_err.span,
|
||||||
|
error_code: ast_err.error_code,
|
||||||
|
error_message: ast_err.error_message,
|
||||||
|
recovered: Some(items),
|
||||||
|
}),
|
||||||
|
None => Ok(items),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AstErrorAnalyzer<'a, T>(pub Option<AstError<'a, T>>);
|
||||||
|
|
||||||
|
impl<'a, T> AstErrorAnalyzer<'a, T> {
|
||||||
|
pub fn get<V: Clone, V2: Clone + Into<V>>(
|
||||||
|
&mut self,
|
||||||
|
r: AstResult<'a, V, V2>,
|
||||||
|
) -> AstResult<'a, V, V2> {
|
||||||
|
if let Err(e) = r {
|
||||||
|
self.0 = Some(e.clone().get());
|
||||||
|
|
||||||
|
if let Some(recovered) = e.recovered {
|
||||||
|
Ok(recovered.into())
|
||||||
|
} else {
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(self, v: T) -> AstResult<'a, T> {
|
||||||
|
if let Some(mut e) = self.0 {
|
||||||
|
e.recovered = Some(v);
|
||||||
|
|
||||||
|
Err(e)
|
||||||
|
} else {
|
||||||
|
Ok(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,603 @@
|
|||||||
|
// ======================================================
|
||||||
|
// LEXICAL
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
|
||||||
|
COMMENT = _{ "//" ~ (!"\n" ~ ANY)* }
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// PRIMITIVES
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
keyword = {
|
||||||
|
"if"
|
||||||
|
| "else"
|
||||||
|
| "for"
|
||||||
|
| "while"
|
||||||
|
| "match"
|
||||||
|
| "return"
|
||||||
|
| "break"
|
||||||
|
| "continue"
|
||||||
|
| "struct"
|
||||||
|
| "enum"
|
||||||
|
| "class"
|
||||||
|
| "trait"
|
||||||
|
| "impl"
|
||||||
|
| "pub"
|
||||||
|
| "mut"
|
||||||
|
| "var"
|
||||||
|
| "true"
|
||||||
|
| "false"
|
||||||
|
| "dyn"
|
||||||
|
| "loop"
|
||||||
|
}
|
||||||
|
|
||||||
|
identifier = @{
|
||||||
|
!(keyword ~ !(ASCII_ALPHANUMERIC | "_")) ~ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")*
|
||||||
|
}
|
||||||
|
|
||||||
|
integer = @{ ASCII_DIGIT+ }
|
||||||
|
|
||||||
|
float = @{
|
||||||
|
ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean = {
|
||||||
|
"true"
|
||||||
|
| "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
string_lit = {
|
||||||
|
"\"" ~ inner_str ~ "\""
|
||||||
|
}
|
||||||
|
|
||||||
|
inner_str = @{
|
||||||
|
(!"\"" ~ ("\\\"" | ANY))*
|
||||||
|
}
|
||||||
|
|
||||||
|
semicolon = _{ ";" }
|
||||||
|
|
||||||
|
static_path = {
|
||||||
|
identifier ~ ("::" ~ identifier)*
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// PROGRAM
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
program = {
|
||||||
|
SOI ~ top_level* ~ EOI
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// MODIFIERS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
visibility = { "pub" ~ ("(" ~ static_path ~ ")")? }
|
||||||
|
mutable = { "mut" }
|
||||||
|
var = { "var" }
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// GENERICS
|
||||||
|
// ======================================================
|
||||||
|
generic_decl = { lifetime | (identifier ~ (":" ~ type_expr_param ~ ("+" ~ type_expr_param)*)?) }
|
||||||
|
generics_decl = { "<" ~ (generic_decl ~ ("," ~ generic_decl)*)? ~ ">" }
|
||||||
|
|
||||||
|
generic = { lifetime | type_expr_param }
|
||||||
|
generics = { "<" ~ (generic ~ ("," ~ generic)*)? ~ ">" }
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// TYPES
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
tuple_type = {
|
||||||
|
"(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")"
|
||||||
|
}
|
||||||
|
|
||||||
|
path_type = {
|
||||||
|
static_path ~ ("<" ~ (type_expr_param ~ ("," ~ type_expr_param)*)? ~ ">")?
|
||||||
|
}
|
||||||
|
|
||||||
|
ref_type = {
|
||||||
|
mutable? ~ lifetime? ~ "*"
|
||||||
|
}
|
||||||
|
|
||||||
|
dyn_type = {
|
||||||
|
"dyn"
|
||||||
|
}
|
||||||
|
|
||||||
|
type_expr = {
|
||||||
|
(path_type | tuple_type) ~ (ref_type | dyn_type)*
|
||||||
|
}
|
||||||
|
|
||||||
|
lifetime = {
|
||||||
|
"'" ~ identifier
|
||||||
|
}
|
||||||
|
|
||||||
|
type_expr_param = {
|
||||||
|
type_expr
|
||||||
|
| lifetime
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// LITERALS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
literal = {
|
||||||
|
float
|
||||||
|
| integer
|
||||||
|
| boolean
|
||||||
|
| string_lit
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// PATTERNS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
tuple_pattern = {
|
||||||
|
"[" ~ (identifier ~ ("," ~ identifier)*) ~ "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
named_tuple_pattern = {
|
||||||
|
static_path ~ "[" ~ (identifier ~ ("," ~ identifier)*)? ~ "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
struct_pattern = {
|
||||||
|
static_path ~ "{" ~ (identifier ~ ("," ~ identifier)*)? ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
pattern = _{
|
||||||
|
named_tuple_pattern
|
||||||
|
| tuple_pattern
|
||||||
|
| struct_pattern
|
||||||
|
| literal
|
||||||
|
| static_path
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// ATTRIBUTES / META
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
attribute = {
|
||||||
|
"#" ~ "[" ~ meta ~ "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
mod_attribute = {
|
||||||
|
"#" ~ "!" ~ "[" ~ meta ~ "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
static_path ~ ("=" ~ literal | "(" ~ meta_list? ~ ")")?
|
||||||
|
}
|
||||||
|
|
||||||
|
meta_list = {
|
||||||
|
meta ~ ("," ~ meta)* ~ ","?
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes = {
|
||||||
|
attribute*
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// DECLARATION HELPERS
|
||||||
|
// ======================================================
|
||||||
|
var_decl = {
|
||||||
|
(var | type_expr) ~ mutable? ~ pattern
|
||||||
|
}
|
||||||
|
|
||||||
|
field = {
|
||||||
|
visibility? ~ type_expr ~ identifier
|
||||||
|
}
|
||||||
|
|
||||||
|
field_list = {
|
||||||
|
field ~ ("," ~ field)* ~ ","?
|
||||||
|
}
|
||||||
|
|
||||||
|
param_list = {
|
||||||
|
var_decl ~ ("," ~ var_decl)* ~ ","?
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// IMPORTS / MODULES
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
import = {
|
||||||
|
visibility? ~ "use" ~ "<" ~ static_path ~ ">" ~ semicolon
|
||||||
|
}
|
||||||
|
|
||||||
|
mod_package = {
|
||||||
|
visibility? ~ "mod" ~ identifier ~ semicolon
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// STRUCTS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
struct_decl = {
|
||||||
|
visibility? ~ "struct" ~ identifier ~ generics_decl? ~ "{" ~ field_list? ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// ENUMS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
enum_named = {
|
||||||
|
identifier
|
||||||
|
}
|
||||||
|
|
||||||
|
enum_tuple = {
|
||||||
|
identifier ~ tuple_type
|
||||||
|
}
|
||||||
|
|
||||||
|
enum_struct = {
|
||||||
|
identifier ~ "{" ~ field_list ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
enum_field = _{
|
||||||
|
enum_tuple
|
||||||
|
| enum_struct
|
||||||
|
| enum_named
|
||||||
|
}
|
||||||
|
|
||||||
|
enum_fields = _{
|
||||||
|
enum_field ~ ("," ~ enum_field)* ~ ","?
|
||||||
|
}
|
||||||
|
|
||||||
|
enum_decl = {
|
||||||
|
visibility? ~ "enum" ~ identifier ~ generics_decl? ~ "{" ~ enum_fields ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// CLASSES
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
class_constructor = {
|
||||||
|
visibility? ~ "constructor" ~ generics_decl? ~ "(" ~ param_list? ~ ")" ~ block
|
||||||
|
}
|
||||||
|
|
||||||
|
class_fields = {
|
||||||
|
class_field*
|
||||||
|
}
|
||||||
|
|
||||||
|
class_field = {
|
||||||
|
field ~ ("=" ~ expr)? ~ semicolon
|
||||||
|
}
|
||||||
|
|
||||||
|
self_param = {
|
||||||
|
"self" ~ mutable? ~ deref_px?
|
||||||
|
}
|
||||||
|
|
||||||
|
method = {
|
||||||
|
visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ self_param? ~ ("," ~ param_list?)? ~ ")" ~ block
|
||||||
|
}
|
||||||
|
|
||||||
|
class_item = _{
|
||||||
|
impl_decl
|
||||||
|
| method
|
||||||
|
}
|
||||||
|
|
||||||
|
class_decl = {
|
||||||
|
visibility? ~ "class" ~ identifier ~ generics_decl? ~ "{" ~ class_fields ~ class_constructor ~ class_item* ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// IMPL
|
||||||
|
// ======================================================
|
||||||
|
impl_for_decl = {
|
||||||
|
"impl" ~ generics_decl? ~ type_expr ~ "for" ~ type_expr ~ "{" ~ method* ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_decl = {
|
||||||
|
"impl" ~ generics_decl? ~ type_expr ~ "{" ~ method* ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// Traits
|
||||||
|
// ======================================================
|
||||||
|
trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* }
|
||||||
|
|
||||||
|
method_no_body = {
|
||||||
|
visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ self_param? ~ ("," ~ param_list?)? ~ ")" ~ semicolon
|
||||||
|
}
|
||||||
|
|
||||||
|
trait_item = _{
|
||||||
|
method
|
||||||
|
| method_no_body
|
||||||
|
}
|
||||||
|
|
||||||
|
trait_decl = {
|
||||||
|
visibility? ~ "trait" ~ identifier ~ generics_decl? ~ trait_requirements? ~ "{" ~ trait_item* ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// FUNCTIONS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
function_decl = {
|
||||||
|
visibility? ~ type_expr ~ identifier ~ "(" ~ param_list? ~ ")" ~ block
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// TOP LEVEL
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
top_level = {
|
||||||
|
(attributes ~ (import | impl_for_decl | impl_decl | trait_decl | struct_decl | enum_decl | class_decl | mod_package | function_decl))
|
||||||
|
| mod_attribute
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// STATEMENTS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
block = {
|
||||||
|
"{" ~ statement_list ~ expr? ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
statement_list = {
|
||||||
|
statement*
|
||||||
|
}
|
||||||
|
|
||||||
|
statement = _{
|
||||||
|
control_flow
|
||||||
|
| (expr ~ semicolon)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// BASIC STATEMENTS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
basic_stmt = {
|
||||||
|
return_stmt
|
||||||
|
| break_stmt
|
||||||
|
| continue_stmt
|
||||||
|
| var_decl_statement
|
||||||
|
}
|
||||||
|
|
||||||
|
return_stmt = {
|
||||||
|
"return" ~ expr?
|
||||||
|
}
|
||||||
|
|
||||||
|
break_stmt = {
|
||||||
|
"break"
|
||||||
|
}
|
||||||
|
|
||||||
|
continue_stmt = {
|
||||||
|
"continue"
|
||||||
|
}
|
||||||
|
|
||||||
|
var_decl_statement = {
|
||||||
|
var_decl ~ ("=" ~ expr)?
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// CONDITIONALS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
control_flow = {
|
||||||
|
if_stmt
|
||||||
|
| while_stmt
|
||||||
|
| c_for_stmt
|
||||||
|
| for_stmt
|
||||||
|
| match_stmt
|
||||||
|
| loop_stmt
|
||||||
|
| block
|
||||||
|
}
|
||||||
|
|
||||||
|
statement_branch = { "(" ~ expr ~ ")" ~ statement }
|
||||||
|
|
||||||
|
else_if = {
|
||||||
|
"else" ~ "if" ~ statement_branch
|
||||||
|
}
|
||||||
|
|
||||||
|
else_if_list = {
|
||||||
|
else_if*
|
||||||
|
}
|
||||||
|
|
||||||
|
if_stmt = {
|
||||||
|
"if" ~ statement_branch ~ else_if_list ~ ("else" ~ statement)?
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// LOOPS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
while_stmt = {
|
||||||
|
"while" ~ statement_branch
|
||||||
|
}
|
||||||
|
|
||||||
|
c_for_stmt = {
|
||||||
|
"for" ~ "(" ~ statement ~ statement ~ expr ~ ")" ~ statement
|
||||||
|
}
|
||||||
|
|
||||||
|
for_stmt = {
|
||||||
|
"for" ~ "(" ~ mutable? ~ pattern ~ ":" ~ expr ~ ")" ~ statement
|
||||||
|
}
|
||||||
|
|
||||||
|
loop_stmt = {
|
||||||
|
"loop" ~ statement
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// MATCH
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
pattern_list = { pattern ~ ("|" ~ pattern)* }
|
||||||
|
|
||||||
|
match_item = {
|
||||||
|
pattern_list ~ "=>" ~ statement
|
||||||
|
}
|
||||||
|
|
||||||
|
match_stmt = {
|
||||||
|
"match" ~ "(" ~ expr ~ ")" ~ "{" ~ match_item* ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// EXPRESSIONS
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// TUPLES & ARRAYS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
tuple = {
|
||||||
|
"(" ~ (expr ~ ("," ~ expr)*)? ~ ")"
|
||||||
|
}
|
||||||
|
|
||||||
|
array = {
|
||||||
|
"[" ~ expr ~ ";" ~ expr ~ "]" // Repeat notation: [0; 10]
|
||||||
|
|
||||||
|
| "[" ~ (expr ~ ("," ~ expr)* ~ ","?)? ~ "]" // Standard elements initialization
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// MACROS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
macro_inner_v = @{
|
||||||
|
string_lit
|
||||||
|
| ("(" ~ macro_inner_v* ~ ")")
|
||||||
|
| (!("(" | ")") ~ ANY)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// PRIMARY EXPRESSIONS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
expr_path_segment = {
|
||||||
|
identifier ~ ("::" ~ generics)?
|
||||||
|
}
|
||||||
|
|
||||||
|
expr_path = {
|
||||||
|
expr_path_segment ~ ("::" ~ expr_path_segment)*
|
||||||
|
}
|
||||||
|
|
||||||
|
primary = {
|
||||||
|
control_flow
|
||||||
|
| basic_stmt
|
||||||
|
| literal
|
||||||
|
| expr_path
|
||||||
|
| tuple
|
||||||
|
| array
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// POSTFIX EXPRESSIONS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
field_px = {
|
||||||
|
"." ~ identifier ~ ("::" ~ generics)?
|
||||||
|
}
|
||||||
|
|
||||||
|
call_px = {
|
||||||
|
"(" ~ (expr ~ ("," ~ expr)*)? ~ ")"
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_call_px = {
|
||||||
|
"!" ~ "(" ~ macro_inner_v* ~ ")"
|
||||||
|
}
|
||||||
|
|
||||||
|
struct_field_decl = {
|
||||||
|
identifier ~ ":" ~ expr
|
||||||
|
}
|
||||||
|
|
||||||
|
struct_px = {
|
||||||
|
"{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ ","? ~ "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
index_px = {
|
||||||
|
"[" ~ expr ~ "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
as_px = {
|
||||||
|
"as" ~ type_expr
|
||||||
|
}
|
||||||
|
|
||||||
|
try_px = {
|
||||||
|
"?"
|
||||||
|
}
|
||||||
|
|
||||||
|
increment = {
|
||||||
|
"++"
|
||||||
|
}
|
||||||
|
|
||||||
|
decrement = {
|
||||||
|
"--"
|
||||||
|
}
|
||||||
|
|
||||||
|
postfix = {
|
||||||
|
field_px
|
||||||
|
| call_px
|
||||||
|
| macro_call_px
|
||||||
|
| struct_px
|
||||||
|
| index_px
|
||||||
|
| as_px
|
||||||
|
| try_px
|
||||||
|
| increment
|
||||||
|
| decrement
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// PREFIX EXPRESSIONS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
deref_px = { "*" }
|
||||||
|
mut_ref_px = { "&" ~ mutable }
|
||||||
|
ref_px = { "&" }
|
||||||
|
new_px = { "new" ~ generics? }
|
||||||
|
not_px = { "!" }
|
||||||
|
neg_px = { "-" }
|
||||||
|
|
||||||
|
prefix = {
|
||||||
|
deref_px
|
||||||
|
| mut_ref_px
|
||||||
|
| ref_px
|
||||||
|
| new_px
|
||||||
|
| not_px
|
||||||
|
| neg_px
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// OPERATORS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
bin_op = {
|
||||||
|
"+="
|
||||||
|
| "-="
|
||||||
|
| "/="
|
||||||
|
| "%="
|
||||||
|
| "&="
|
||||||
|
| "|="
|
||||||
|
| "^="
|
||||||
|
| "<<="
|
||||||
|
| ">>="
|
||||||
|
| "<<"
|
||||||
|
| ">>"
|
||||||
|
| "..="
|
||||||
|
| ".."
|
||||||
|
| "<="
|
||||||
|
| ">="
|
||||||
|
| "=="
|
||||||
|
| "!="
|
||||||
|
| "&&"
|
||||||
|
| "||"
|
||||||
|
| "+"
|
||||||
|
| "-"
|
||||||
|
| "*"
|
||||||
|
| "/"
|
||||||
|
| "%"
|
||||||
|
| "<"
|
||||||
|
| ">"
|
||||||
|
| "&"
|
||||||
|
| "|"
|
||||||
|
| "^"
|
||||||
|
| "="
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// EXPRESSIONS
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
expr = { term ~ (bin_op ~ term)* }
|
||||||
|
|
||||||
|
term = { prefix* ~ primary ~ postfix* }
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
use pest::Parser;
|
||||||
|
use pest_derive::Parser;
|
||||||
|
|
||||||
|
pub mod ast;
|
||||||
|
pub mod error;
|
||||||
|
pub mod parser;
|
||||||
|
pub mod rev_mapper;
|
||||||
|
|
||||||
|
use ast::*;
|
||||||
|
|
||||||
|
use crate::error::{IntoErr, ParseError};
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[grammar = "./src/grammar.pest"]
|
||||||
|
pub struct MistParser;
|
||||||
|
|
||||||
|
pub fn parse<'a>(source: &'a str) -> Result<Vec<TopLevel>, ParseError<'a, Vec<TopLevel>>> {
|
||||||
|
let mut pairs = MistParser::parse(Rule::program, source)?;
|
||||||
|
|
||||||
|
let mut statements = vec![];
|
||||||
|
|
||||||
|
let mut analyzer = error::AstErrorAnalyzer(None);
|
||||||
|
|
||||||
|
for pair in pairs.next().unwrap().into_inner() {
|
||||||
|
if pair.as_rule() != Rule::EOI {
|
||||||
|
statements.push(analyzer.get(TopLevel::try_from(pair)).get()?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match analyzer.build(statements) {
|
||||||
|
Ok(v) => Ok(v),
|
||||||
|
Err(e) => Err(ParseError::Ast(e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ast_ensure {
|
||||||
|
($pair:expr, $rule:expr $(, $rules:expr)* => $body:block) => {
|
||||||
|
if $pair.as_rule() == $rule $(|| $pair.as_rule() == $rules)*
|
||||||
|
$body
|
||||||
|
else {
|
||||||
|
Err(AstError {
|
||||||
|
span: $pair.as_span(),
|
||||||
|
error_code: crate::error::ErrorCode::AstGenBug,
|
||||||
|
error_message: format!("Possible bug: expected {:?}, got {:?}", $rule, $pair.as_rule()),
|
||||||
|
recovered: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ast_expr {
|
||||||
|
(use $r:expr, $($v:expr),* $(,)?) => {{
|
||||||
|
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||||
|
|
||||||
|
$(
|
||||||
|
analyzer.get($v).get()?;
|
||||||
|
)*
|
||||||
|
|
||||||
|
analyzer.build($r)
|
||||||
|
}};
|
||||||
|
|
||||||
|
($($item:ident)::+ { $($k:ident: $v:expr),* $(,)? }) => {{
|
||||||
|
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||||
|
|
||||||
|
let v = $($item)::+ { $($k: analyzer.get($v).get()?),* };
|
||||||
|
|
||||||
|
analyzer.build(v)
|
||||||
|
}};
|
||||||
|
|
||||||
|
($($item:ident)::+ ( $($v:expr),* $(,)? )) => {{
|
||||||
|
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||||
|
|
||||||
|
let v = $($item)::+ ( $(analyzer.get($v).get()?),* );
|
||||||
|
|
||||||
|
analyzer.build(v)
|
||||||
|
}};
|
||||||
|
|
||||||
|
($($item:ident)::+) => {
|
||||||
|
$($item)::+
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
ast_expr,
|
||||||
|
error::{AstError, AstResult, IntoErr},
|
||||||
|
parser::listen_rule,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for VarDeclStmt {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
match pair.as_rule() {
|
||||||
|
Rule::var_decl_statement => {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
ast_expr!(VarDeclStmt {
|
||||||
|
decl: inner.next().unwrap().try_into(),
|
||||||
|
init: inner.next().map(Expression::try_from).transpose()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FieldDeclStmt {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
match pair.as_rule() {
|
||||||
|
Rule::class_field => {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
ast_expr!(FieldDeclStmt {
|
||||||
|
decl: inner.next().unwrap().try_into(),
|
||||||
|
init: inner.next().map(Expression::try_from).transpose(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for VarDecl {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
match pair.as_rule() {
|
||||||
|
Rule::var_decl => {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
let type_ = inner
|
||||||
|
.next()
|
||||||
|
.and_then(|pair| {
|
||||||
|
if pair.as_str().trim() == "var" {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(TypeExpr::try_from(pair))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.transpose();
|
||||||
|
|
||||||
|
let mutable: AstResult<'_, bool> = Ok(listen_rule(&mut inner, Rule::mutable));
|
||||||
|
|
||||||
|
let name = Pattern::try_from(inner.next().unwrap());
|
||||||
|
|
||||||
|
ast_expr!(VarDecl {
|
||||||
|
type_: type_,
|
||||||
|
mutable: mutable,
|
||||||
|
name: name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FieldDecl {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
match pair.as_rule() {
|
||||||
|
Rule::field => {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
ast_expr!(FieldDecl {
|
||||||
|
visibility: Visibility::try_from(&mut inner),
|
||||||
|
type_: TypeExpr::try_from(inner.next().unwrap()),
|
||||||
|
name: Identifier::try_from(inner.next().unwrap()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
ast_ensure, ast_expr,
|
||||||
|
error::{AstError, AstResult, GetLength, IntoErr, collect_recovered, collect_recovered_map},
|
||||||
|
};
|
||||||
|
use pest::pratt_parser::PrattParser;
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::expr => {
|
||||||
|
static PRATT_PARSER: OnceLock<PrattParser<Rule>> = OnceLock::new();
|
||||||
|
let pratt = PRATT_PARSER.get_or_init(|| {
|
||||||
|
use pest::pratt_parser::{Assoc::*, Op};
|
||||||
|
|
||||||
|
PrattParser::new().op(Op::infix(Rule::bin_op, Left))
|
||||||
|
});
|
||||||
|
|
||||||
|
pratt
|
||||||
|
.map_primary(|primary_pair| Expression::try_from(primary_pair))
|
||||||
|
.map_infix(|expr, op, rhs| {
|
||||||
|
ast_expr!(Expression::Binary {
|
||||||
|
lhs: expr.map(Box::new).get_map(Box::new),
|
||||||
|
op: Ok(op.as_str().to_string()) as AstResult<'_, String>,
|
||||||
|
rhs: rhs.map(Box::new).get_map(Box::new),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.parse(inner)
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::term => {
|
||||||
|
let mut prefix_pairs = Vec::new();
|
||||||
|
let mut primary_pair = None;
|
||||||
|
let mut postfix_pairs = Vec::new();
|
||||||
|
|
||||||
|
for p in inner {
|
||||||
|
match p.as_rule() {
|
||||||
|
Rule::prefix => prefix_pairs.push(p),
|
||||||
|
Rule::primary => primary_pair = Some(p),
|
||||||
|
Rule::postfix => postfix_pairs.push(p),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let prefixes = collect_recovered::<Prefix, Prefix>(prefix_pairs.into_iter());
|
||||||
|
let exp = Expression::try_from(
|
||||||
|
primary_pair.expect("Term must contain a primary expression"),
|
||||||
|
);
|
||||||
|
let postfixes = collect_recovered::<Postfix, Postfix>(postfix_pairs.into_iter());
|
||||||
|
|
||||||
|
if postfixes.len() > 0 || prefixes.len() > 0 {
|
||||||
|
ast_expr!(Expression::Fix {
|
||||||
|
initial: exp.map(Box::new),
|
||||||
|
prefixes: prefixes,
|
||||||
|
postfixes: postfixes,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ast_expr!(use exp?, prefixes, postfixes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::tuple => {
|
||||||
|
ast_expr!(Expression::Literal(
|
||||||
|
collect_recovered(pair.into_inner())
|
||||||
|
.map(Literal::Tuple)
|
||||||
|
.get_map(Literal::Tuple)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::primary => pair.into_inner().next().unwrap().try_into(),
|
||||||
|
Rule::static_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||||
|
Rule::literal => ast_expr!(Expression::Literal(pair.try_into())),
|
||||||
|
Rule::expr_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||||
|
Rule::statement | Rule::basic_stmt | Rule::control_flow => ast_expr!(
|
||||||
|
Expression::Statement(pair.try_into().get_map(Box::new).map(Box::new))
|
||||||
|
),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Prefix {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
Ok(match pair.as_rule() {
|
||||||
|
Rule::prefix => Self::try_from(pair.into_inner().next().unwrap())?,
|
||||||
|
Rule::deref_px => Self::Deref,
|
||||||
|
Rule::mut_ref_px => Self::RefMut,
|
||||||
|
Rule::ref_px => Self::Ref,
|
||||||
|
Rule::new_px => Self::New(
|
||||||
|
pair.into_inner()
|
||||||
|
.next()
|
||||||
|
.map(|v| v.try_into().get())
|
||||||
|
.transpose()?,
|
||||||
|
),
|
||||||
|
Rule::not_px => Self::Not,
|
||||||
|
Rule::neg_px => Self::Neg,
|
||||||
|
|
||||||
|
_ => return AstError::bug_unimplemented(pair),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Postfix {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::postfix => Postfix::try_from(inner.next().unwrap()),
|
||||||
|
|
||||||
|
Rule::field_px => {
|
||||||
|
ast_expr!(Postfix::FieldAccess(
|
||||||
|
inner.next().unwrap().try_into(),
|
||||||
|
inner.next().map(Generics::try_from).transpose()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::call_px => ast_expr!(Postfix::Call(collect_recovered(inner))),
|
||||||
|
|
||||||
|
Rule::struct_px => ast_expr!(Postfix::StructCall(collect_recovered_map(inner, |p| {
|
||||||
|
let mut pi = p.into_inner();
|
||||||
|
Ok((
|
||||||
|
Identifier::try_from(pi.next().unwrap())?,
|
||||||
|
Expression::try_from(pi.next().unwrap()).get()?,
|
||||||
|
))
|
||||||
|
}))),
|
||||||
|
|
||||||
|
Rule::index_px => {
|
||||||
|
ast_expr!(Postfix::Index(Expression::try_from(inner.next().unwrap())))
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::macro_call_px => Ok(Postfix::MacroCall(inner.as_str().to_string())),
|
||||||
|
|
||||||
|
Rule::as_px => {
|
||||||
|
ast_expr!(Postfix::As(inner.next().unwrap().try_into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::try_px => Ok(Postfix::Try),
|
||||||
|
|
||||||
|
Rule::increment => Ok(Postfix::Increment),
|
||||||
|
Rule::decrement => Ok(Postfix::Decrement),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ExprPath {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
ast_ensure!(pair, Rule::expr_path => {
|
||||||
|
ast_expr!(ExprPath(collect_recovered(pair.into_inner())))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ExprPathSegment {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
ast_ensure!(pair, Rule::expr_path_segment => {
|
||||||
|
ast_expr!(ExprPathSegment {
|
||||||
|
ident: Identifier::try_from(inner.next().unwrap()),
|
||||||
|
generics: inner.next().map(Generics::try_from).transpose(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
pub mod decl;
|
||||||
|
pub mod expr;
|
||||||
|
pub mod statement;
|
||||||
|
pub mod types;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
ast_ensure, ast_expr,
|
||||||
|
error::{AstError, IntoErr, collect_recovered},
|
||||||
|
parser::consume_rule,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Identifier {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
ast_ensure!(pair, Rule::identifier => {
|
||||||
|
Ok(Identifier(pair.as_str().to_string()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Path {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
match pair.as_rule() {
|
||||||
|
Rule::static_path => Ok(Path(collect_recovered(pair.into_inner()).get()?)),
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Literal {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
Ok(match rule {
|
||||||
|
Rule::primary => Self::try_from(inner.next().unwrap())?,
|
||||||
|
Rule::literal => Self::try_from(inner.next().unwrap())?,
|
||||||
|
Rule::integer => Literal::Int(pair.as_str().parse::<i64>().unwrap()),
|
||||||
|
Rule::float => Literal::Float(pair.as_str().parse::<f64>().unwrap()),
|
||||||
|
Rule::boolean => Literal::Bool(pair.as_str().parse::<bool>().unwrap()),
|
||||||
|
Rule::string_lit => Literal::String(inner.as_str().to_string()),
|
||||||
|
Rule::tuple => Literal::Tuple(collect_recovered(inner).get()?),
|
||||||
|
_ => return AstError::bug_unimplemented(pair),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Pattern {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::tuple_pattern => ast_expr!(Pattern::Tuple(collect_recovered(pair.into_inner()))),
|
||||||
|
|
||||||
|
Rule::named_tuple_pattern => ast_expr!(Pattern::NamedTuple(
|
||||||
|
Path::try_from(inner.next().unwrap()),
|
||||||
|
collect_recovered(inner),
|
||||||
|
)),
|
||||||
|
|
||||||
|
Rule::struct_pattern => ast_expr!(Pattern::Struct(
|
||||||
|
Path::try_from(inner.next().unwrap()),
|
||||||
|
collect_recovered(inner),
|
||||||
|
)),
|
||||||
|
|
||||||
|
Rule::literal => ast_expr!(Pattern::Literal(pair.try_into())),
|
||||||
|
|
||||||
|
Rule::identifier => ast_expr!(Pattern::Id(pair.try_into())),
|
||||||
|
|
||||||
|
Rule::static_path => ast_expr!(Pattern::Path(pair.try_into())),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<&mut pest::iterators::Pairs<'a, Rule>> for Visibility {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pairs: &mut pest::iterators::Pairs<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
Ok(consume_rule(pairs, Rule::visibility)
|
||||||
|
.map(|pair| -> Result<Visibility, AstError<'a, Self>> {
|
||||||
|
if let Some(path) = pair.into_inner().next() {
|
||||||
|
ast_expr!(Visibility::PublicTarget(Path::try_from(path)))
|
||||||
|
} else {
|
||||||
|
Ok(Visibility::Public)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.transpose()?
|
||||||
|
.unwrap_or_else(|| Visibility::Private))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
ast_ensure, ast_expr,
|
||||||
|
error::{AstError, AstResult, IntoErr, collect_recovered},
|
||||||
|
parser::listen_rule,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
ast_ensure!(pair, Rule::block => {
|
||||||
|
ast_expr!(Block(collect_recovered(inner.next().unwrap().into_inner()), inner.next().map(Spanned::try_from).transpose()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for StatementBranch {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
ast_ensure!(pair, Rule::statement_branch => {
|
||||||
|
ast_expr!(StatementBranch {
|
||||||
|
condition: inner.next().unwrap().try_into(),
|
||||||
|
body: inner.next().unwrap().try_into().map(Box::new),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::statement | Rule::basic_stmt | Rule::control_flow => {
|
||||||
|
Statement::try_from(inner.next().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::block => ast_expr!(Statement::Block(pair.try_into())),
|
||||||
|
|
||||||
|
Rule::var_decl_statement => ast_expr!(Statement::VarDecl(pair.try_into())),
|
||||||
|
|
||||||
|
Rule::return_stmt => {
|
||||||
|
ast_expr!(Statement::Return(
|
||||||
|
inner.next().map(Expression::try_from).transpose()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::break_stmt => Ok(Statement::Break),
|
||||||
|
|
||||||
|
Rule::continue_stmt => Ok(Statement::Continue),
|
||||||
|
|
||||||
|
Rule::if_stmt => {
|
||||||
|
ast_expr!(Statement::If {
|
||||||
|
initial: inner.next().unwrap().try_into(),
|
||||||
|
else_if: collect_recovered(inner.next().unwrap().into_inner()),
|
||||||
|
else_branch: inner
|
||||||
|
.next()
|
||||||
|
.map(Expression::try_from)
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.map(Box::new))
|
||||||
|
.get_map(|v| { Some(Box::new(v)) }),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::while_stmt => ast_expr!(Statement::While(inner.next().unwrap().try_into())),
|
||||||
|
|
||||||
|
Rule::loop_stmt => ast_expr!(Statement::Loop(inner.next().unwrap().try_into())),
|
||||||
|
|
||||||
|
Rule::c_for_stmt => ast_expr!(Statement::CStyleFor {
|
||||||
|
init: inner.next().unwrap().try_into(),
|
||||||
|
condition: inner.next().unwrap().try_into(),
|
||||||
|
update: inner.next().unwrap().try_into(),
|
||||||
|
body: inner.next().unwrap().try_into(),
|
||||||
|
}),
|
||||||
|
|
||||||
|
Rule::for_stmt => ast_expr!(Statement::For {
|
||||||
|
mutable: Ok(listen_rule(&mut inner, Rule::mutable)) as AstResult<'_, bool>,
|
||||||
|
pattern: inner.next().unwrap().try_into(),
|
||||||
|
iterator: inner.next().unwrap().try_into(),
|
||||||
|
body: inner.next().unwrap().try_into().map(Box::new),
|
||||||
|
}),
|
||||||
|
|
||||||
|
Rule::match_stmt => ast_expr!(Statement::Match(
|
||||||
|
inner.next().unwrap().try_into(),
|
||||||
|
inner
|
||||||
|
.map(|match_itms| {
|
||||||
|
let mut match_inner = match_itms.into_inner();
|
||||||
|
Ok((
|
||||||
|
collect_recovered(match_inner.next().unwrap().into_inner()).get()?,
|
||||||
|
Expression::try_from(match_inner.next().unwrap()).get()?,
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.collect::<AstResult<'a, Vec<_>>>(),
|
||||||
|
)),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
ast_ensure, ast_expr,
|
||||||
|
error::{AstError, GetLength, IntoErr, collect_recovered},
|
||||||
|
parser::{consume_rule, listen_rule},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypePostfix {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::ref_type => {
|
||||||
|
let mutable = listen_rule(&mut inner, Rule::mutable);
|
||||||
|
let lifetime = consume_rule(&mut inner, Rule::lifetime)
|
||||||
|
.map(|pair| Identifier::try_from(pair.into_inner().next().unwrap()))
|
||||||
|
.transpose()
|
||||||
|
.get()?;
|
||||||
|
|
||||||
|
Ok(if mutable {
|
||||||
|
if let Some(lifetime) = lifetime {
|
||||||
|
TypePostfix::RefMutLifetime(lifetime)
|
||||||
|
} else {
|
||||||
|
TypePostfix::RefMut
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(lifetime) = lifetime {
|
||||||
|
TypePostfix::RefLifetime(lifetime)
|
||||||
|
} else {
|
||||||
|
TypePostfix::Ref
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::dyn_type => Ok(TypePostfix::Dyn),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypeExprKind {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::tuple_type => ast_expr!(TypeExprKind::Tuple(collect_recovered(inner))),
|
||||||
|
Rule::path_type => {
|
||||||
|
let path = Path::try_from(inner.next().unwrap());
|
||||||
|
let params = collect_recovered(inner);
|
||||||
|
|
||||||
|
if params.len() == 0 {
|
||||||
|
ast_expr!(TypeExprKind::Path(path))
|
||||||
|
} else {
|
||||||
|
ast_expr!(TypeExprKind::PathParams(path, params))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypeExpr {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::type_expr => ast_expr!(TypeExpr(
|
||||||
|
inner.next().unwrap().try_into(),
|
||||||
|
collect_recovered(inner),
|
||||||
|
)),
|
||||||
|
Rule::type_expr_param => Self::try_from(inner.next().unwrap()),
|
||||||
|
Rule::lifetime => ast_expr!(TypeExprKind::Lifetime(inner.next().unwrap().try_into()))
|
||||||
|
.get_map(TypeExpr::no_px)
|
||||||
|
.map(TypeExpr::no_px),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for GenericsDecl {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
ast_ensure!(pair, Rule::generics_decl => {
|
||||||
|
ast_expr!(GenericsDecl(collect_recovered(inner)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for GenericDecl {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
ast_ensure!(pair, Rule::generic_decl => {
|
||||||
|
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
|
||||||
|
ast_expr!(GenericDecl::Lifetime(
|
||||||
|
pair.into_inner().next().unwrap().try_into(),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
ast_expr!(GenericDecl::Type(
|
||||||
|
inner.next().unwrap().try_into(),
|
||||||
|
collect_recovered(inner),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Generics {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
ast_ensure!(pair, Rule::generics => {
|
||||||
|
ast_expr!(Generics(collect_recovered(inner)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Generic {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
ast_ensure!(pair, Rule::generic => {
|
||||||
|
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
|
||||||
|
ast_expr!(Generic::Lifetime(
|
||||||
|
pair.into_inner().next().unwrap().try_into(),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
ast_expr!(Generic::Type(
|
||||||
|
inner.next().unwrap().try_into()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
error::{AstError, IntoErr, collect_recovered},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Attribute {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
match pair.as_rule() {
|
||||||
|
Rule::attribute => {
|
||||||
|
// unwrap #[ ... ]
|
||||||
|
Attribute::try_from(pair.into_inner().next().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::meta => {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
// first item is always the path
|
||||||
|
let path = inner.next().unwrap().try_into().get()?;
|
||||||
|
|
||||||
|
// check what comes next
|
||||||
|
match inner.next() {
|
||||||
|
None => {
|
||||||
|
// #[path]
|
||||||
|
Ok(Attribute::Path(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(next) => match next.as_rule() {
|
||||||
|
Rule::primary => {
|
||||||
|
// #[path = literal]
|
||||||
|
Ok(Attribute::NameValue {
|
||||||
|
path,
|
||||||
|
value: inner.next().unwrap().try_into().get()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::meta_list => {
|
||||||
|
// #[path(...)]
|
||||||
|
Ok(Attribute::List {
|
||||||
|
path,
|
||||||
|
items: collect_recovered(next.into_inner()).get()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => unreachable!("unexpected rule in meta: {:?}", next.as_rule()),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::meta_list => {
|
||||||
|
// This case usually won't be hit directly,
|
||||||
|
// but it's nice to keep it safe if reused
|
||||||
|
let items = pair
|
||||||
|
.into_inner()
|
||||||
|
.map(Attribute::try_from)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
// NOTE: this shouldn't normally construct an Attribute alone
|
||||||
|
// but you can panic or wrap depending on your design
|
||||||
|
panic!("meta_list should be handled inside meta: {:?}", items);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => unreachable!("unexpected rule: {:?}", pair.as_rule()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
error::{AstError, IntoErr},
|
||||||
|
parser::consume_rule,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ClassConstructor {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
visibility: Visibility::try_from(&mut inner).get()?,
|
||||||
|
|
||||||
|
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.get()?
|
||||||
|
.unwrap_or_default(),
|
||||||
|
|
||||||
|
params: consume_rule(&mut inner, Rule::param_list)
|
||||||
|
.map(ParamList::try_from)
|
||||||
|
.transpose()
|
||||||
|
.get()?
|
||||||
|
.unwrap_or_default(),
|
||||||
|
|
||||||
|
body: inner.next().unwrap().try_into().get()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ClassItem {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::impl_decl | Rule::impl_for_decl => {
|
||||||
|
Ok(ClassItem::ImplDecl(pair.try_into().get()?))
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::method => Ok(ClassItem::Method(pair.try_into().get()?)),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
error::{AstError, IntoErr, collect_recovered},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for EnumItem {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::enum_named => Ok(EnumItem::Named(inner.next().unwrap().try_into().get()?)),
|
||||||
|
|
||||||
|
Rule::enum_tuple => Ok(EnumItem::Tuple(
|
||||||
|
inner.next().unwrap().try_into().get()?,
|
||||||
|
collect_recovered(inner.next().unwrap().into_inner()).get()?,
|
||||||
|
)),
|
||||||
|
|
||||||
|
Rule::enum_struct => Ok(EnumItem::Struct(
|
||||||
|
inner.next().unwrap().try_into().get()?,
|
||||||
|
inner
|
||||||
|
.next()
|
||||||
|
.map(|pair| collect_recovered::<FieldDecl, FieldDecl>(pair.into_inner()))
|
||||||
|
.transpose()
|
||||||
|
.get()?
|
||||||
|
.unwrap_or_default(),
|
||||||
|
)),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
ast_ensure, ast_expr,
|
||||||
|
error::{AstError, AstResult, IntoErr, collect_recovered},
|
||||||
|
parser::{consume_rule, listen_rule},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
ast_ensure!(pair, Rule::function_decl, Rule::method, Rule::method_no_body => {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
let visibility = Visibility::try_from(&mut inner);
|
||||||
|
let return_type = TypeExpr::try_from(inner.next().unwrap());
|
||||||
|
let name = Identifier::try_from(inner.next().unwrap());
|
||||||
|
|
||||||
|
let generics = consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.unwrap_or_default());
|
||||||
|
|
||||||
|
let self_param = consume_rule(&mut inner, Rule::self_param).map(|param| {
|
||||||
|
let mut param_inner = param.into_inner();
|
||||||
|
let name = Pattern::Id(Identifier(String::from("self")));
|
||||||
|
|
||||||
|
let mutable = listen_rule(&mut param_inner, Rule::mutable);
|
||||||
|
|
||||||
|
let is_ref = listen_rule(&mut param_inner, Rule::deref_px);
|
||||||
|
|
||||||
|
VarDecl {
|
||||||
|
mutable: mutable && !is_ref,
|
||||||
|
name: name.clone(),
|
||||||
|
type_: Some(TypeExpr(
|
||||||
|
TypeExprKind::Path(Path(vec![Identifier("Self".to_string())])),
|
||||||
|
if is_ref {
|
||||||
|
vec![if mutable {
|
||||||
|
TypePostfix::RefMut
|
||||||
|
} else {
|
||||||
|
TypePostfix::Ref
|
||||||
|
}]
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let params = consume_rule(&mut inner, Rule::param_list)
|
||||||
|
.map({
|
||||||
|
let self_param = self_param.clone();
|
||||||
|
|params_pair| -> AstResult<'a, ParamList> {
|
||||||
|
let mut params = ParamList::try_from(params_pair)?;
|
||||||
|
if let Some(x) = self_param {
|
||||||
|
params.0.insert(0, x);
|
||||||
|
}
|
||||||
|
Ok(params)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| Ok(ParamList(self_param.into_iter().collect())));
|
||||||
|
|
||||||
|
let body = inner.next().map(Block::try_from).transpose();
|
||||||
|
|
||||||
|
ast_expr!(Self {
|
||||||
|
visibility: visibility,
|
||||||
|
return_type: return_type,
|
||||||
|
name: name,
|
||||||
|
generics: generics,
|
||||||
|
params: params,
|
||||||
|
body: body,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ParamList {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
Ok(ParamList(collect_recovered(pair.into_inner()).get()?))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
error::{AstError, IntoErr, collect_recovered},
|
||||||
|
parser::consume_rule,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ImplDecl {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::impl_for_decl => Ok(ImplDecl {
|
||||||
|
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.get()?
|
||||||
|
.unwrap_or_default(),
|
||||||
|
trait_: Some(inner.next().unwrap().try_into().get()?),
|
||||||
|
target: inner.next().unwrap().try_into().get()?,
|
||||||
|
methods: collect_recovered(inner).get()?,
|
||||||
|
}),
|
||||||
|
|
||||||
|
Rule::impl_decl => Ok(ImplDecl {
|
||||||
|
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.get()?
|
||||||
|
.unwrap_or_default(),
|
||||||
|
trait_: None,
|
||||||
|
target: inner.next().unwrap().try_into().get()?,
|
||||||
|
methods: collect_recovered(inner).get()?,
|
||||||
|
}),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
pub mod attribute;
|
||||||
|
pub mod class;
|
||||||
|
pub mod enums;
|
||||||
|
pub mod function;
|
||||||
|
pub mod impl_decl;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
Rule,
|
||||||
|
ast::*,
|
||||||
|
ast_expr,
|
||||||
|
error::{AstError, IntoErr, collect_recovered},
|
||||||
|
parser::consume_rule,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevel {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
let attributes = collect_recovered(inner.next().unwrap().into_inner());
|
||||||
|
|
||||||
|
ast_expr!(TopLevel(
|
||||||
|
inner.next().map(Spanned::try_from).unwrap(),
|
||||||
|
attributes,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let rule = pair.as_rule();
|
||||||
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
|
match rule {
|
||||||
|
Rule::import => ast_expr!(TopLevelKind::Import(
|
||||||
|
Visibility::try_from(&mut inner),
|
||||||
|
Path::try_from(inner.next().unwrap()),
|
||||||
|
)),
|
||||||
|
|
||||||
|
Rule::function_decl => ast_expr!(TopLevelKind::FunctionDecl(pair.try_into())),
|
||||||
|
|
||||||
|
Rule::struct_decl => ast_expr!(TopLevelKind::StructDecl {
|
||||||
|
visibility: Visibility::try_from(&mut inner),
|
||||||
|
|
||||||
|
name: inner.next().unwrap().try_into(),
|
||||||
|
|
||||||
|
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.unwrap_or_default()),
|
||||||
|
|
||||||
|
fields: inner
|
||||||
|
.next()
|
||||||
|
.map(|pair| collect_recovered(pair.into_inner()))
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.unwrap_or_default()),
|
||||||
|
}),
|
||||||
|
|
||||||
|
Rule::class_decl => ast_expr!(TopLevelKind::ClassDecl {
|
||||||
|
visibility: Visibility::try_from(&mut inner),
|
||||||
|
|
||||||
|
name: inner.next().unwrap().try_into(),
|
||||||
|
|
||||||
|
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.unwrap_or_default()),
|
||||||
|
|
||||||
|
fields: collect_recovered(inner.next().unwrap().into_inner()),
|
||||||
|
|
||||||
|
constructor: inner.next().unwrap().try_into(),
|
||||||
|
|
||||||
|
items: collect_recovered(inner),
|
||||||
|
}),
|
||||||
|
|
||||||
|
Rule::enum_decl => ast_expr!(TopLevelKind::EnumDecl {
|
||||||
|
visibility: Visibility::try_from(&mut inner),
|
||||||
|
|
||||||
|
name: inner.next().unwrap().try_into(),
|
||||||
|
|
||||||
|
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.unwrap_or_default()),
|
||||||
|
|
||||||
|
fields: collect_recovered(inner),
|
||||||
|
}),
|
||||||
|
|
||||||
|
Rule::mod_package => ast_expr!(TopLevelKind::Mod(
|
||||||
|
Visibility::try_from(&mut inner),
|
||||||
|
inner.next().unwrap().try_into(),
|
||||||
|
)),
|
||||||
|
|
||||||
|
Rule::impl_for_decl | Rule::impl_decl => {
|
||||||
|
ast_expr!(TopLevelKind::ImplDecl(pair.try_into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::trait_decl => ast_expr!(TopLevelKind::TraitDecl {
|
||||||
|
visibility: Visibility::try_from(&mut inner),
|
||||||
|
|
||||||
|
name: inner.next().unwrap().try_into(),
|
||||||
|
|
||||||
|
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||||
|
.map(GenericsDecl::try_from)
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.unwrap_or_default()),
|
||||||
|
|
||||||
|
requirements: consume_rule(&mut inner, Rule::trait_requirements)
|
||||||
|
.map(|pair| collect_recovered(pair.into_inner()))
|
||||||
|
.transpose()
|
||||||
|
.map(|v| v.unwrap_or_default()),
|
||||||
|
|
||||||
|
items: collect_recovered(&mut inner),
|
||||||
|
}),
|
||||||
|
|
||||||
|
_ => AstError::bug_unimplemented(pair),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
pub mod common;
|
||||||
|
pub mod items;
|
||||||
|
|
||||||
|
use crate::{Rule, ast::Spanned, error::AstError};
|
||||||
|
|
||||||
|
pub fn listen_rule(pairs: &mut pest::iterators::Pairs<'_, Rule>, rule: Rule) -> bool {
|
||||||
|
let consumed = pairs
|
||||||
|
.peek()
|
||||||
|
.map(|p| p.as_rule() == rule)
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if consumed {
|
||||||
|
pairs.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
consumed
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn consume_rule<'a>(
|
||||||
|
pairs: &mut pest::iterators::Pairs<'a, Rule>,
|
||||||
|
rule: Rule,
|
||||||
|
) -> Option<pest::iterators::Pair<'a, Rule>> {
|
||||||
|
let consumed = pairs
|
||||||
|
.peek()
|
||||||
|
.map(|p| p.as_rule() == rule)
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if consumed { pairs.next() } else { None }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: TryFrom<pest::iterators::Pair<'a, Rule>, Error = AstError<'a, T>>>
|
||||||
|
TryFrom<pest::iterators::Pair<'a, Rule>> for Spanned<T>
|
||||||
|
{
|
||||||
|
type Error = AstError<'a, Self>;
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
let span = pair.as_span().start_pos().line_col();
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
line: span.0,
|
||||||
|
column: span.1,
|
||||||
|
item: pair.try_into().map_err(|err: AstError<'_, T>| AstError {
|
||||||
|
span: err.span,
|
||||||
|
error_code: err.error_code,
|
||||||
|
error_message: err.error_message,
|
||||||
|
recovered: err.recovered.map(|v| Spanned {
|
||||||
|
line: span.0,
|
||||||
|
column: span.1,
|
||||||
|
item: v,
|
||||||
|
}),
|
||||||
|
})?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
|
||||||
|
|
||||||
|
integer = @{ ASCII_DIGIT+ }
|
||||||
|
|
||||||
|
map = { "/*" ~ integer ~ ":" ~ integer ~ "*/" }
|
||||||
|
|
||||||
|
non_map = { (!map ~ ANY)+ }
|
||||||
|
|
||||||
|
mapping = { SOI ~ (map | non_map)* ~ EOI }
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use pest::Parser;
|
||||||
|
use pest_derive::Parser;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[grammar = "./src/rev_mapper/grammar.pest"]
|
||||||
|
pub struct MistMapperParser;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct MistMap(pub usize, pub usize);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct RustMap(pub usize, pub usize);
|
||||||
|
|
||||||
|
pub fn get_mapping(input: &str) -> HashSet<(RustMap, MistMap)> {
|
||||||
|
let mut mapping = HashSet::new();
|
||||||
|
|
||||||
|
let pairs = MistMapperParser::parse(Rule::mapping, input)
|
||||||
|
.unwrap()
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.into_inner();
|
||||||
|
|
||||||
|
for pair in pairs {
|
||||||
|
if pair.as_rule() == Rule::map {
|
||||||
|
let rs = pair.as_span().start_pos().line_col();
|
||||||
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
|
let (line, col) = (
|
||||||
|
inner.next().unwrap().as_str().parse().unwrap(),
|
||||||
|
inner.next().unwrap().as_str().parse().unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
mapping.insert((RustMap(rs.0, rs.1), MistMap(line, col)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mapping
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_mapping(
|
||||||
|
mapping: &HashSet<(RustMap, MistMap)>,
|
||||||
|
target: &RustMap,
|
||||||
|
) -> Option<(RustMap, MistMap)> {
|
||||||
|
mapping
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.filter(|(rust, _)| rust <= target)
|
||||||
|
.max_by_key(|(rust, _)| *rust)
|
||||||
|
}
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mist-test"
|
||||||
|
version = "0.1.0"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "mist-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "main"
|
||||||
|
path = ".mist/src/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
use <super::task>;
|
||||||
|
use <super::logger>;
|
||||||
|
use <super::event>;
|
||||||
|
|
||||||
|
pub class Application {
|
||||||
|
String name;
|
||||||
|
|
||||||
|
Vec<task::Task> tasks;
|
||||||
|
Vec<String> plugins;
|
||||||
|
|
||||||
|
logger::Logger logger;
|
||||||
|
|
||||||
|
bool running;
|
||||||
|
i32 ticks;
|
||||||
|
|
||||||
|
pub constructor(str* name) {
|
||||||
|
self.name = name.to_string();
|
||||||
|
self.tasks = new Vec();
|
||||||
|
self.plugins = new Vec();
|
||||||
|
|
||||||
|
self.logger = new logger::Logger("app");
|
||||||
|
|
||||||
|
self.running = false;
|
||||||
|
self.ticks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void boot(self mut*) {
|
||||||
|
self.logger.info("booting application");
|
||||||
|
|
||||||
|
self.running = true;
|
||||||
|
|
||||||
|
self.emit(event::Event::Startup);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void run(self mut*) {
|
||||||
|
while(self.running) {
|
||||||
|
self.tick();
|
||||||
|
|
||||||
|
if(self.ticks >= 5) {
|
||||||
|
self.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick(self mut*) {
|
||||||
|
self.logger.info("tick");
|
||||||
|
|
||||||
|
self.ticks++;
|
||||||
|
|
||||||
|
var task = task::create_task("background-job");
|
||||||
|
|
||||||
|
self.tasks.push(task);
|
||||||
|
|
||||||
|
println!("tasks: {}", self.tasks.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void shutdown(self mut*) {
|
||||||
|
self.emit(event::Event::Shutdown);
|
||||||
|
|
||||||
|
self.logger.warning("shutdown");
|
||||||
|
|
||||||
|
self.running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void register_plugin(self mut*, String name) {
|
||||||
|
self.plugins.push(name.clone());
|
||||||
|
|
||||||
|
self.emit(event::Event::PluginLoaded(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
void emit(self*, event::Event event) {
|
||||||
|
match(event) {
|
||||||
|
event::Event::Startup => {
|
||||||
|
self.logger.info("startup event");
|
||||||
|
}
|
||||||
|
|
||||||
|
event::Event::Shutdown => {
|
||||||
|
self.logger.info("shutdown event");
|
||||||
|
}
|
||||||
|
|
||||||
|
event::Event::PluginLoaded[name] => {
|
||||||
|
println!("plugin loaded: {}", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
event::Event::TaskExecuted[name] => {
|
||||||
|
println!("task executed: {}", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
event::Event::Error[message] => {
|
||||||
|
self.logger.error(&message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 test_stmt() {
|
||||||
|
if (0 == 0) {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loops_test() {
|
||||||
|
for (x : 0..10) {
|
||||||
|
println!("{x}");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var mut i = 0; i < 10; i++) {
|
||||||
|
println!("{i}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
|
||||||
|
while (i == 1) {
|
||||||
|
println!("hi");
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
println!("loop!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pub enum Event {
|
||||||
|
Startup,
|
||||||
|
Shutdown,
|
||||||
|
TaskExecuted(String),
|
||||||
|
PluginLoaded(String),
|
||||||
|
Error(String),
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
use <std::fmt::Formatter>;
|
||||||
|
use <std::fmt>;
|
||||||
|
|
||||||
|
pub trait TestLogging<T: fmt::Display>: fmt::Display {
|
||||||
|
String get(self*);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum LogLevel {
|
||||||
|
Info,
|
||||||
|
Warning,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for LogLevel {
|
||||||
|
fmt::Result fmt(self*, Formatter<'_> mut* f) {
|
||||||
|
match (self) {
|
||||||
|
LogLevel::Info => write!(f, "[INFO]");
|
||||||
|
|
||||||
|
LogLevel::Warning => write!(f, "[WARN]");
|
||||||
|
|
||||||
|
LogLevel::Error => write!(f, "[ERROR]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestLogging<LogLevel> for LogLevel {
|
||||||
|
String get(self*) {
|
||||||
|
return format!("{self}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub class Logger {
|
||||||
|
String prefix;
|
||||||
|
|
||||||
|
pub constructor(str* prefix) {
|
||||||
|
self.prefix = prefix.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void info(self*, str* message) {
|
||||||
|
self.log(LogLevel::Info, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void warning(self*, str* message) {
|
||||||
|
self.log(LogLevel::Warning, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void error(self*, str* message) {
|
||||||
|
self.log(LogLevel::Error, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(self*, LogLevel level, str* message) {
|
||||||
|
match(level) {
|
||||||
|
LogLevel::Info => {
|
||||||
|
println!("{level} {} {}", self.prefix, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
LogLevel::Warning => {
|
||||||
|
println!("{} {} {}", level.get(), self.prefix, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
LogLevel::Error => {
|
||||||
|
println!("{level} {} {}", self.prefix, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display {
|
||||||
|
fmt::Result fmt(self*, Formatter<'_> mut* f) {
|
||||||
|
write!(f, "logger ({})", self.prefix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
pub mod app;
|
||||||
|
pub mod task;
|
||||||
|
pub mod plugin;
|
||||||
|
pub mod logger;
|
||||||
|
pub mod event;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
var mut app_instance = new app::Application("mist-app");
|
||||||
|
|
||||||
|
app_instance.boot();
|
||||||
|
app_instance.run();
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
pub struct PluginInfo {
|
||||||
|
pub String name,
|
||||||
|
pub String version,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub class PluginRegistry<T> {
|
||||||
|
T plugins;
|
||||||
|
|
||||||
|
pub constructor(T plugins) {
|
||||||
|
self.plugins = plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub T plugins(self) {
|
||||||
|
return self.plugins;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
pub enum TaskState {
|
||||||
|
Pending,
|
||||||
|
Running,
|
||||||
|
Finished,
|
||||||
|
Failed,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Task {
|
||||||
|
pub String name,
|
||||||
|
pub TaskState state,
|
||||||
|
pub i32 executions,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub Task create_task(str* name) {
|
||||||
|
Task {
|
||||||
|
name: name.to_string(),
|
||||||
|
state: TaskState::Pending,
|
||||||
|
executions: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "parser"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
pest = "2.8.6"
|
|
||||||
pest_derive = "2.8.6"
|
|
||||||
serde = { version = "1.0.228", features = ["serde_derive"] }
|
|
||||||
serde_json = "1.0.149"
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct FieldList(pub Vec<(String, Visibility, TypeExpr)>);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct ParamList(pub Vec<VarDecl>);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct Block(pub Vec<Statement>);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum TypePostfix {
|
|
||||||
Ref,
|
|
||||||
RefMut,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum Visibility {
|
|
||||||
Public,
|
|
||||||
Private,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum Attribute {
|
|
||||||
/// #[test]
|
|
||||||
Path(Path),
|
|
||||||
|
|
||||||
/// #[name = "value"]
|
|
||||||
NameValue { path: Path, value: Literal },
|
|
||||||
|
|
||||||
/// #[derive(Clone, Copy)]
|
|
||||||
List { path: Path, items: Vec<Attribute> },
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum TypeExprKind {
|
|
||||||
Path(Path),
|
|
||||||
PathParams(Path, Vec<TypeExpr>),
|
|
||||||
Tuple(Vec<TypeExpr>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct TypeExpr(pub TypeExprKind, pub Vec<TypePostfix>);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct Path(pub Vec<String>);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum BinaryOp {
|
|
||||||
Plus,
|
|
||||||
Minus,
|
|
||||||
Multiply,
|
|
||||||
Divide,
|
|
||||||
Modulo,
|
|
||||||
Equal,
|
|
||||||
NotEqual,
|
|
||||||
LessThan,
|
|
||||||
GreaterThan,
|
|
||||||
LessThanOrEqual,
|
|
||||||
GreaterThanOrEqual,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct TopLevel(pub TopLevelKind, pub Vec<Attribute>);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum TopLevelKind {
|
|
||||||
ModAttribute,
|
|
||||||
Include(Path),
|
|
||||||
StructDecl {
|
|
||||||
visibility: Visibility,
|
|
||||||
name: String,
|
|
||||||
fields: FieldList,
|
|
||||||
},
|
|
||||||
FunctionDecl(FunctionDecl),
|
|
||||||
ClassDecl {
|
|
||||||
visibility: Visibility,
|
|
||||||
name: String,
|
|
||||||
fields: Vec<VarDeclStmt>,
|
|
||||||
constructor: ClassConstructor,
|
|
||||||
methods: Vec<FunctionDecl>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct ClassConstructor {
|
|
||||||
pub visibility: Visibility,
|
|
||||||
pub params: ParamList,
|
|
||||||
pub body: Block,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct FunctionDecl {
|
|
||||||
pub visibility: Visibility,
|
|
||||||
pub name: String,
|
|
||||||
pub params: ParamList,
|
|
||||||
pub return_type: TypeExpr,
|
|
||||||
pub body: Block,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum Postfix {
|
|
||||||
FieldAccess(String),
|
|
||||||
Call(Vec<Expression>),
|
|
||||||
MacroCall(String),
|
|
||||||
StructCall(Vec<(String, Expression)>),
|
|
||||||
Index(Expression),
|
|
||||||
Binary(BinaryOp, Expression),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum Prefix {
|
|
||||||
Ref,
|
|
||||||
RefMut,
|
|
||||||
Deref,
|
|
||||||
New,
|
|
||||||
Not,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum Statement {
|
|
||||||
Expression(Expression),
|
|
||||||
Block(Block),
|
|
||||||
|
|
||||||
VarDecl(VarDeclStmt),
|
|
||||||
VarAssign(VarAssignStmt),
|
|
||||||
If {
|
|
||||||
initial: StatementBranch,
|
|
||||||
else_if: Vec<StatementBranch>,
|
|
||||||
else_branch: Option<Box<Statement>>,
|
|
||||||
},
|
|
||||||
While(StatementBranch),
|
|
||||||
CStyleFor {
|
|
||||||
init: Box<Statement>,
|
|
||||||
condition: Expression,
|
|
||||||
update: Box<Statement>,
|
|
||||||
body: Box<Statement>,
|
|
||||||
},
|
|
||||||
For {
|
|
||||||
pattern: String,
|
|
||||||
iterator: Expression,
|
|
||||||
body: Box<Statement>,
|
|
||||||
},
|
|
||||||
|
|
||||||
Return(Option<Expression>),
|
|
||||||
Break,
|
|
||||||
Continue,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct VarDecl {
|
|
||||||
pub mutable: bool,
|
|
||||||
pub name: String,
|
|
||||||
pub type_: Option<TypeExpr>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct VarDeclStmt {
|
|
||||||
pub decl: VarDecl,
|
|
||||||
pub init: Option<Expression>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct VarAssignStmt {
|
|
||||||
pub target: Expression,
|
|
||||||
pub value: Expression,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct StatementBranch {
|
|
||||||
pub condition: Expression,
|
|
||||||
pub body: Box<Statement>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum Expression {
|
|
||||||
Literal(Literal),
|
|
||||||
Path(Path),
|
|
||||||
Fix {
|
|
||||||
initial: Box<Expression>,
|
|
||||||
prefixes: Vec<Prefix>,
|
|
||||||
postfixes: Vec<Postfix>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum Literal {
|
|
||||||
String(String),
|
|
||||||
Int(i64),
|
|
||||||
Float(f64),
|
|
||||||
Bool(bool),
|
|
||||||
Tuple(Vec<Expression>),
|
|
||||||
}
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
|
|
||||||
COMMENT = _{ "//" ~ (!"\n" ~ ANY)* }
|
|
||||||
|
|
||||||
program = { SOI ~ top_level* ~ EOI }
|
|
||||||
|
|
||||||
// primitives
|
|
||||||
identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
|
|
||||||
integer = @{ ASCII_DIGIT+ }
|
|
||||||
float = @{ ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+ }
|
|
||||||
boolean = { "true" | "false" }
|
|
||||||
string_lit = { "\"" ~ inner_str ~ "\"" }
|
|
||||||
inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* }
|
|
||||||
static_path = { identifier ~ ("::" ~ identifier)* }
|
|
||||||
|
|
||||||
export = { "public" }
|
|
||||||
mutable = { "mut" }
|
|
||||||
sharp = _{ "#" }
|
|
||||||
var = { "var" }
|
|
||||||
var_decl = { (var | type_expr) ~ mutable? ~ identifier }
|
|
||||||
semicolon = _{ ";" }
|
|
||||||
|
|
||||||
// ================= CLASS =================
|
|
||||||
class_constructor = {
|
|
||||||
export? ~ "constructor" ~ "(" ~ param_list? ~ ")" ~ block
|
|
||||||
}
|
|
||||||
|
|
||||||
class_fields = { var_decl_statement* }
|
|
||||||
|
|
||||||
self_param = { "self" ~ mutable? ~ deref_px? }
|
|
||||||
|
|
||||||
method = {
|
|
||||||
export? ~ type_expr ~ identifier ~ "(" ~ self_param? ~ param_list? ~ ")" ~ block
|
|
||||||
}
|
|
||||||
|
|
||||||
class_decl = {
|
|
||||||
"class" ~ identifier ~ "{" ~ class_fields ~ class_constructor ~ method* ~ "}"
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================= TOP LEVEL =================
|
|
||||||
|
|
||||||
top_level = { (attributes ~ (import | function_decl | struct_decl | class_decl)) | mod_attribute }
|
|
||||||
|
|
||||||
attribute = {
|
|
||||||
"#" ~ "[" ~ meta ~ "]"
|
|
||||||
}
|
|
||||||
|
|
||||||
mod_attribute = {
|
|
||||||
"#" ~ "!" ~ "[" ~ meta ~ "]"
|
|
||||||
}
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
static_path ~ ("=" ~ primary | "(" ~ meta_list? ~ ")")?
|
|
||||||
}
|
|
||||||
|
|
||||||
meta_list = {
|
|
||||||
meta ~ ("," ~ meta)* ~ ","?
|
|
||||||
}
|
|
||||||
|
|
||||||
attributes = { attribute* }
|
|
||||||
|
|
||||||
import = { sharp ~ "include" ~ "<" ~ static_path ~ ">" }
|
|
||||||
|
|
||||||
field_list = { field ~ ("," ~ field)* ~ ","? }
|
|
||||||
field = { export? ~ type_expr ~ identifier }
|
|
||||||
|
|
||||||
param_list = { var_decl ~ ("," ~ var_decl)* ~ ","? }
|
|
||||||
|
|
||||||
struct_decl = {
|
|
||||||
export? ~ "struct" ~ identifier ~ "{" ~ field_list? ~ "}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function_decl = {
|
|
||||||
export? ~ type_expr ~ identifier ~ "(" ~ param_list? ~ ")" ~ block
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================= STATEMENTS =================
|
|
||||||
|
|
||||||
block = { "{" ~ statement_list ~ "}" }
|
|
||||||
|
|
||||||
statement_list = { statement* }
|
|
||||||
|
|
||||||
statement = _{
|
|
||||||
expr_stmt
|
|
||||||
| var_decl_statement
|
|
||||||
| assign_statement
|
|
||||||
| if_stmt
|
|
||||||
| while_stmt
|
|
||||||
| c_for_stmt
|
|
||||||
| for_stmt
|
|
||||||
| return_stmt
|
|
||||||
| break_stmt
|
|
||||||
| continue_stmt
|
|
||||||
| block
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- basic statements ---
|
|
||||||
|
|
||||||
expr_stmt = { expr ~ semicolon }
|
|
||||||
|
|
||||||
return_stmt = { "return" ~ expr? ~ semicolon }
|
|
||||||
|
|
||||||
break_stmt = { "break" ~ semicolon }
|
|
||||||
|
|
||||||
continue_stmt = { "continue" ~ semicolon }
|
|
||||||
|
|
||||||
var_decl_statement = { var_decl ~ ("=" ~ expr)? ~ semicolon }
|
|
||||||
|
|
||||||
assign_statement = { expr ~ "=" ~ expr ~ semicolon }
|
|
||||||
|
|
||||||
else_if = { "else" ~ "if" ~ "(" ~ expr ~ ")" ~ statement }
|
|
||||||
|
|
||||||
else_if_list = { else_if* }
|
|
||||||
|
|
||||||
if_stmt = {
|
|
||||||
"if" ~ "(" ~ expr ~ ")" ~ statement ~ else_if_list ~ ("else" ~ statement)?
|
|
||||||
}
|
|
||||||
|
|
||||||
while_stmt = {
|
|
||||||
"while" ~ "(" ~ expr ~ ")" ~ statement
|
|
||||||
}
|
|
||||||
|
|
||||||
c_for_stmt = {
|
|
||||||
"for" ~ "(" ~ statement ~ expr ~ semicolon ~ statement ~ ")" ~ statement
|
|
||||||
}
|
|
||||||
|
|
||||||
for_stmt = {
|
|
||||||
"for" ~ "(" ~ identifier ~ "in" ~ expr ~ ")" ~ statement
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================= EXPRESSIONS =================
|
|
||||||
tuple_type = { "(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")" }
|
|
||||||
path_type = { static_path ~ ("<" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ">")? }
|
|
||||||
ref_type = { mutable? ~ "*" }
|
|
||||||
type_expr = { (path_type | tuple_type) ~ ref_type* }
|
|
||||||
|
|
||||||
macro_inner_v = {
|
|
||||||
"(" ~ macro_inner_v* ~ ")"
|
|
||||||
| (!("(" | ")") ~ ANY)
|
|
||||||
}
|
|
||||||
|
|
||||||
tuple = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
|
|
||||||
|
|
||||||
primary = {
|
|
||||||
float
|
|
||||||
| integer
|
|
||||||
| boolean
|
|
||||||
| string_lit
|
|
||||||
| static_path
|
|
||||||
| tuple
|
|
||||||
}
|
|
||||||
|
|
||||||
postfix = {
|
|
||||||
field_px
|
|
||||||
| call_px
|
|
||||||
| macro_call_px
|
|
||||||
| struct_px
|
|
||||||
| index_px
|
|
||||||
| binary_px
|
|
||||||
}
|
|
||||||
|
|
||||||
field_px = { "." ~ identifier }
|
|
||||||
call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
|
|
||||||
macro_call_px = { "!" ~ "(" ~ macro_inner_v* ~ ")" }
|
|
||||||
struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ ","? ~ "}" }
|
|
||||||
index_px = { "[" ~ expr ~ "]" }
|
|
||||||
binary_px = { bin_op ~ expr }
|
|
||||||
bin_op = { "<=" | ">=" | "==" | "!=" | "+" | "-" | "*" | "/" | "%" | "<" | ">" }
|
|
||||||
struct_field_decl = { identifier ~ ":" ~ expr }
|
|
||||||
|
|
||||||
prefix = {
|
|
||||||
deref_px
|
|
||||||
| mut_ref_px
|
|
||||||
| ref_px
|
|
||||||
| new_px
|
|
||||||
| not_px
|
|
||||||
}
|
|
||||||
|
|
||||||
deref_px = { "*" }
|
|
||||||
mut_ref_px = { "&" ~ mutable }
|
|
||||||
ref_px = { "&" }
|
|
||||||
new_px = { "new" }
|
|
||||||
not_px = { "!" }
|
|
||||||
|
|
||||||
prefix_list = { prefix* }
|
|
||||||
|
|
||||||
expr = {
|
|
||||||
prefix_list ~ primary ~ postfix*
|
|
||||||
}
|
|
||||||
@@ -1,610 +0,0 @@
|
|||||||
use pest::Parser;
|
|
||||||
use pest_derive::Parser;
|
|
||||||
|
|
||||||
pub mod ast;
|
|
||||||
|
|
||||||
use ast::*;
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
|
||||||
#[grammar = "./src/grammar.pest"]
|
|
||||||
pub struct MistParser;
|
|
||||||
|
|
||||||
// convenience alias for pest errors
|
|
||||||
pub type ParseError = pest::error::Error<Rule>;
|
|
||||||
|
|
||||||
pub fn parse(source: &str) -> Result<Vec<TopLevel>, ParseError> {
|
|
||||||
let mut pairs = MistParser::parse(Rule::program, source)?;
|
|
||||||
|
|
||||||
let mut statements = vec![];
|
|
||||||
|
|
||||||
for pair in pairs.next().unwrap().into_inner() {
|
|
||||||
if pair.as_rule() != Rule::EOI {
|
|
||||||
statements.push(TopLevel::from(pair));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(statements)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for TypeExpr {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::type_expr => TypeExpr(
|
|
||||||
TypeExprKind::from(inner.next().unwrap()),
|
|
||||||
inner.map(TypePostfix::from).collect(),
|
|
||||||
),
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let inner = pair.into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::ref_type => {
|
|
||||||
if inner.peek().is_some() {
|
|
||||||
TypePostfix::RefMut
|
|
||||||
} else {
|
|
||||||
TypePostfix::Ref
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for TypeExprKind {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::tuple_type => TypeExprKind::Tuple(inner.map(TypeExpr::from).collect()),
|
|
||||||
Rule::path_type => {
|
|
||||||
let path = Path::from(inner.next().unwrap());
|
|
||||||
let params = inner.map(TypeExpr::from).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
if params.len() == 0 {
|
|
||||||
TypeExprKind::Path(path)
|
|
||||||
} else {
|
|
||||||
TypeExprKind::PathParams(path, params)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Path {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::static_path => Path(pair.into_inner().map(|i| i.as_str().to_string()).collect()),
|
|
||||||
_ => unimplemented!("{pair:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for FieldList {
|
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
|
||||||
let params = pair
|
|
||||||
.into_inner()
|
|
||||||
.map(|p| {
|
|
||||||
let mut param_inner = p.into_inner();
|
|
||||||
let visibility = Visibility::from(&mut param_inner);
|
|
||||||
let param_type = TypeExpr::from(param_inner.next().unwrap());
|
|
||||||
let param_name = param_inner.next().unwrap().as_str().to_string();
|
|
||||||
(param_name, visibility, param_type)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
FieldList(params)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for ParamList {
|
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
|
||||||
ParamList(pair.into_inner().map(VarDecl::from).collect())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Attribute {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::attribute => {
|
|
||||||
// unwrap #[ ... ]
|
|
||||||
Attribute::from(pair.into_inner().next().unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::meta => {
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
// first item is always the path
|
|
||||||
let path = Path::from(inner.next().unwrap());
|
|
||||||
|
|
||||||
// check what comes next
|
|
||||||
match inner.next() {
|
|
||||||
None => {
|
|
||||||
// #[path]
|
|
||||||
Attribute::Path(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(next) => match next.as_rule() {
|
|
||||||
Rule::primary => {
|
|
||||||
// #[path = literal]
|
|
||||||
Attribute::NameValue {
|
|
||||||
path,
|
|
||||||
value: Literal::from(next),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::meta_list => {
|
|
||||||
// #[path(...)]
|
|
||||||
let items = next.into_inner().map(Attribute::from).collect();
|
|
||||||
|
|
||||||
Attribute::List { path, items }
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => unreachable!("unexpected rule in meta: {:?}", next.as_rule()),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::meta_list => {
|
|
||||||
// This case usually won't be hit directly,
|
|
||||||
// but it's nice to keep it safe if reused
|
|
||||||
let items = pair.into_inner().map(Attribute::from).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
// NOTE: this shouldn't normally construct an Attribute alone
|
|
||||||
// but you can panic or wrap depending on your design
|
|
||||||
panic!("meta_list should be handled inside meta: {:?}", items);
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => unreachable!("unexpected rule: {:?}", pair.as_rule()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for TopLevel {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
let attributes = inner
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.into_inner()
|
|
||||||
.map(Attribute::from)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
TopLevel(
|
|
||||||
inner
|
|
||||||
.next()
|
|
||||||
.map(TopLevelKind::from)
|
|
||||||
.unwrap_or(TopLevelKind::ModAttribute),
|
|
||||||
attributes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for StatementBranch {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
let condition = Expression::from(inner.next().unwrap());
|
|
||||||
let body = Statement::from(inner.next().unwrap());
|
|
||||||
|
|
||||||
StatementBranch {
|
|
||||||
condition,
|
|
||||||
body: Box::new(body),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for ClassConstructor {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
let visibility = Visibility::from(&mut inner);
|
|
||||||
|
|
||||||
let params = consume_rule(&mut inner, Rule::param_list)
|
|
||||||
.map(ParamList::from)
|
|
||||||
.unwrap_or_else(|| ParamList(Vec::new()));
|
|
||||||
|
|
||||||
Self {
|
|
||||||
visibility,
|
|
||||||
params,
|
|
||||||
body: Block::from(inner.next().unwrap()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let mut inner = pair.clone().into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::import => TopLevelKind::Include(Path::from(inner.next().unwrap())),
|
|
||||||
|
|
||||||
Rule::function_decl => TopLevelKind::FunctionDecl(FunctionDecl::from(pair)),
|
|
||||||
|
|
||||||
Rule::struct_decl => {
|
|
||||||
let visibility = Visibility::from(&mut inner);
|
|
||||||
let name = inner.next().unwrap().as_str().to_string();
|
|
||||||
let fields_pair = inner.next().unwrap();
|
|
||||||
let fields = FieldList::from(fields_pair);
|
|
||||||
|
|
||||||
TopLevelKind::StructDecl {
|
|
||||||
visibility,
|
|
||||||
name,
|
|
||||||
fields,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::class_decl => TopLevelKind::ClassDecl {
|
|
||||||
visibility: Visibility::from(&mut inner),
|
|
||||||
name: inner.next().unwrap().as_str().to_string(),
|
|
||||||
fields: inner
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.into_inner()
|
|
||||||
.map(VarDeclStmt::from)
|
|
||||||
.collect(),
|
|
||||||
constructor: ClassConstructor::from(inner.next().unwrap()),
|
|
||||||
methods: inner.into_iter().map(FunctionDecl::from).collect(),
|
|
||||||
},
|
|
||||||
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Block {
|
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
|
||||||
let statements = pair
|
|
||||||
.into_inner()
|
|
||||||
.flat_map(|pair| {
|
|
||||||
if pair.as_rule() == Rule::statement_list {
|
|
||||||
pair.into_inner().map(Statement::from).collect()
|
|
||||||
} else {
|
|
||||||
vec![Statement::from(pair)]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
Block(statements)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Statement {
|
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let mut inner = pair.clone().into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::statement => Statement::from(inner.next().unwrap()),
|
|
||||||
|
|
||||||
Rule::expr_stmt => Statement::Expression(Expression::from(inner.next().unwrap())),
|
|
||||||
|
|
||||||
Rule::block => Statement::Block(Block::from(inner.next().unwrap())),
|
|
||||||
|
|
||||||
Rule::var_decl_statement => Statement::VarDecl(VarDeclStmt::from(pair)),
|
|
||||||
|
|
||||||
Rule::return_stmt => {
|
|
||||||
let expr = inner.next().map(Expression::from);
|
|
||||||
|
|
||||||
Statement::Return(expr)
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::break_stmt => Statement::Break,
|
|
||||||
|
|
||||||
Rule::continue_stmt => Statement::Continue,
|
|
||||||
|
|
||||||
Rule::if_stmt => {
|
|
||||||
let mut inner = inner.skip(2);
|
|
||||||
|
|
||||||
Statement::If {
|
|
||||||
initial: pair.into(),
|
|
||||||
else_if: inner
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.into_inner()
|
|
||||||
.map(StatementBranch::from)
|
|
||||||
.collect(),
|
|
||||||
else_branch: inner.next().map(Statement::from).map(Box::new),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::while_stmt => Statement::While(pair.into()),
|
|
||||||
|
|
||||||
Rule::c_for_stmt => Statement::CStyleFor {
|
|
||||||
init: Box::new(Statement::from(inner.next().unwrap())),
|
|
||||||
condition: inner.next().unwrap().into(),
|
|
||||||
update: Box::new(Statement::from(inner.next().unwrap())),
|
|
||||||
body: Box::new(Statement::from(inner.next().unwrap())),
|
|
||||||
},
|
|
||||||
|
|
||||||
Rule::for_stmt => Statement::For {
|
|
||||||
pattern: inner.next().unwrap().as_str().to_string(),
|
|
||||||
iterator: inner.next().unwrap().into(),
|
|
||||||
body: Box::new(Statement::from(inner.next().unwrap())),
|
|
||||||
},
|
|
||||||
|
|
||||||
Rule::assign_statement => Statement::VarAssign(VarAssignStmt {
|
|
||||||
target: Expression::from(inner.next().unwrap()),
|
|
||||||
value: Expression::from(inner.next().unwrap()),
|
|
||||||
}),
|
|
||||||
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Literal {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let mut inner = pair.clone().into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::primary => Self::from(inner.next().unwrap()),
|
|
||||||
Rule::integer => Literal::Int(pair.as_str().parse::<i64>().unwrap()),
|
|
||||||
Rule::float => Literal::Float(pair.as_str().parse::<f64>().unwrap()),
|
|
||||||
Rule::boolean => Literal::Bool(pair.as_str().parse::<bool>().unwrap()),
|
|
||||||
Rule::string_lit => Literal::String(inner.as_str().to_string()),
|
|
||||||
Rule::tuple => Literal::Tuple(inner.map(Expression::from).collect()),
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Expression {
|
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let mut inner = pair.clone().into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::expr => {
|
|
||||||
let prefixes: Vec<Prefix> = inner
|
|
||||||
.next()
|
|
||||||
.map(|p| p.into_inner().into_iter().map(Prefix::from).collect())
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let exp = Expression::from(inner.next().unwrap());
|
|
||||||
|
|
||||||
if inner.len() > 0 || prefixes.len() > 0 {
|
|
||||||
Expression::Fix {
|
|
||||||
initial: Box::new(exp),
|
|
||||||
prefixes,
|
|
||||||
postfixes: inner.map(|p| Postfix::from(p)).collect(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
exp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rule::primary => Expression::from(inner.next().unwrap()),
|
|
||||||
Rule::static_path => Expression::Path(Path::from(pair)),
|
|
||||||
Rule::integer | Rule::float | Rule::boolean | Rule::string_lit | Rule::tuple => {
|
|
||||||
Expression::Literal(Literal::from(pair))
|
|
||||||
}
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Prefix {
|
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::prefix => Self::from(pair.into_inner().next().unwrap()),
|
|
||||||
Rule::deref_px => Self::Deref,
|
|
||||||
Rule::mut_ref_px => Self::RefMut,
|
|
||||||
Rule::ref_px => Self::Ref,
|
|
||||||
Rule::new_px => Self::New,
|
|
||||||
Rule::not_px => Self::Not,
|
|
||||||
_ => unimplemented!("{pair:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for Postfix {
|
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
|
||||||
let rule = pair.as_rule();
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
match rule {
|
|
||||||
Rule::postfix => Postfix::from(inner.next().unwrap()),
|
|
||||||
|
|
||||||
Rule::field_px => {
|
|
||||||
let field_name = inner.next().unwrap().as_str().to_string();
|
|
||||||
Postfix::FieldAccess(field_name)
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::call_px => Postfix::Call(inner.map(Expression::from).collect()),
|
|
||||||
|
|
||||||
Rule::struct_px => Postfix::StructCall(
|
|
||||||
inner
|
|
||||||
.map(|p| {
|
|
||||||
let mut pi = p.into_inner();
|
|
||||||
(
|
|
||||||
pi.next().unwrap().as_str().to_string(),
|
|
||||||
Expression::from(pi.next().unwrap()),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
|
|
||||||
Rule::index_px => Postfix::Index(Expression::from(inner.next().unwrap())),
|
|
||||||
|
|
||||||
Rule::binary_px => {
|
|
||||||
let op_pair = inner.next().unwrap();
|
|
||||||
let op = match op_pair.as_str() {
|
|
||||||
"+" => BinaryOp::Plus,
|
|
||||||
"-" => BinaryOp::Minus,
|
|
||||||
"*" => BinaryOp::Multiply,
|
|
||||||
"/" => BinaryOp::Divide,
|
|
||||||
"%" => BinaryOp::Modulo,
|
|
||||||
"==" => BinaryOp::Equal,
|
|
||||||
"!=" => BinaryOp::NotEqual,
|
|
||||||
"<" => BinaryOp::LessThan,
|
|
||||||
">" => BinaryOp::GreaterThan,
|
|
||||||
"<=" => BinaryOp::LessThanOrEqual,
|
|
||||||
">=" => BinaryOp::GreaterThanOrEqual,
|
|
||||||
|
|
||||||
_ => {
|
|
||||||
unimplemented!("Binary operator not implemented yet: {}", op_pair.as_str())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Postfix::Binary(op, Expression::from(inner.next().unwrap()))
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule::macro_call_px => Postfix::MacroCall(inner.as_str().to_string()),
|
|
||||||
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for VarDeclStmt {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::var_decl_statement => {
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
let decl = VarDecl::from(inner.next().unwrap());
|
|
||||||
|
|
||||||
let init = inner.next().map(Expression::from);
|
|
||||||
|
|
||||||
VarDeclStmt { decl, init }
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for VarDecl {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::var_decl => {
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
let type_ = inner.next().and_then(|pair| {
|
|
||||||
if pair.as_str().trim() == "var" {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(TypeExpr::from(pair))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let mutable = listen_rule(&mut inner, Rule::mutable);
|
|
||||||
|
|
||||||
let name = inner.next().unwrap().as_str().to_string();
|
|
||||||
|
|
||||||
VarDecl {
|
|
||||||
mutable,
|
|
||||||
name,
|
|
||||||
type_,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => unimplemented!("{:?}", pair.as_rule()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for FunctionDecl {
|
|
||||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
|
||||||
let mut inner = pair.into_inner();
|
|
||||||
|
|
||||||
let visibility = Visibility::from(&mut inner);
|
|
||||||
|
|
||||||
let return_type = TypeExpr::from(inner.next().unwrap());
|
|
||||||
|
|
||||||
let name = inner.next().unwrap().as_str().to_string();
|
|
||||||
let self_param = consume_rule(&mut inner, Rule::self_param).map(|param| {
|
|
||||||
let mut param_inner = param.into_inner();
|
|
||||||
let name = format!("self");
|
|
||||||
|
|
||||||
let mutable = listen_rule(&mut param_inner, Rule::mutable);
|
|
||||||
|
|
||||||
let is_ref = listen_rule(&mut param_inner, Rule::deref_px);
|
|
||||||
|
|
||||||
VarDecl {
|
|
||||||
mutable: mutable && !is_ref,
|
|
||||||
name,
|
|
||||||
type_: Some(TypeExpr(
|
|
||||||
TypeExprKind::Path(Path(vec![format!("Self")])),
|
|
||||||
if is_ref {
|
|
||||||
vec![if mutable {
|
|
||||||
TypePostfix::RefMut
|
|
||||||
} else {
|
|
||||||
TypePostfix::Ref
|
|
||||||
}]
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let params = consume_rule(&mut inner, Rule::param_list)
|
|
||||||
.map({
|
|
||||||
let self_param = self_param.clone();
|
|
||||||
|params_pair| {
|
|
||||||
let mut params = ParamList::from(params_pair);
|
|
||||||
if let Some(x) = self_param {
|
|
||||||
params.0.insert(0, x);
|
|
||||||
}
|
|
||||||
params
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| ParamList(self_param.into_iter().collect()));
|
|
||||||
|
|
||||||
let body = Block::from(inner.next().unwrap());
|
|
||||||
|
|
||||||
Self {
|
|
||||||
visibility,
|
|
||||||
name,
|
|
||||||
params,
|
|
||||||
return_type,
|
|
||||||
body,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&mut pest::iterators::Pairs<'_, Rule>> for Visibility {
|
|
||||||
fn from(pairs: &mut pest::iterators::Pairs<'_, Rule>) -> Self {
|
|
||||||
if listen_rule(pairs, Rule::export) {
|
|
||||||
Visibility::Public
|
|
||||||
} else {
|
|
||||||
Visibility::Private
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn listen_rule(pairs: &mut pest::iterators::Pairs<'_, Rule>, rule: Rule) -> bool {
|
|
||||||
let consumed = pairs
|
|
||||||
.peek()
|
|
||||||
.map(|p| p.as_rule() == rule)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
if consumed {
|
|
||||||
pairs.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
consumed
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn consume_rule<'a>(
|
|
||||||
pairs: &mut pest::iterators::Pairs<'a, Rule>,
|
|
||||||
rule: Rule,
|
|
||||||
) -> Option<pest::iterators::Pair<'a, Rule>> {
|
|
||||||
let consumed = pairs
|
|
||||||
.peek()
|
|
||||||
.map(|p| p.as_rule() == rule)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
if consumed { pairs.next() } else { None }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
pub mod builder;
|
||||||
|
pub mod transpiler;
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
use <mist_analyzer>;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
mist_analyzer::start();
|
||||||
|
}
|
||||||
+183
@@ -0,0 +1,183 @@
|
|||||||
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
env, fs,
|
||||||
|
path::{MAIN_SEPARATOR, PathBuf},
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
use cargo_metadata::{CompilerMessage, Message};
|
||||||
|
use mist_parser::rev_mapper::{RustMap, find_mapping, get_mapping};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct MistDiagnosticMessage {
|
||||||
|
pub message: String,
|
||||||
|
pub file_path: PathBuf,
|
||||||
|
pub file_name: String,
|
||||||
|
pub line: usize,
|
||||||
|
pub column: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum MistDiagnostic {
|
||||||
|
Error(MistDiagnosticMessage),
|
||||||
|
Warning(MistDiagnosticMessage),
|
||||||
|
Rust(CompilerMessage),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(mut args: Vec<String>, root: PathBuf) -> bool {
|
||||||
|
args.remove(0);
|
||||||
|
args.insert(1, "--message-format=json".to_string());
|
||||||
|
|
||||||
|
let is_root = root == env::current_dir().expect("Failed getting env");
|
||||||
|
|
||||||
|
let mut command = Command::new("cargo")
|
||||||
|
.args(args)
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.stdin(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to run cargo");
|
||||||
|
|
||||||
|
let mut reader = std::io::BufReader::new(command.stdout.take().expect("Failed to get reader"));
|
||||||
|
|
||||||
|
let mut diagnostics = Vec::new();
|
||||||
|
|
||||||
|
let mut mapping = HashMap::new();
|
||||||
|
|
||||||
|
let mist_src = format!(".mist{MAIN_SEPARATOR}src");
|
||||||
|
|
||||||
|
for message in cargo_metadata::Message::parse_stream(&mut reader) {
|
||||||
|
match message {
|
||||||
|
Ok(Message::CompilerMessage(msg)) => {
|
||||||
|
for span in &msg.message.spans {
|
||||||
|
if span.is_primary {
|
||||||
|
let rust_path = root.join(&span.file_name);
|
||||||
|
|
||||||
|
let mist_file = span
|
||||||
|
.file_name
|
||||||
|
.replacen(&mist_src, "src", 1)
|
||||||
|
.trim_end_matches(".rs")
|
||||||
|
.to_string()
|
||||||
|
+ ".mist";
|
||||||
|
|
||||||
|
let mist_path = root.join(&mist_file);
|
||||||
|
|
||||||
|
if !fs::exists(&mist_path).expect("Unable to check if mist file exists") {
|
||||||
|
diagnostics.push(MistDiagnostic::Rust(msg));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let map = mapping.entry(rust_path.clone()).or_insert_with(|| {
|
||||||
|
get_mapping(
|
||||||
|
&fs::read_to_string(rust_path)
|
||||||
|
.expect("Failed to read file for mapping"),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let mist_span =
|
||||||
|
find_mapping(&map, &RustMap(span.line_end, span.column_start))
|
||||||
|
.expect("Unable to find mapping");
|
||||||
|
|
||||||
|
let mist_msg = MistDiagnosticMessage {
|
||||||
|
message: span.label.clone().unwrap_or(msg.message.message.clone()),
|
||||||
|
file_name: if is_root {
|
||||||
|
mist_file
|
||||||
|
} else {
|
||||||
|
mist_path.to_string_lossy().to_string()
|
||||||
|
},
|
||||||
|
file_path: mist_path,
|
||||||
|
line: mist_span.1.0,
|
||||||
|
column: mist_span.1.1,
|
||||||
|
};
|
||||||
|
|
||||||
|
match msg.message.level {
|
||||||
|
cargo_metadata::diagnostic::DiagnosticLevel::Error => {
|
||||||
|
diagnostics.push(MistDiagnostic::Error(mist_msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
cargo_metadata::diagnostic::DiagnosticLevel::Warning => {
|
||||||
|
diagnostics.push(MistDiagnostic::Warning(mist_msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Message::BuildFinished(finish)) => {
|
||||||
|
print_diagnostics(&diagnostics);
|
||||||
|
|
||||||
|
let mut raw_reader = reader.into_inner();
|
||||||
|
let mut stdout = std::io::stdout();
|
||||||
|
|
||||||
|
std::io::copy(&mut raw_reader, &mut stdout)
|
||||||
|
.map_err(|v| v.to_string())
|
||||||
|
.expect("(Mist) Failed to copy IO");
|
||||||
|
|
||||||
|
command.wait().unwrap();
|
||||||
|
|
||||||
|
return finish.success;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Message::TextLine(text)) => println!("{text}"),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_diagnostics(diagnostics: &Vec<MistDiagnostic>) {
|
||||||
|
let mut files = HashMap::new();
|
||||||
|
|
||||||
|
for diag in diagnostics {
|
||||||
|
match diag {
|
||||||
|
MistDiagnostic::Error(msg) => {
|
||||||
|
let line = get_line(&mut files, &msg);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
||||||
|
msg.file_name,
|
||||||
|
msg.line,
|
||||||
|
msg.column,
|
||||||
|
msg.message,
|
||||||
|
line.unwrap_or_default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
MistDiagnostic::Warning(msg) => {
|
||||||
|
let line = get_line(&mut files, &msg);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
||||||
|
msg.file_name,
|
||||||
|
msg.line,
|
||||||
|
msg.column,
|
||||||
|
msg.message,
|
||||||
|
line.unwrap_or_default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
MistDiagnostic::Rust(rs) => println!("{rs}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_line(
|
||||||
|
files: &mut HashMap<PathBuf, Vec<String>>,
|
||||||
|
msg: &MistDiagnosticMessage,
|
||||||
|
) -> Option<String> {
|
||||||
|
let src_path = msg.file_path.clone();
|
||||||
|
|
||||||
|
let lines = files.entry(src_path.clone()).or_insert_with(|| {
|
||||||
|
fs::read_to_string(src_path)
|
||||||
|
.expect("Unable to read mist file")
|
||||||
|
.lines()
|
||||||
|
.into_iter()
|
||||||
|
.map(String::from)
|
||||||
|
.collect()
|
||||||
|
});
|
||||||
|
|
||||||
|
lines.get(msg.line).map(|v| v.trim().to_string())
|
||||||
|
}
|
||||||
-595
@@ -1,595 +0,0 @@
|
|||||||
use parser::ast::{
|
|
||||||
Attribute, BinaryOp, Block, Expression, FunctionDecl, Literal, Path, Postfix, Prefix,
|
|
||||||
Statement, StatementBranch, TopLevel, TopLevelKind, TypeExpr, TypeExprKind, TypePostfix,
|
|
||||||
VarAssignStmt, VarDecl, VarDeclStmt, Visibility,
|
|
||||||
};
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Traits
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/// Implemented by nodes that *write* into the codegen output buffer.
|
|
||||||
/// Requires `&mut RustCodegen` because it calls `add` / `addln` / indentation helpers.
|
|
||||||
pub trait ToRust {
|
|
||||||
fn to_rust(&self, cg: &mut RustCodegen);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implemented by nodes that *produce* a `String` without mutating the codegen.
|
|
||||||
/// Only needs `&RustCodegen` (e.g. for indent level or helper access).
|
|
||||||
pub trait GetRust {
|
|
||||||
fn get_rust(&self) -> String;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Codegen struct
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
pub struct RustCodegen {
|
|
||||||
output: String,
|
|
||||||
indent: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RustCodegen {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
output: String::new(),
|
|
||||||
indent: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn indent_str(&self) -> String {
|
|
||||||
" ".repeat(self.indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add(&mut self, s: &str) {
|
|
||||||
self.output.push_str(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn addln(&mut self, s: &str) {
|
|
||||||
self.add(s);
|
|
||||||
self.add("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_indentedln(&mut self, s: &str) {
|
|
||||||
let line = format!("{}{}\n", self.indent_str(), s);
|
|
||||||
self.add(&line);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate(&mut self, toplevels: &[TopLevel]) -> String {
|
|
||||||
for tl in toplevels {
|
|
||||||
tl.to_rust(self);
|
|
||||||
}
|
|
||||||
self.output.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ensure_brackets(&mut self, stmt: &Statement) {
|
|
||||||
match stmt {
|
|
||||||
Statement::Block(_) => stmt.to_rust(self),
|
|
||||||
_ => {
|
|
||||||
self.add_indentedln("{");
|
|
||||||
self.indent += 1;
|
|
||||||
stmt.to_rust(self);
|
|
||||||
self.indent -= 1;
|
|
||||||
self.add_indentedln("}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RustCodegen {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// GetRust — pure string production (expressions, types)
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
impl GetRust for TypeExpr {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
get_type_postfixes(&self.1) + &self.0.get_rust()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for TypeExprKind {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
TypeExprKind::Path(path) => get_static_type_path(path),
|
|
||||||
TypeExprKind::PathParams(path, params) => {
|
|
||||||
format!(
|
|
||||||
"{}<{}>",
|
|
||||||
get_static_type_path(path),
|
|
||||||
params
|
|
||||||
.iter()
|
|
||||||
.map(|t| t.get_rust())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
TypeExprKind::Tuple(types) => format!(
|
|
||||||
"({})",
|
|
||||||
types
|
|
||||||
.iter()
|
|
||||||
.map(|t| t.get_rust())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Literal {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Int(n) => n.to_string(),
|
|
||||||
Self::Float(n) => format!("{n:?}"),
|
|
||||||
Self::Bool(b) => b.to_string(),
|
|
||||||
Self::String(s) => format!("\"{s}\""),
|
|
||||||
Self::Tuple(t) => {
|
|
||||||
format!(
|
|
||||||
"({})",
|
|
||||||
t.iter()
|
|
||||||
.map(Expression::get_rust)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Expression {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Expression::Path(path) => path.get_rust(),
|
|
||||||
Expression::Literal(literal) => literal.get_rust(),
|
|
||||||
Expression::Fix {
|
|
||||||
initial,
|
|
||||||
prefixes,
|
|
||||||
postfixes,
|
|
||||||
} => {
|
|
||||||
prefixes.get_rust()
|
|
||||||
+ &initial.get_rust()
|
|
||||||
+ &Some(prefixes).get_rust()
|
|
||||||
+ &postfixes.get_rust()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Prefix {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Deref => "*",
|
|
||||||
Self::Ref => "&",
|
|
||||||
Self::RefMut => "&mut ",
|
|
||||||
Self::Not => "!",
|
|
||||||
Self::New => "",
|
|
||||||
}
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for [Prefix] {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
self.iter().map(Prefix::get_rust).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Option<&Vec<Prefix>> {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
self.map(|prefixes| {
|
|
||||||
prefixes
|
|
||||||
.iter()
|
|
||||||
.last()
|
|
||||||
.map(|p| match p {
|
|
||||||
Prefix::New => "::new",
|
|
||||||
_ => "",
|
|
||||||
})
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_string()
|
|
||||||
})
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Postfix {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Postfix::FieldAccess(field) => format!(".{}", field),
|
|
||||||
|
|
||||||
Postfix::Call(args) => {
|
|
||||||
let args = args
|
|
||||||
.iter()
|
|
||||||
.map(|a| a.get_rust())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ");
|
|
||||||
format!("({})", args)
|
|
||||||
}
|
|
||||||
|
|
||||||
Postfix::MacroCall(inner) => {
|
|
||||||
format!("!({})", inner)
|
|
||||||
}
|
|
||||||
|
|
||||||
Postfix::StructCall(fields) => {
|
|
||||||
let fields = fields
|
|
||||||
.iter()
|
|
||||||
.map(|(k, v)| format!("{}: {}", k, v.get_rust()))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ");
|
|
||||||
format!("{{ {} }}", fields)
|
|
||||||
}
|
|
||||||
|
|
||||||
Postfix::Index(idx) => {
|
|
||||||
format!("[{}]", idx.get_rust())
|
|
||||||
}
|
|
||||||
|
|
||||||
Postfix::Binary(op, rhs) => {
|
|
||||||
let op_str = match op {
|
|
||||||
BinaryOp::Plus => "+",
|
|
||||||
BinaryOp::Minus => "-",
|
|
||||||
BinaryOp::Multiply => "*",
|
|
||||||
BinaryOp::Divide => "/",
|
|
||||||
BinaryOp::Modulo => "%",
|
|
||||||
BinaryOp::Equal => "==",
|
|
||||||
BinaryOp::NotEqual => "!=",
|
|
||||||
BinaryOp::LessThan => "<",
|
|
||||||
BinaryOp::GreaterThan => ">",
|
|
||||||
BinaryOp::LessThanOrEqual => "<=",
|
|
||||||
BinaryOp::GreaterThanOrEqual => ">=",
|
|
||||||
};
|
|
||||||
format!(" {} {}", op_str, rhs.get_rust())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for [Postfix] {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
self.iter().map(Postfix::get_rust).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// ToRust — output-writing (top-level, statements, blocks)
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
impl ToRust for Block {
|
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
|
||||||
for stmt in &self.0 {
|
|
||||||
stmt.to_rust(cg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToRust for TopLevel {
|
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
|
||||||
match &self.0 {
|
|
||||||
TopLevelKind::ModAttribute => {
|
|
||||||
for attr in &self.1 {
|
|
||||||
cg.addln(&format!("#![{}]", attr.get_rust()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
for attr in &self.1 {
|
|
||||||
cg.addln(&format!("#[{}]", attr.get_rust()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0.to_rust(cg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Attribute {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Path(path) => path.get_rust(),
|
|
||||||
Self::NameValue { path, value } => {
|
|
||||||
format!("{} = {}", path.get_rust(), value.get_rust())
|
|
||||||
}
|
|
||||||
Self::List { path, items } => {
|
|
||||||
format!(
|
|
||||||
"{}({})",
|
|
||||||
path.get_rust(),
|
|
||||||
items
|
|
||||||
.iter()
|
|
||||||
.map(Attribute::get_rust)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToRust for TopLevelKind {
|
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
|
||||||
match self {
|
|
||||||
Self::ModAttribute => {}
|
|
||||||
Self::Include(path) => {
|
|
||||||
cg.addln(&format!("use {};", path.get_rust()));
|
|
||||||
}
|
|
||||||
Self::FunctionDecl(decl) => decl.to_rust(cg),
|
|
||||||
Self::StructDecl {
|
|
||||||
visibility,
|
|
||||||
name,
|
|
||||||
fields,
|
|
||||||
} => {
|
|
||||||
cg.addln(&format!("{}struct {} {{", visibility.get_rust(), name));
|
|
||||||
cg.indent += 1;
|
|
||||||
|
|
||||||
for (field_name, _, ty) in &fields.0 {
|
|
||||||
let ty = ty.get_rust();
|
|
||||||
cg.add_indentedln(&format!("pub {}: {},", field_name, ty));
|
|
||||||
}
|
|
||||||
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.addln("}\n");
|
|
||||||
}
|
|
||||||
Self::ClassDecl {
|
|
||||||
visibility,
|
|
||||||
name,
|
|
||||||
fields,
|
|
||||||
constructor,
|
|
||||||
methods,
|
|
||||||
} => {
|
|
||||||
// Struct decl
|
|
||||||
cg.addln(&format!("{}struct {} {{", visibility.get_rust(), name));
|
|
||||||
cg.indent += 1;
|
|
||||||
|
|
||||||
for field in fields {
|
|
||||||
let ty = field.decl.type_.clone().unwrap().get_rust();
|
|
||||||
cg.add_indentedln(&format!("pub {}: {},", field.decl.name, ty));
|
|
||||||
}
|
|
||||||
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.addln("}\n");
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
cg.addln(&format!("impl {} {{", name));
|
|
||||||
cg.indent += 1;
|
|
||||||
|
|
||||||
let params_str = constructor
|
|
||||||
.params
|
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.map(VarDecl::get_rust)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ");
|
|
||||||
|
|
||||||
cg.add_indentedln(&format!(
|
|
||||||
"{}fn new({}) -> Self {{",
|
|
||||||
constructor.visibility.get_rust(),
|
|
||||||
params_str
|
|
||||||
));
|
|
||||||
cg.indent += 1;
|
|
||||||
|
|
||||||
cg.add_indentedln("let mut this: Self = unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };");
|
|
||||||
|
|
||||||
for field in fields {
|
|
||||||
if let Some(init) = &field.init {
|
|
||||||
cg.add_indentedln(&format!(
|
|
||||||
"this.{} = {};",
|
|
||||||
field.decl.name,
|
|
||||||
init.get_rust()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cg.add_indentedln(&format!(
|
|
||||||
"this.construct_class({});",
|
|
||||||
constructor
|
|
||||||
.params
|
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.map(|e| e.name.to_string())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
));
|
|
||||||
|
|
||||||
cg.add_indentedln("this");
|
|
||||||
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.add_indentedln("}\n");
|
|
||||||
|
|
||||||
// Constructor function
|
|
||||||
cg.add_indentedln(&format!(
|
|
||||||
"{}fn construct_class(&mut self, {}) {{",
|
|
||||||
constructor.visibility.get_rust(),
|
|
||||||
params_str
|
|
||||||
));
|
|
||||||
cg.indent += 1;
|
|
||||||
|
|
||||||
constructor.body.to_rust(cg);
|
|
||||||
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.add_indentedln("}\n");
|
|
||||||
|
|
||||||
for method in methods {
|
|
||||||
method.to_rust(cg);
|
|
||||||
}
|
|
||||||
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.addln("}\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToRust for Statement {
|
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
|
||||||
match self {
|
|
||||||
Statement::Expression(expr) => {
|
|
||||||
cg.add_indentedln(&format!("{};", expr.get_rust()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::Block(block) => {
|
|
||||||
cg.add_indentedln("{");
|
|
||||||
cg.indent += 1;
|
|
||||||
block.to_rust(cg);
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.add_indentedln("}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
|
||||||
let init = init
|
|
||||||
.as_ref()
|
|
||||||
.map(|e| format!(" = {}", e.get_rust()))
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
cg.add_indentedln(&format!("let {}{};", decl.get_rust(), init));
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::VarAssign(VarAssignStmt { target, value }) => {
|
|
||||||
cg.add_indentedln(&format!("{} = {};", target.get_rust(), value.get_rust(),));
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::If {
|
|
||||||
initial,
|
|
||||||
else_if,
|
|
||||||
else_branch,
|
|
||||||
} => {
|
|
||||||
cg.add_indentedln(&format!("if {}", initial.condition.get_rust()));
|
|
||||||
cg.ensure_brackets(&initial.body);
|
|
||||||
|
|
||||||
for else_if_branch in else_if {
|
|
||||||
cg.add_indentedln(&format!("else if {}", else_if_branch.condition.get_rust()));
|
|
||||||
cg.ensure_brackets(&else_if_branch.body);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(else_br) = else_branch {
|
|
||||||
cg.add_indentedln("else");
|
|
||||||
cg.ensure_brackets(else_br);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::While(StatementBranch { condition, body }) => {
|
|
||||||
cg.add_indentedln(&format!("while {}", condition.get_rust()));
|
|
||||||
cg.ensure_brackets(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::CStyleFor {
|
|
||||||
init,
|
|
||||||
condition,
|
|
||||||
update,
|
|
||||||
body,
|
|
||||||
} => {
|
|
||||||
cg.add_indentedln("{");
|
|
||||||
cg.indent += 1;
|
|
||||||
|
|
||||||
init.to_rust(cg);
|
|
||||||
|
|
||||||
cg.add_indentedln(&format!("while {}", condition.get_rust()));
|
|
||||||
|
|
||||||
cg.add_indentedln("{");
|
|
||||||
cg.indent += 1;
|
|
||||||
|
|
||||||
cg.ensure_brackets(body);
|
|
||||||
|
|
||||||
update.to_rust(cg);
|
|
||||||
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.add_indentedln("}");
|
|
||||||
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.add_indentedln("}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::For {
|
|
||||||
pattern,
|
|
||||||
iterator,
|
|
||||||
body,
|
|
||||||
} => {
|
|
||||||
cg.add_indentedln(&format!("for {} in {}", pattern, iterator.get_rust()));
|
|
||||||
cg.ensure_brackets(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::Return(expr) => {
|
|
||||||
let val = expr.as_ref().map(|e| e.get_rust()).unwrap_or_default();
|
|
||||||
cg.add_indentedln(&format!("return {};", val));
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement::Break => cg.add_indentedln("break;"),
|
|
||||||
Statement::Continue => cg.add_indentedln("continue;"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToRust for FunctionDecl {
|
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
|
||||||
let params_str = self
|
|
||||||
.params
|
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.map(VarDecl::get_rust)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ");
|
|
||||||
|
|
||||||
cg.add_indentedln(&format!(
|
|
||||||
"{}fn {}({}) -> {} {{",
|
|
||||||
self.visibility.get_rust(),
|
|
||||||
self.name,
|
|
||||||
params_str,
|
|
||||||
self.return_type.get_rust()
|
|
||||||
));
|
|
||||||
cg.indent += 1;
|
|
||||||
self.body.to_rust(cg);
|
|
||||||
cg.indent -= 1;
|
|
||||||
cg.add_indentedln("}\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for VarDecl {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
let mutability = if self.mutable { "mut " } else { "" };
|
|
||||||
|
|
||||||
let ty = self
|
|
||||||
.type_
|
|
||||||
.as_ref()
|
|
||||||
.map(|t| format!(": {}", t.get_rust()))
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
format!("{}{}{}", mutability, self.name, ty)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Path {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
self.0.join("::")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for TypePostfix {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
TypePostfix::Ref => format!("&"),
|
|
||||||
TypePostfix::RefMut => format!("&mut "),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetRust for Visibility {
|
|
||||||
fn get_rust(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Visibility::Public => "pub ",
|
|
||||||
Visibility::Private => "",
|
|
||||||
}
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_static_type_path(path: &Path) -> String {
|
|
||||||
let rust_path = path.get_rust();
|
|
||||||
|
|
||||||
if rust_path == "void" {
|
|
||||||
format!("()")
|
|
||||||
} else {
|
|
||||||
rust_path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_type_postfixes(postfixes: &[TypePostfix]) -> String {
|
|
||||||
postfixes.iter().map(TypePostfix::get_rust).collect()
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
use std::{fs, path::PathBuf, process, time::Instant};
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Config {
|
|
||||||
src: String,
|
|
||||||
output: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build() {
|
|
||||||
let start = Instant::now();
|
|
||||||
|
|
||||||
// 1. find project root
|
|
||||||
let root = find_project_root().unwrap_or_else(|| {
|
|
||||||
panic!("error: could not find project root (mist.json)");
|
|
||||||
});
|
|
||||||
|
|
||||||
println!("mistc build ({})", root.display());
|
|
||||||
|
|
||||||
// 2. load config
|
|
||||||
let config = load_config(&root);
|
|
||||||
|
|
||||||
let src = root.join(&config.src);
|
|
||||||
|
|
||||||
for entry in fs::read_dir(src).unwrap() {
|
|
||||||
if let Ok(entry) = entry {
|
|
||||||
let entry_path = root.join(&entry.path());
|
|
||||||
let out_dir = root.join(&config.output);
|
|
||||||
let file_name = entry.file_name();
|
|
||||||
let file_name = file_name.to_string_lossy();
|
|
||||||
|
|
||||||
// 3. read entry file
|
|
||||||
let source = match fs::read_to_string(&entry_path) {
|
|
||||||
Ok(s) => s,
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("error: failed to read entry file\n {}", e);
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let parser_result = parser::parse(&source).map_err(|e| e.to_string());
|
|
||||||
|
|
||||||
let ast = match parser_result {
|
|
||||||
Ok(ast) => ast,
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("error: parse failed\n{}", e);
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// semantic::walk_ast(semantic::scope::Scope::from_top(&root, &ast), &mut ast);
|
|
||||||
|
|
||||||
let mut gc = crate::codegen::RustCodegen::new();
|
|
||||||
let output = gc.generate(&ast);
|
|
||||||
|
|
||||||
if let Err(e) = fs::create_dir_all(&out_dir) {
|
|
||||||
eprintln!("error: failed to create build dir\n {}", e);
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let out_file = out_dir.join(file_name.replace(".mist", ".rs"));
|
|
||||||
|
|
||||||
if let Err(e) = fs::write(&out_file, output) {
|
|
||||||
eprintln!("error: failed to write output\n {}", e);
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let elapsed = start.elapsed();
|
|
||||||
|
|
||||||
println!("build finished in {:.2?}", elapsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn find_project_root() -> Option<PathBuf> {
|
|
||||||
let mut dir = std::env::current_dir().ok()?;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if dir.join("mist.json").exists() {
|
|
||||||
return Some(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !dir.pop() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_config(root: &std::path::Path) -> Config {
|
|
||||||
let content =
|
|
||||||
std::fs::read_to_string(root.join("mist.json")).expect("failed to read mist.json");
|
|
||||||
|
|
||||||
serde_json::from_str(&content).expect("invalid mist.json format")
|
|
||||||
}
|
|
||||||
+106
@@ -0,0 +1,106 @@
|
|||||||
|
use <std::process>;
|
||||||
|
use <std::env>;
|
||||||
|
use <std::fs>;
|
||||||
|
|
||||||
|
pub mod builder;
|
||||||
|
pub mod transpiler;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
Vec<String> args = env::args().collect();
|
||||||
|
|
||||||
|
if (args.len() < 2) {
|
||||||
|
print_usage();
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
match (args[1].as_str()) {
|
||||||
|
"run" | "build" | "check" | "r" | "b" | "c" => {
|
||||||
|
var root = transpiler::build(false);
|
||||||
|
|
||||||
|
println!("");
|
||||||
|
|
||||||
|
if (builder::build(args, root)) {
|
||||||
|
println!("\x1b[32m\nBuild successful\x1b[0m");
|
||||||
|
} else {
|
||||||
|
println!("\x1b[31m\nBuild failed\x1b[0m");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"transpile" | "t" => {
|
||||||
|
transpiler::build(args.get(2).is_some());
|
||||||
|
}
|
||||||
|
"init" => {
|
||||||
|
init_project(args);
|
||||||
|
}
|
||||||
|
"version" | "--version" | "-v" => {
|
||||||
|
println!("mist {}", env!("CARGO_PKG_VERSION"));
|
||||||
|
}
|
||||||
|
"help" | "--help" | "-h" => {
|
||||||
|
print_usage();
|
||||||
|
}
|
||||||
|
unknown => {
|
||||||
|
eprintln!("error: unknown command '{}'\n", unknown);
|
||||||
|
print_usage();
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_usage() {
|
||||||
|
println!("Mist - the mist compiler\n");
|
||||||
|
println!(" View our documentation! \x1b[35mhttps://mist.selimaj.dev\x1b[0m");
|
||||||
|
println!(" Follow us on github! \x1b[35mhttps://github.com/mist-go\x1b[0m\n");
|
||||||
|
println!("usage:");
|
||||||
|
println!(" \x1b[36m mist run\x1b[0m,\x1b[36m r\x1b[0m run the project in the current directory\n");
|
||||||
|
println!(
|
||||||
|
" \x1b[36m mist build\x1b[0m,\x1b[36m b\x1b[0m build the project in the current directory\n"
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
" \x1b[36m mist transpile\x1b[0m,\x1b[36m t\x1b[0m transpile the project in the current directory\n"
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
" \x1b[36m mist check\x1b[0m,\x1b[36m c\x1b[0m check the project in the current directory\n"
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
" \x1b[36m mist init\x1b[0m initialize a project in the current folder\n"
|
||||||
|
);
|
||||||
|
println!(" \x1b[36m mist version \x1b[0m print the compiler version\n");
|
||||||
|
println!(" \x1b[36m mist help\x1b[0m print this message\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_project(Vec<String> mut args) {
|
||||||
|
args.remove(0);
|
||||||
|
|
||||||
|
new process::Command("cargo")
|
||||||
|
.args(args)
|
||||||
|
.stdout(process::Stdio::inherit())
|
||||||
|
.stderr(process::Stdio::inherit())
|
||||||
|
.stdin(process::Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to run cargo").wait().expect("Unable to wait");
|
||||||
|
|
||||||
|
bool is_lib = fs::metadata("src/lib.rs").is_ok();
|
||||||
|
|
||||||
|
if (is_lib) {
|
||||||
|
fs::remove_file("src/lib.rs").expect("Failed to remove src/lib.rs");
|
||||||
|
fs::write("src/lib.mist", "void test() {\n}").expect("Failed to create src/lib.mist");
|
||||||
|
} else {
|
||||||
|
fs::remove_file("src/main.rs").expect("Failed to remove src/main.rs");
|
||||||
|
fs::write("src/main.mist", "void main() {\n println!(\"Hello, World!\");\n}\n").expect("Failed to create src/main.mist");
|
||||||
|
}
|
||||||
|
|
||||||
|
inject_mist_target(is_lib);
|
||||||
|
|
||||||
|
println!("\n\x1b[34minfo\x1b[0m: Please open Cargo.toml and adjust `\x1b[35mname\x1b[0m = ` as needed, Thank you for using Mist!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void inject_mist_target(bool is_lib) {
|
||||||
|
String toml_content = fs::read_to_string("Cargo.toml").expect("Failed to read Cargo.toml");
|
||||||
|
|
||||||
|
str* inject = if (is_lib) {
|
||||||
|
"\n[lib]\nname = \"my_lib\"\npath = \".mist/src/lib.rs\"\n"
|
||||||
|
} else {
|
||||||
|
"\n[[bin]]\nname = \"my_bin\"\npath = \".mist/src/main.rs\"\n"
|
||||||
|
};
|
||||||
|
|
||||||
|
fs::write("Cargo.toml", toml_content+inject).expect("Failed to create src/main.mist");
|
||||||
|
}
|
||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
use std::process;
|
|
||||||
|
|
||||||
pub mod codegen;
|
|
||||||
pub mod compiler;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
|
||||||
|
|
||||||
if args.len() < 2 {
|
|
||||||
print_usage();
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
match args[1].as_str() {
|
|
||||||
"build" => {
|
|
||||||
if args.len() < 2 {
|
|
||||||
eprintln!("error: expected a file path\n usage: mist build");
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
compiler::build();
|
|
||||||
}
|
|
||||||
"version" | "--version" | "-v" => {
|
|
||||||
println!("mist {}", env!("CARGO_PKG_VERSION"));
|
|
||||||
}
|
|
||||||
"help" | "--help" | "-h" => {
|
|
||||||
print_usage();
|
|
||||||
}
|
|
||||||
unknown => {
|
|
||||||
eprintln!("error: unknown command '{}'\n", unknown);
|
|
||||||
print_usage();
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_usage() {
|
|
||||||
println!("mist - the mist compiler");
|
|
||||||
println!();
|
|
||||||
println!("usage:");
|
|
||||||
println!(" mist build compile the project in the current directory");
|
|
||||||
println!(" mist check <file.ms> parse and validate without compiling");
|
|
||||||
println!(" mist version print the compiler version");
|
|
||||||
println!(" mist help print this message");
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process,
|
||||||
|
time::Instant,
|
||||||
|
};
|
||||||
|
|
||||||
|
use mist_parser::error::ParseError;
|
||||||
|
|
||||||
|
pub fn build(force: bool) -> PathBuf {
|
||||||
|
let start = Instant::now();
|
||||||
|
|
||||||
|
let root = std::env::current_dir()
|
||||||
|
.ok()
|
||||||
|
.expect("Unable to find project root");
|
||||||
|
|
||||||
|
let src_dir = root.join("src");
|
||||||
|
let out_dir = root.join(".mist/src");
|
||||||
|
|
||||||
|
build_dir(&root, &src_dir, &src_dir, &out_dir, force);
|
||||||
|
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m",
|
||||||
|
elapsed
|
||||||
|
);
|
||||||
|
|
||||||
|
root
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_dir(root: &Path, base_src: &Path, current_dir: &Path, out_dir: &Path, force: bool) {
|
||||||
|
let entries = match fs::read_dir(current_dir) {
|
||||||
|
Ok(entries) => entries,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!(
|
||||||
|
"error: failed to read directory {}\n {}",
|
||||||
|
current_dir.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for entry in entries {
|
||||||
|
let entry = match entry {
|
||||||
|
Ok(entry) => entry,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("error: failed to read directory entry\n {}", e);
|
||||||
|
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let path = entry.path();
|
||||||
|
|
||||||
|
// recurse into nested directories
|
||||||
|
if path.is_dir() {
|
||||||
|
build_dir(root, base_src, &path, out_dir, force);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let relative = path.strip_prefix(base_src).unwrap();
|
||||||
|
|
||||||
|
// Handle non-mist files with a cache check
|
||||||
|
if path.extension().and_then(|e| e.to_str()) != Some("mist") {
|
||||||
|
let dest_path = out_dir.join(relative);
|
||||||
|
|
||||||
|
// Create parent directories for static assets if needed
|
||||||
|
if let Some(parent) = dest_path.parent() {
|
||||||
|
let _ = fs::create_dir_all(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !force && should_skip(&path, &dest_path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::copy(&path, dest_path).expect("Failed to copy non-mist file");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let output_path = out_dir.join(relative).with_extension("rs");
|
||||||
|
|
||||||
|
// Cache layer: Skip if the generated .rs file is newer than the .mist source
|
||||||
|
if !force && should_skip(&path, &output_path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create parent directories
|
||||||
|
if let Some(parent) = output_path.parent() {
|
||||||
|
if let Err(e) = fs::create_dir_all(parent) {
|
||||||
|
eprintln!(
|
||||||
|
"error: failed to create output directory {}\n {}",
|
||||||
|
parent.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// read source
|
||||||
|
let source = match fs::read_to_string(&path) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("error: failed to read file {}\n {}", path.display(), e);
|
||||||
|
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let parser_result = mist_parser::parse(&source).map_err(|e| match e {
|
||||||
|
ParseError::Ast(e) => {
|
||||||
|
let start_pos = e.span.start_pos().line_col();
|
||||||
|
|
||||||
|
let span = e.span.as_str();
|
||||||
|
|
||||||
|
format!(
|
||||||
|
"\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}{}\t{}",
|
||||||
|
path.as_os_str().display(),
|
||||||
|
start_pos.0,
|
||||||
|
start_pos.1,
|
||||||
|
e.error_message,
|
||||||
|
span,
|
||||||
|
if span.ends_with("\n") { "" } else { "\n" },
|
||||||
|
"^".repeat(span.trim().len()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ParseError::PreAst(e) => format!("{e}"),
|
||||||
|
});
|
||||||
|
|
||||||
|
let ast = match parser_result {
|
||||||
|
Ok(ast) => ast,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("error: parse failed in {}\n{}", path.display(), e);
|
||||||
|
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// semantic::walk_ast(semantic::scope::Scope::from_top(root, &ast), &mut ast);
|
||||||
|
|
||||||
|
let mut gc = mist_codegen::RustCodegen::new();
|
||||||
|
let output = gc.generate(ast);
|
||||||
|
|
||||||
|
if let Err(e) = fs::write(&output_path, output) {
|
||||||
|
eprintln!(
|
||||||
|
"error: failed to write output {}\n {}",
|
||||||
|
output_path.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_skip(source: &Path, output: &Path) -> bool {
|
||||||
|
if let (Ok(src_meta), Ok(out_meta)) = (fs::metadata(source), fs::metadata(output)) {
|
||||||
|
if let (Ok(src_time), Ok(out_time)) = (src_meta.modified(), out_meta.modified()) {
|
||||||
|
return out_time >= src_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
@@ -1,450 +0,0 @@
|
|||||||
{
|
|
||||||
"fmt": {
|
|
||||||
"package_name": "fmt",
|
|
||||||
"structs": {},
|
|
||||||
"functions": {
|
|
||||||
"append": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Append",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"b": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]byte",
|
|
||||||
"name": "b"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"[]byte"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"appendf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Appendf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"b": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]byte",
|
|
||||||
"name": "b"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"[]byte"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"appendln": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Appendln",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"b": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]byte",
|
|
||||||
"name": "b"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"[]byte"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"errorf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Errorf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"formatString": {
|
|
||||||
"export": true,
|
|
||||||
"name": "FormatString",
|
|
||||||
"params": {
|
|
||||||
"state": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "fmt.State",
|
|
||||||
"name": "state"
|
|
||||||
},
|
|
||||||
"verb": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "rune",
|
|
||||||
"name": "verb"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"string"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fprint": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Fprint",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"w": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "io.Writer",
|
|
||||||
"name": "w"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fprintf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Fprintf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
},
|
|
||||||
"w": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "io.Writer",
|
|
||||||
"name": "w"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fprintln": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Fprintln",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"w": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "io.Writer",
|
|
||||||
"name": "w"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fscan": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Fscan",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"r": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "io.Reader",
|
|
||||||
"name": "r"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fscanf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Fscanf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
},
|
|
||||||
"r": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "io.Reader",
|
|
||||||
"name": "r"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fscanln": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Fscanln",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"r": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "io.Reader",
|
|
||||||
"name": "r"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"print": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Print",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"printf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Printf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"println": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Println",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"scan": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Scan",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"scanf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Scanf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"scanln": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Scanln",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"sprint": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Sprint",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"string"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"sprintf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Sprintf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"string"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"sprintln": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Sprintln",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"string"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"sscan": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Sscan",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"str": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "str"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"sscanf": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Sscanf",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"format": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "format"
|
|
||||||
},
|
|
||||||
"str": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "str"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"sscanln": {
|
|
||||||
"export": true,
|
|
||||||
"name": "Sscanln",
|
|
||||||
"params": {
|
|
||||||
"a": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "[]any",
|
|
||||||
"name": "a"
|
|
||||||
},
|
|
||||||
"str": {
|
|
||||||
"export": true,
|
|
||||||
"var_type": "string",
|
|
||||||
"name": "str"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"return_types": [
|
|
||||||
"int",
|
|
||||||
"error"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
class MyClass {
|
|
||||||
String message;
|
|
||||||
|
|
||||||
public constructor(str* name) {
|
|
||||||
self.message = format!("Hello {}!", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void greet(self*) {
|
|
||||||
println!("{}", self.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
var my_class = new MyClass("World");
|
|
||||||
my_class.greet();
|
|
||||||
var x = 1 + 2 + 3;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user