From e74eace15c82372976e7bec4fe3eb581c6848fbd Mon Sep 17 00:00:00 2001 From: rvcas Date: Tue, 2 Aug 2022 19:43:19 -0400 Subject: [PATCH 01/18] chore: init lang crate --- Cargo.lock | 4 ++++ Cargo.toml | 2 +- crates/lang/Cargo.toml | 8 ++++++++ crates/lang/src/lib.rs | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 crates/lang/Cargo.toml create mode 100644 crates/lang/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c2c18b5c..c6334cc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,10 @@ dependencies = [ "uplc", ] +[[package]] +name = "aiken-lang" +version = "0.0.0" + [[package]] name = "anyhow" version = "1.0.57" diff --git a/Cargo.toml b/Cargo.toml index f409c5ce..c66a4d73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["crates/cli", "crates/flat", "crates/uplc"] +members = ["crates/*"] diff --git a/crates/lang/Cargo.toml b/crates/lang/Cargo.toml new file mode 100644 index 00000000..dbb3f1d6 --- /dev/null +++ b/crates/lang/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "aiken-lang" +version = "0.0.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] \ No newline at end of file diff --git a/crates/lang/src/lib.rs b/crates/lang/src/lib.rs new file mode 100644 index 00000000..1b4a90c9 --- /dev/null +++ b/crates/lang/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} From fd17605e4de52e08ab41c3de05767fb0b15d20a3 Mon Sep 17 00:00:00 2001 From: rvcas Date: Tue, 2 Aug 2022 21:20:50 -0400 Subject: [PATCH 02/18] feat: add deps --- Cargo.lock | 497 +++++++++++++++++++++++++---------------- crates/lang/Cargo.toml | 5 +- 2 files changed, 310 insertions(+), 192 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6334cc7..41f7068c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,18 +2,46 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" +dependencies = ["const-random"] + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = ["getrandom", "once_cell", "version_check"] + [[package]] name = "aiken" +<<<<<<< HEAD version = "0.0.11" +======= +<<<<<<< HEAD +version = "0.0.10" +======= +<<<<<<< HEAD +version = "0.0.8" +>>>>>>> c50961c (feat: add deps) +>>>>>>> 508f3c6 (feat: add deps) dependencies = [ "anyhow", "clap", "uplc", ] +======= +version = "0.0.7" +dependencies = ["anyhow", "clap", "uplc"] +>>>>>>> 27331bc (feat: add deps) [[package]] name = "aiken-lang" version = "0.0.0" +dependencies = ["chumsky", "internment", "miette"] [[package]] name = "anyhow" @@ -32,11 +60,7 @@ name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] +dependencies = ["hermit-abi", "libc", "winapi"] [[package]] name = "autocfg" @@ -61,9 +85,7 @@ name = "bit-set" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" -dependencies = [ - "bit-vec", -] +dependencies = ["bit-vec"] [[package]] name = "bit-vec" @@ -89,21 +111,28 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chumsky" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d02796e4586c6c41aeb68eae9bfb4558a522c35f1430c14b40136c3706e09e4" +dependencies = ["ahash 0.3.8"] + [[package]] name = "clap" version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ - "atty", - "bitflags", - "clap_derive", - "clap_lex", - "indexmap", - "lazy_static", - "strsim", - "termcolor", - "textwrap", + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "lazy_static", + "strsim", + "termcolor", + "textwrap", ] [[package]] @@ -111,46 +140,64 @@ name = "clap_derive" version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] +dependencies = ["heck", "proc-macro-error", "proc-macro2", "quote", "syn"] [[package]] name = "clap_lex" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" -dependencies = [ - "os_str_bytes", -] +dependencies = ["os_str_bytes"] [[package]] +<<<<<<< HEAD name = "cryptoxide" + +======= version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "129eabb7b0b78644a3a7e7cf220714aba47463bb281f69fa7a71ca5d12564cca" +name = "const-random" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f590d95d011aa80b063ffe3253422ed5aa462af4e9867d43ce8337562bac77c4" +dependencies = ["const-random-macro", "proc-macro-hack"] +[[package]] +name = "const-random-macro" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "615f6e27d000a2bffbc7f2f6a8669179378fa27ee4d0a509e985dfc0a7defb40" +dependencies = ["getrandom", "lazy_static", "proc-macro-hack", "tiny-keccak"] + +[[package]] + +>>>>>>> 1281557 (feat: add deps) + +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "fastrand" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" -dependencies = [ - "instant", -] +dependencies = ["instant"] [[package]] name = "flat-rs" +<<<<<<< HEAD version = "0.0.10" dependencies = [ "anyhow", "proptest", "thiserror", ] +======= +version = "0.0.7" +dependencies = ["anyhow", "thiserror"] +>>>>>>> c50961c (feat: add deps) [[package]] name = "fnv" @@ -163,11 +210,7 @@ name = "getrandom" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] +dependencies = ["cfg-if", "libc", "wasi"] [[package]] name = "half" @@ -181,6 +224,13 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = ["ahash 0.7.6"] + [[package]] name = "heck" version = "0.4.0" @@ -192,9 +242,7 @@ name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] +dependencies = ["libc"] [[package]] name = "hex" @@ -207,26 +255,31 @@ name = "indexmap" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" -dependencies = [ - "autocfg", - "hashbrown", -] +dependencies = ["autocfg", "hashbrown 0.11.2"] [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] +dependencies = ["cfg-if"] [[package]] +<<<<<<< HEAD name = "itoa" + +======= + +>>>>>>> 1281557 (feat: add deps) + version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" - +name = "internment" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a798d7677f07d6f1e77be484ea8626ddb1566194de399f1206306820c406371" +dependencies = ["hashbrown 0.12.3", "parking_lot"] [[package]] name = "lazy_static" version = "1.4.0" @@ -239,64 +292,76 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = ["autocfg", "scopeguard"] + [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +dependencies = ["cfg-if"] [[package]] +<<<<<<< HEAD name = "minicbor" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5e575910763b21a0db7df5e142907fe944bff84d1dfc78e2ba92e7f3bdfd36b" -dependencies = [ - "half", - "minicbor-derive 0.11.0", -] +dependencies = ["half", "minicbor-derive 0.11.0"] [[package]] name = "minicbor" version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a20020e8e2d1881d8736f64011bb5ff99f1db9947ce3089706945c8915695cb" -dependencies = [ - "minicbor-derive 0.12.0", -] +dependencies = ["minicbor-derive 0.12.0"] [[package]] name = "minicbor-derive" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a86c5f04def8fb7735ae918bb589af82f985526f4c62e0249544b668b2f456" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +dependencies = ["proc-macro2", "quote", "syn"] [[package]] + +======= name = "minicbor-derive" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8608fb1c805b5b6b3d5ab7bd95c40c396df622b64d77b2d621a5eae1eed050ee" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +name = "miette" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2c9d50e919ffdc4d2d83b83972a13e8ba86ba8245a205bee9e314d593c15a8" +dependencies = ["miette-derive", "once_cell", "thiserror", "unicode-width"] + +[[package]] + +>>>>>>> 1281557 (feat: add deps) +name = "miette-derive" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8d10c73bcc9f0ab5c918521dab23d178062a56e6b328eb37106d497280bd94" +dependencies = ["proc-macro2", "quote", "syn"] [[package]] name = "num-traits" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] +dependencies = ["autocfg"] + +[[package]] +name = "once_cell" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "os_str_bytes" @@ -305,32 +370,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435" [[package]] +<<<<<<< HEAD name = "pallas-codec" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dce0ea17341c1a0e43e2bb4a637740198dcb09826879ce3ac5ae1c6f4398a5d" -dependencies = [ - "minicbor 0.17.1", -] +dependencies = ["minicbor 0.17.1"] [[package]] name = "pallas-crypto" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "051226367cd851895c73e3115d378b58495ade1ee60c3a154c0d0c30554565fa" -dependencies = [ - "cryptoxide", - "hex", - "pallas-codec", - "rand_core", - "thiserror", -] +dependencies = ["cryptoxide", "hex", "pallas-codec", "rand_core", "thiserror"] [[package]] -name = "pallas-primitives" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a0fcc7d5a7120bc2b2e203ec5e7f8088107c500c0eb665569d0e77a910d3c0" dependencies = [ "base58", "bech32", @@ -340,28 +394,45 @@ dependencies = [ "pallas-crypto", "serde", "serde_json", +======= +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", ] +[[package]]dependencies = [ +"cfg-if", +"libc", +"redox_syscall", +"smallvec", +"windows-sys", +>>>>>>> 1281557 (feat: add deps) +]name = "pallas-primitives" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a0fcc7d5a7120bc2b2e203ec5e7f8088107c500c0eb665569d0e77a910d3c0" +name = "parking_lot_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" + [[package]] name = "peg" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af728fe826811af3b38c37e93de6d104485953ea373d656eebae53d6987fcd2c" -dependencies = [ - "peg-macros", - "peg-runtime", -] +dependencies = ["peg-macros", "peg-runtime"] [[package]] name = "peg-macros" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4536be147b770b824895cbad934fccce8e49f14b4c4946eaa46a6e4a12fcdc16" -dependencies = [ - "peg-runtime", - "proc-macro2", - "quote", -] +dependencies = ["peg-runtime", "proc-macro2", "quote"] [[package]] name = "peg-runtime" @@ -380,12 +451,7 @@ name = "pretty" version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83f3aa1e3ca87d3b124db7461265ac176b40c277f37e503eaa29c9c75c037846" -dependencies = [ - "arrayvec", - "log", - "typed-arena", - "unicode-segmentation", -] +dependencies = ["arrayvec", "log", "typed-arena", "unicode-segmentation"] [[package]] name = "proc-macro-error" @@ -393,11 +459,11 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", ] [[package]] @@ -405,20 +471,20 @@ name = "proc-macro-error-attr" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] +dependencies = ["proc-macro2", "quote", "version_check"] + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" -dependencies = [ - "unicode-ident", -] +dependencies = ["unicode-ident"] [[package]] name = "proptest" @@ -426,18 +492,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5" dependencies = [ - "bit-set", - "bitflags", - "byteorder", - "lazy_static", - "num-traits", - "quick-error 2.0.1", - "rand", - "rand_chacha", - "rand_xorshift", - "regex-syntax", - "rusty-fork", - "tempfile", + "bit-set", + "bitflags", + "byteorder", + "lazy_static", + "num-traits", + "quick-error 2.0.1", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", ] [[package]] @@ -457,57 +523,42 @@ name = "quote" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" -dependencies = [ - "proc-macro2", -] +dependencies = ["proc-macro2"] [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] +dependencies = ["libc", "rand_chacha", "rand_core"] [[package]] name = "rand_chacha" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] +dependencies = ["ppv-lite86", "rand_core"] [[package]] name = "rand_core" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -dependencies = [ - "getrandom", -] +dependencies = ["getrandom"] [[package]] name = "rand_xorshift" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -dependencies = [ - "rand_core", -] +dependencies = ["rand_core"] [[package]] name = "redox_syscall" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" -dependencies = [ - "bitflags", -] +dependencies = ["bitflags"] [[package]] name = "regex-syntax" @@ -520,23 +571,17 @@ name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] +dependencies = ["winapi"] [[package]] name = "rusty-fork" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = [ - "fnv", - "quick-error 1.2.3", - "tempfile", - "wait-timeout", -] +dependencies = ["fnv", "quick-error 1.2.3", "tempfile", "wait-timeout"] [[package]] +<<<<<<< HEAD name = "ryu" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -549,16 +594,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2" [[package]] + +======= name = "serde_json" version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" -dependencies = [ - "itoa", - "ryu", - "serde", -] +dependencies = ["itoa", "ryu", "serde"] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] + +>>>>>>> 1281557 (feat: add deps) + +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "strsim" version = "0.10.0" @@ -570,11 +625,7 @@ name = "syn" version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +dependencies = ["proc-macro2", "quote", "unicode-ident"] [[package]] name = "tempfile" @@ -582,12 +633,12 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", ] [[package]] @@ -595,9 +646,7 @@ name = "termcolor" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] +dependencies = ["winapi-util"] [[package]] name = "textwrap" @@ -610,20 +659,21 @@ name = "thiserror" version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" -dependencies = [ - "thiserror-impl", -] +dependencies = ["thiserror-impl"] [[package]] name = "thiserror-impl" version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +dependencies = ["proc-macro2", "quote", "syn"] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = ["crunchy"] [[package]] name = "typed-arena" @@ -644,9 +694,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] +<<<<<<< HEAD name = "uplc" +<<<<<<< HEAD version = "0.0.11" +======= +<<<<<<< HEAD +version = "0.0.10" +======= +version = "0.0.8" +======= +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +>>>>>>> 27331bc (feat: add deps) +>>>>>>> c50961c (feat: add deps) +>>>>>>> 508f3c6 (feat: add deps) dependencies = [ +<<<<<<< HEAD "cryptoxide", "flat-rs", "hex", @@ -657,7 +725,18 @@ dependencies = [ "pretty", "proptest", "thiserror", -] +======= + "flat-rs", + "hex", + "minicbor 0.18.0", + "pallas-primitives", + "peg", + "pretty", + "proptest", + "thiserror", +>>>>>>> 273fa4a (feat: add deps) +]name = "uplc" +version = "0.0.7" [[package]] name = "version_check" @@ -670,9 +749,7 @@ name = "wait-timeout" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -dependencies = [ - "libc", -] +dependencies = ["libc"] [[package]] name = "wasi" @@ -685,10 +762,7 @@ name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] +dependencies = ["winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu"] [[package]] name = "winapi-i686-pc-windows-gnu" @@ -701,12 +775,53 @@ name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] +dependencies = ["winapi"] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" diff --git a/crates/lang/Cargo.toml b/crates/lang/Cargo.toml index dbb3f1d6..d2f2d709 100644 --- a/crates/lang/Cargo.toml +++ b/crates/lang/Cargo.toml @@ -5,4 +5,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] \ No newline at end of file +[dependencies] +chumsky = "0.8.0" +internment = "0.7.0" +miette = "5.2.0" From 46057d62dca5b65a1e15918d0ee95b350cff18c1 Mon Sep 17 00:00:00 2001 From: rvcas Date: Fri, 5 Aug 2022 15:48:45 -0400 Subject: [PATCH 03/18] chore: update lock file --- Cargo.lock | 219 +++++++++++++++++++++++++++-------------------------- 1 file changed, 112 insertions(+), 107 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41f7068c..e87fda1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,9 +45,9 @@ dependencies = ["chumsky", "internment", "miette"] [[package]] name = "anyhow" -version = "1.0.57" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +checksum = "c91f1f46651137be86f3a2b9a8359f9ab421d04d941c62b5982e1ca21113adf9" [[package]] name = "arrayvec" @@ -82,9 +82,9 @@ checksum = "c5738be7561b0eeb501ef1d5c5db3f24e01ceb55fededd9b00039aada34966ad" [[package]] name = "bit-set" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" dependencies = ["bit-vec"] [[package]] @@ -120,16 +120,16 @@ dependencies = ["ahash 0.3.8"] [[package]] name = "clap" -version = "3.1.18" +version = "3.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" +checksum = "a3dbbb6653e7c55cc8595ad3e1f7be8f32aba4eb7ff7f0fd1163d4f3d137c0a9" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", "indexmap", - "lazy_static", + "once_cell", "strsim", "termcolor", "textwrap", @@ -137,26 +137,19 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.1.18" +version = "3.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" +checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" dependencies = ["heck", "proc-macro-error", "proc-macro2", "quote", "syn"] [[package]] name = "clap_lex" -version = "0.2.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = ["os_str_bytes"] [[package]] -<<<<<<< HEAD -name = "cryptoxide" - -======= -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129eabb7b0b78644a3a7e7cf220714aba47463bb281f69fa7a71ca5d12564cca" name = "const-random" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -171,18 +164,22 @@ checksum = "615f6e27d000a2bffbc7f2f6a8669179378fa27ee4d0a509e985dfc0a7defb40" dependencies = ["getrandom", "lazy_static", "proc-macro-hack", "tiny-keccak"] [[package]] - ->>>>>>> 1281557 (feat: add deps) - name = "crunchy" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "cryptoxide" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "129eabb7b0b78644a3a7e7cf220714aba47463bb281f69fa7a71ca5d12564cca" + [[package]] name = "fastrand" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = ["instant"] [[package]] @@ -218,12 +215,6 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - [[package]] name = "hashbrown" version = "0.12.3" @@ -252,10 +243,10 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "indexmap" -version = "1.8.1" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" -dependencies = ["autocfg", "hashbrown 0.11.2"] +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = ["autocfg", "hashbrown"] [[package]] name = "instant" @@ -265,21 +256,18 @@ checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = ["cfg-if"] [[package]] -<<<<<<< HEAD -name = "itoa" - -======= - ->>>>>>> 1281557 (feat: add deps) - -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" name = "internment" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a798d7677f07d6f1e77be484ea8626ddb1566194de399f1206306820c406371" -dependencies = ["hashbrown 0.12.3", "parking_lot"] +dependencies = ["hashbrown", "parking_lot"] + +[[package]] +name = "itoa" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" + [[package]] name = "lazy_static" version = "1.4.0" @@ -288,9 +276,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" [[package]] name = "lock_api" @@ -307,7 +295,20 @@ checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = ["cfg-if"] [[package]] -<<<<<<< HEAD +name = "miette" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2c9d50e919ffdc4d2d83b83972a13e8ba86ba8245a205bee9e314d593c15a8" +dependencies = ["miette-derive", "once_cell", "thiserror", "unicode-width"] + +[[package]] +name = "miette-derive" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8d10c73bcc9f0ab5c918521dab23d178062a56e6b328eb37106d497280bd94" +dependencies = ["proc-macro2", "quote", "syn"] + +[[package]] name = "minicbor" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -329,25 +330,10 @@ checksum = "d0a86c5f04def8fb7735ae918bb589af82f985526f4c62e0249544b668b2f456" dependencies = ["proc-macro2", "quote", "syn"] [[package]] - -======= name = "minicbor-derive" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8608fb1c805b5b6b3d5ab7bd95c40c396df622b64d77b2d621a5eae1eed050ee" -name = "miette" -version = "5.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2c9d50e919ffdc4d2d83b83972a13e8ba86ba8245a205bee9e314d593c15a8" -dependencies = ["miette-derive", "once_cell", "thiserror", "unicode-width"] - -[[package]] - ->>>>>>> 1281557 (feat: add deps) -name = "miette-derive" -version = "5.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c8d10c73bcc9f0ab5c918521dab23d178062a56e6b328eb37106d497280bd94" dependencies = ["proc-macro2", "quote", "syn"] [[package]] @@ -365,12 +351,11 @@ checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "os_str_bytes" -version = "6.0.1" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435" +checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] -<<<<<<< HEAD name = "pallas-codec" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -385,25 +370,25 @@ checksum = "051226367cd851895c73e3115d378b58495ade1ee60c3a154c0d0c30554565fa" dependencies = ["cryptoxide", "hex", "pallas-codec", "rand_core", "thiserror"] [[package]] -dependencies = [ - "base58", - "bech32", - "hex", - "log", - "pallas-codec", - "pallas-crypto", - "serde", - "serde_json", -======= -name = "parking_lot" -version = "0.12.1" +name = "pallas-primitives" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "97a0fcc7d5a7120bc2b2e203ec5e7f8088107c500c0eb665569d0e77a910d3c0" dependencies = [ - "lock_api", - "parking_lot_core", + "base58", + "bech32", + "hex", + "log", + "pallas-codec", + "pallas-crypto", + "serde", + "serde_json", ] +[[package]] + + +<<<<<<< HEAD [[package]]dependencies = [ "cfg-if", "libc", @@ -412,14 +397,29 @@ dependencies = [ "windows-sys", >>>>>>> 1281557 (feat: add deps) ]name = "pallas-primitives" + +======= +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = ["lock_api", "parking_lot_core"] version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97a0fcc7d5a7120bc2b2e203ec5e7f8088107c500c0eb665569d0e77a910d3c0" +[[package]] +>>>>>>> 70e1d06 (chore: update lock file) + +<<<<<<< HEAD +======= + +>>>>>>> 70e1d06 (chore: update lock file) + name = "parking_lot_core" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" - +dependencies = ["cfg-if", "libc", "redox_syscall", "smallvec", "windows-sys"] [[package]] name = "peg" version = "0.8.0" @@ -481,9 +481,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = ["unicode-ident"] [[package]] @@ -520,9 +520,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quote" -version = "1.0.18" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = ["proc-macro2"] [[package]] @@ -555,16 +555,16 @@ dependencies = ["rand_core"] [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = ["bitflags"] [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "remove_dir_all" @@ -581,12 +581,17 @@ checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = ["fnv", "quick-error 1.2.3", "tempfile", "wait-timeout"] [[package]] -<<<<<<< HEAD name = "ryu" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "serde" version = "1.0.142" @@ -594,26 +599,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2" [[package]] - -======= name = "serde_json" version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" dependencies = ["itoa", "ryu", "serde"] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] - ->>>>>>> 1281557 (feat: add deps) - name = "smallvec" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + [[package]] name = "strsim" version = "0.10.0" @@ -622,9 +619,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.95" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = ["proc-macro2", "quote", "unicode-ident"] [[package]] @@ -656,16 +653,16 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" dependencies = ["thiserror-impl"] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" dependencies = ["proc-macro2", "quote", "syn"] [[package]] @@ -683,9 +680,9 @@ checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" [[package]] name = "unicode-ident" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-segmentation" @@ -714,8 +711,11 @@ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" >>>>>>> c50961c (feat: add deps) >>>>>>> 508f3c6 (feat: add deps) dependencies = [ +<<<<<<< HEAD <<<<<<< HEAD "cryptoxide", +======= +>>>>>>> 70e1d06 (chore: update lock file) "flat-rs", "hex", "minicbor 0.18.0", @@ -725,6 +725,7 @@ dependencies = [ "pretty", "proptest", "thiserror", +<<<<<<< HEAD ======= "flat-rs", "hex", @@ -736,8 +737,12 @@ dependencies = [ "thiserror", >>>>>>> 273fa4a (feat: add deps) ]name = "uplc" -version = "0.0.7" +======= +] +>>>>>>> 70e1d06 (chore: update lock file) + +version = "0.0.7" [[package]] name = "version_check" version = "0.9.4" From 35143f1544dc07d0d1247259885429aa1aa46f86 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 8 Aug 2022 14:58:29 -0400 Subject: [PATCH 04/18] feat: add the ast module --- crates/lang/src/ast.rs | 5 +++++ crates/lang/src/lib.rs | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 crates/lang/src/ast.rs diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs new file mode 100644 index 00000000..5541619b --- /dev/null +++ b/crates/lang/src/ast.rs @@ -0,0 +1,5 @@ +pub struct Module {} + +pub enum Decl {} + +pub enum Expr {} diff --git a/crates/lang/src/lib.rs b/crates/lang/src/lib.rs index 1b4a90c9..660c3de9 100644 --- a/crates/lang/src/lib.rs +++ b/crates/lang/src/lib.rs @@ -1,3 +1,5 @@ +pub mod ast; + #[cfg(test)] mod tests { #[test] From 5a9ec708ee85e80618cb0738685806a6d6e60ad6 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 8 Aug 2022 15:03:42 -0400 Subject: [PATCH 05/18] chore: update lock file --- Cargo.lock | 427 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 288 insertions(+), 139 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e87fda1a..43f9a7f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,14 +7,20 @@ name = "ahash" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" -dependencies = ["const-random"] +dependencies = [ + "const-random", +] [[package]] name = "ahash" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = ["getrandom", "once_cell", "version_check"] +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] [[package]] name = "aiken" @@ -35,19 +41,31 @@ dependencies = [ ] ======= version = "0.0.7" +<<<<<<< HEAD dependencies = ["anyhow", "clap", "uplc"] >>>>>>> 27331bc (feat: add deps) +======= +dependencies = [ + "anyhow", + "clap", + "uplc", +] +>>>>>>> 1ba348e (chore: update lock file) [[package]] name = "aiken-lang" version = "0.0.0" -dependencies = ["chumsky", "internment", "miette"] +dependencies = [ + "chumsky", + "internment", + "miette", +] [[package]] name = "anyhow" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c91f1f46651137be86f3a2b9a8359f9ab421d04d941c62b5982e1ca21113adf9" +checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" [[package]] name = "arrayvec" @@ -60,7 +78,11 @@ name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = ["hermit-abi", "libc", "winapi"] +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] [[package]] name = "autocfg" @@ -85,7 +107,9 @@ name = "bit-set" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = ["bit-vec"] +dependencies = [ + "bit-vec", +] [[package]] name = "bit-vec" @@ -116,7 +140,9 @@ name = "chumsky" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d02796e4586c6c41aeb68eae9bfb4558a522c35f1430c14b40136c3706e09e4" -dependencies = ["ahash 0.3.8"] +dependencies = [ + "ahash 0.3.8", +] [[package]] name = "clap" @@ -124,15 +150,15 @@ version = "3.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3dbbb6653e7c55cc8595ad3e1f7be8f32aba4eb7ff7f0fd1163d4f3d137c0a9" dependencies = [ - "atty", - "bitflags", - "clap_derive", - "clap_lex", - "indexmap", - "once_cell", - "strsim", - "termcolor", - "textwrap", + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", ] [[package]] @@ -140,28 +166,44 @@ name = "clap_derive" version = "3.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" -dependencies = ["heck", "proc-macro-error", "proc-macro2", "quote", "syn"] +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] [[package]] name = "clap_lex" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = ["os_str_bytes"] +dependencies = [ + "os_str_bytes", +] [[package]] name = "const-random" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f590d95d011aa80b063ffe3253422ed5aa462af4e9867d43ce8337562bac77c4" -dependencies = ["const-random-macro", "proc-macro-hack"] +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] [[package]] name = "const-random-macro" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "615f6e27d000a2bffbc7f2f6a8669179378fa27ee4d0a509e985dfc0a7defb40" -dependencies = ["getrandom", "lazy_static", "proc-macro-hack", "tiny-keccak"] +dependencies = [ + "getrandom", + "lazy_static", + "proc-macro-hack", + "tiny-keccak", +] [[package]] name = "crunchy" @@ -180,7 +222,9 @@ name = "fastrand" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" -dependencies = ["instant"] +dependencies = [ + "instant", +] [[package]] name = "flat-rs" @@ -193,8 +237,15 @@ dependencies = [ ] ======= version = "0.0.7" +<<<<<<< HEAD dependencies = ["anyhow", "thiserror"] >>>>>>> c50961c (feat: add deps) +======= +dependencies = [ + "anyhow", + "thiserror", +] +>>>>>>> 2f7eda3 (chore: update lock file) [[package]] name = "fnv" @@ -207,7 +258,11 @@ name = "getrandom" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = ["cfg-if", "libc", "wasi"] +dependencies = [ + "cfg-if", + "libc", + "wasi", +] [[package]] name = "half" @@ -220,7 +275,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = ["ahash 0.7.6"] +dependencies = [ + "ahash 0.7.6", +] [[package]] name = "heck" @@ -233,7 +290,9 @@ name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = ["libc"] +dependencies = [ + "libc", +] [[package]] name = "hex" @@ -246,21 +305,29 @@ name = "indexmap" version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = ["autocfg", "hashbrown"] +dependencies = [ + "autocfg", + "hashbrown", +] [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = ["cfg-if"] +dependencies = [ + "cfg-if", +] [[package]] name = "internment" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a798d7677f07d6f1e77be484ea8626ddb1566194de399f1206306820c406371" -dependencies = ["hashbrown", "parking_lot"] +dependencies = [ + "hashbrown", + "parking_lot", +] [[package]] name = "itoa" @@ -285,63 +352,92 @@ name = "lock_api" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" -dependencies = ["autocfg", "scopeguard"] +dependencies = [ + "autocfg", + "scopeguard", +] [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = ["cfg-if"] +dependencies = [ + "cfg-if", +] [[package]] name = "miette" version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e2c9d50e919ffdc4d2d83b83972a13e8ba86ba8245a205bee9e314d593c15a8" -dependencies = ["miette-derive", "once_cell", "thiserror", "unicode-width"] +dependencies = [ + "miette-derive", + "once_cell", + "thiserror", + "unicode-width", +] [[package]] name = "miette-derive" version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c8d10c73bcc9f0ab5c918521dab23d178062a56e6b328eb37106d497280bd94" -dependencies = ["proc-macro2", "quote", "syn"] +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "minicbor" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5e575910763b21a0db7df5e142907fe944bff84d1dfc78e2ba92e7f3bdfd36b" -dependencies = ["half", "minicbor-derive 0.11.0"] +dependencies = [ + "half", + "minicbor-derive 0.11.0", +] [[package]] name = "minicbor" version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a20020e8e2d1881d8736f64011bb5ff99f1db9947ce3089706945c8915695cb" -dependencies = ["minicbor-derive 0.12.0"] +dependencies = [ + "minicbor-derive 0.12.0", +] [[package]] name = "minicbor-derive" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a86c5f04def8fb7735ae918bb589af82f985526f4c62e0249544b668b2f456" -dependencies = ["proc-macro2", "quote", "syn"] +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "minicbor-derive" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8608fb1c805b5b6b3d5ab7bd95c40c396df622b64d77b2d621a5eae1eed050ee" -dependencies = ["proc-macro2", "quote", "syn"] +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "num-traits" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = ["autocfg"] +dependencies = [ + "autocfg", +] [[package]] name = "once_cell" @@ -360,14 +456,22 @@ name = "pallas-codec" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dce0ea17341c1a0e43e2bb4a637740198dcb09826879ce3ac5ae1c6f4398a5d" -dependencies = ["minicbor 0.17.1"] +dependencies = [ + "minicbor 0.17.1", +] [[package]] name = "pallas-crypto" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "051226367cd851895c73e3115d378b58495ade1ee60c3a154c0d0c30554565fa" -dependencies = ["cryptoxide", "hex", "pallas-codec", "rand_core", "thiserror"] +dependencies = [ + "cryptoxide", + "hex", + "pallas-codec", + "rand_core", + "thiserror", +] [[package]] name = "pallas-primitives" @@ -375,64 +479,59 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97a0fcc7d5a7120bc2b2e203ec5e7f8088107c500c0eb665569d0e77a910d3c0" dependencies = [ - "base58", - "bech32", - "hex", - "log", - "pallas-codec", - "pallas-crypto", - "serde", - "serde_json", + "base58", + "bech32", + "hex", + "log", + "pallas-codec", + "pallas-crypto", + "serde", + "serde_json", ] [[package]] - - -<<<<<<< HEAD -[[package]]dependencies = [ -"cfg-if", -"libc", -"redox_syscall", -"smallvec", -"windows-sys", ->>>>>>> 1281557 (feat: add deps) -]name = "pallas-primitives" - -======= name = "parking_lot" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = ["lock_api", "parking_lot_core"] -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a0fcc7d5a7120bc2b2e203ec5e7f8088107c500c0eb665569d0e77a910d3c0" +dependencies = [ + "lock_api", + "parking_lot_core", +] + [[package]] ->>>>>>> 70e1d06 (chore: update lock file) - -<<<<<<< HEAD -======= - ->>>>>>> 70e1d06 (chore: update lock file) - name = "parking_lot_core" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" -dependencies = ["cfg-if", "libc", "redox_syscall", "smallvec", "windows-sys"] +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + [[package]] name = "peg" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af728fe826811af3b38c37e93de6d104485953ea373d656eebae53d6987fcd2c" -dependencies = ["peg-macros", "peg-runtime"] +dependencies = [ + "peg-macros", + "peg-runtime", +] [[package]] name = "peg-macros" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4536be147b770b824895cbad934fccce8e49f14b4c4946eaa46a6e4a12fcdc16" -dependencies = ["peg-runtime", "proc-macro2", "quote"] +dependencies = [ + "peg-runtime", + "proc-macro2", + "quote", +] [[package]] name = "peg-runtime" @@ -451,7 +550,12 @@ name = "pretty" version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83f3aa1e3ca87d3b124db7461265ac176b40c277f37e503eaa29c9c75c037846" -dependencies = ["arrayvec", "log", "typed-arena", "unicode-segmentation"] +dependencies = [ + "arrayvec", + "log", + "typed-arena", + "unicode-segmentation", +] [[package]] name = "proc-macro-error" @@ -459,11 +563,11 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", ] [[package]] @@ -471,7 +575,11 @@ name = "proc-macro-error-attr" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = ["proc-macro2", "quote", "version_check"] +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] [[package]] name = "proc-macro-hack" @@ -484,7 +592,9 @@ name = "proc-macro2" version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -dependencies = ["unicode-ident"] +dependencies = [ + "unicode-ident", +] [[package]] name = "proptest" @@ -492,18 +602,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5" dependencies = [ - "bit-set", - "bitflags", - "byteorder", - "lazy_static", - "num-traits", - "quick-error 2.0.1", - "rand", - "rand_chacha", - "rand_xorshift", - "regex-syntax", - "rusty-fork", - "tempfile", + "bit-set", + "bitflags", + "byteorder", + "lazy_static", + "num-traits", + "quick-error 2.0.1", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", ] [[package]] @@ -523,42 +633,57 @@ name = "quote" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = ["proc-macro2"] +dependencies = [ + "proc-macro2", +] [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = ["libc", "rand_chacha", "rand_core"] +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] [[package]] name = "rand_chacha" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = ["ppv-lite86", "rand_core"] +dependencies = [ + "ppv-lite86", + "rand_core", +] [[package]] name = "rand_core" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -dependencies = ["getrandom"] +dependencies = [ + "getrandom", +] [[package]] name = "rand_xorshift" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -dependencies = ["rand_core"] +dependencies = [ + "rand_core", +] [[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = ["bitflags"] +dependencies = [ + "bitflags", +] [[package]] name = "regex-syntax" @@ -571,14 +696,21 @@ name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = ["winapi"] +dependencies = [ + "winapi", +] [[package]] name = "rusty-fork" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = ["fnv", "quick-error 1.2.3", "tempfile", "wait-timeout"] +dependencies = [ + "fnv", + "quick-error 1.2.3", + "tempfile", + "wait-timeout", +] [[package]] name = "ryu" @@ -603,7 +735,11 @@ name = "serde_json" version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" -dependencies = ["itoa", "ryu", "serde"] +dependencies = [ + "itoa", + "ryu", + "serde", +] [[package]] name = "smallvec" @@ -622,7 +758,11 @@ name = "syn" version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" -dependencies = ["proc-macro2", "quote", "unicode-ident"] +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] name = "tempfile" @@ -630,12 +770,12 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", ] [[package]] @@ -643,7 +783,9 @@ name = "termcolor" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = ["winapi-util"] +dependencies = [ + "winapi-util", +] [[package]] name = "textwrap" @@ -656,21 +798,29 @@ name = "thiserror" version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" -dependencies = ["thiserror-impl"] +dependencies = [ + "thiserror-impl", +] [[package]] name = "thiserror-impl" version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" -dependencies = ["proc-macro2", "quote", "syn"] +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "tiny-keccak" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = ["crunchy"] +dependencies = [ + "crunchy", +] [[package]] name = "typed-arena" @@ -707,7 +857,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] +<<<<<<< HEAD >>>>>>> 27331bc (feat: add deps) +<<<<<<< HEAD >>>>>>> c50961c (feat: add deps) >>>>>>> 508f3c6 (feat: add deps) dependencies = [ @@ -715,7 +867,13 @@ dependencies = [ <<<<<<< HEAD "cryptoxide", ======= ->>>>>>> 70e1d06 (chore: update lock file) +>>>>>>> 2f7eda3 (chore: update lock file) +======= +name = "uplc" +version = "0.0.7" +>>>>>>> 1ba348e (chore: update lock file) +dependencies = [ + "cryptoxide", "flat-rs", "hex", "minicbor 0.18.0", @@ -725,24 +883,8 @@ dependencies = [ "pretty", "proptest", "thiserror", -<<<<<<< HEAD -======= - "flat-rs", - "hex", - "minicbor 0.18.0", - "pallas-primitives", - "peg", - "pretty", - "proptest", - "thiserror", ->>>>>>> 273fa4a (feat: add deps) -]name = "uplc" - -======= ] ->>>>>>> 70e1d06 (chore: update lock file) -version = "0.0.7" [[package]] name = "version_check" version = "0.9.4" @@ -754,7 +896,9 @@ name = "wait-timeout" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -dependencies = ["libc"] +dependencies = [ + "libc", +] [[package]] name = "wasi" @@ -767,7 +911,10 @@ name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = ["winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu"] +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] [[package]] name = "winapi-i686-pc-windows-gnu" @@ -780,7 +927,9 @@ name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = ["winapi"] +dependencies = [ + "winapi", +] [[package]] name = "winapi-x86_64-pc-windows-gnu" @@ -794,11 +943,11 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", ] [[package]] From 208f2e80eae5128e154b0863f526f039e0fd7d0c Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 10 Aug 2022 15:50:19 -0400 Subject: [PATCH 06/18] feat: more ast elements and some sample syntax --- crates/lang/src/ast.rs | 46 +++++++++++++++++++++++++++-- syntax.txt | 66 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 syntax.txt diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs index 5541619b..c8f8c0e4 100644 --- a/crates/lang/src/ast.rs +++ b/crates/lang/src/ast.rs @@ -1,5 +1,47 @@ -pub struct Module {} +pub struct Module { + pub name: Vec, + pub docs: Vec, + pub is_script: bool, + pub is_lib: bool, + pub is_policy: bool, +} -pub enum Decl {} +pub enum Definition { + Fn { + arguments: Vec, + body: Expr, + doc: Option, + name: String, + public: bool, + return_annotation: Option<()>, + return_type: (), + }, + + TypeAlias { + alias: String, + annotation: (), + doc: Option, + parameters: Vec, + public: bool, + tipo: (), + }, + + DataType { + constructors: Vec<()>, + doc: Option, + name: String, + opaque: bool, + parameters: Vec, + public: bool, + typed_parameters: Vec<()>, + }, + + Use { + module: Vec, + as_name: Option, + // unqualified: Vec, + // package: PackageName, + }, +} pub enum Expr {} diff --git a/syntax.txt b/syntax.txt new file mode 100644 index 00000000..b71a8d3e --- /dev/null +++ b/syntax.txt @@ -0,0 +1,66 @@ +// imports +use std/address.Address as A // alias + +use std/list.{map, foldl} // access module members in one import + +// `///` used for document generation + +// Records (single constructor `data` type) +pub type Datum { + signer: Address, +} + +// above is suger for +pub type Datum { + Datum { signer: Address }, +} + +// type aliases +type A = Address + +// multiple constructors and a `generic` +pub type Redeemer(a) { + // records wrapped in parens + Buy(Address, a), + // records wrapped in curlies + Sell { address: Address, some_thing: a }, +} + +pub fn main(datum: Datum, redeemer: Redeemer, ctx: ScriptContext) { + [1, 2, 3] + |> list.map(fn(x) -> x + 1) +} + +// named and anonymous functions +fn(x) -> x + 1 + +fn add_one(x) -> x + 1 + +fn(x: Int) -> x + 1 + +fn add_one(label x: Int) -> x + 1 + +fn(x: Int) { + x + 1 +} + +fn(x: Int) -> Int { + x + 1 +} + +fn add_one(x: Int) -> Int { + x + 1 +} + +// can be curried +fn add(a, b) { + a + 1 +} + +let add_one = add(1) + +// matching +when redeemer is { + Buyer(address, thing) -> do_stuff(), + Seller { address, some_thing } -> do_seller_stuff(), +} From 1d6809661c1a81efb66239f073a85d4c058a641d Mon Sep 17 00:00:00 2001 From: rvcas Date: Fri, 12 Aug 2022 19:44:34 -0400 Subject: [PATCH 07/18] feat: lexer --- Cargo.lock | 7 + crates/cli/src/args.rs | 47 +++- crates/cli/src/main.rs | 28 +++ crates/lang/Cargo.toml | 1 + crates/lang/src/ast.rs | 492 ++++++++++++++++++++++++++++++++++++-- crates/lang/src/build.rs | 4 + crates/lang/src/error.rs | 109 +++++++++ crates/lang/src/expr.rs | 269 +++++++++++++++++++++ crates/lang/src/lexer.rs | 163 +++++++++++++ crates/lang/src/lib.rs | 16 +- crates/lang/src/parser.rs | 7 + crates/lang/src/tipo.rs | 159 ++++++++++++ crates/lang/src/token.rs | 149 ++++++++++++ 13 files changed, 1414 insertions(+), 37 deletions(-) create mode 100644 crates/lang/src/build.rs create mode 100644 crates/lang/src/error.rs create mode 100644 crates/lang/src/expr.rs create mode 100644 crates/lang/src/lexer.rs create mode 100644 crates/lang/src/parser.rs create mode 100644 crates/lang/src/tipo.rs create mode 100644 crates/lang/src/token.rs diff --git a/Cargo.lock b/Cargo.lock index 43f9a7f0..dd4f828a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,6 +59,7 @@ dependencies = [ "chumsky", "internment", "miette", + "vec1", ] [[package]] @@ -885,6 +886,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "vec1" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc1631c774f0f9570797191e01247cbefde789eebfbf128074cb934115a6133" + [[package]] name = "version_check" version = "0.9.4" diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index fcbe306c..8e60cbf7 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -7,6 +7,15 @@ use clap::{Parser, Subcommand}; #[clap(version, about, long_about = None)] #[clap(propagate_version = true)] pub enum Args { + /// Build an aiken project + Build, + /// Start a development server + Dev, + /// Create a new aiken project + New { + /// Project name + name: PathBuf, + }, /// A subcommand for working with Untyped Plutus Core #[clap(subcommand)] Uplc(UplcCommand), @@ -15,33 +24,49 @@ pub enum Args { /// Commands for working with Untyped Plutus Core #[derive(Subcommand)] pub enum UplcCommand { + /// Evaluate an Untyped Plutus Core program + Eval { + /// Handle input as flat bytes + #[clap(short, long)] + flat: bool, + + /// File to load and evaluate + input: PathBuf, + }, /// Encode textual Untyped Plutus Core to flat bytes Flat { + /// Textual Untyped Plutus Core file input: PathBuf, - #[clap(short, long)] - print: bool, + + /// Output file name #[clap(short, long)] out: Option, - }, - /// Decode flat bytes to textual Untyped Plutus Core - Unflat { - input: PathBuf, + + /// Print output instead of saving to file #[clap(short, long)] print: bool, - #[clap(short, long)] - out: Option, }, /// Format an Untyped Plutus Core program Fmt { + /// Textual Untyped Plutus Core file input: PathBuf, + + /// Print output instead of saving to file #[clap(short, long)] print: bool, }, - /// Evaluate an Untyped Plutus Core program - Eval { + /// Decode flat bytes to textual Untyped Plutus Core + Unflat { + /// Flat encoded Untyped Plutus Core file input: PathBuf, + + /// Output file name #[clap(short, long)] - flat: bool, + out: Option, + + /// Print output instead of saving to file + #[clap(short, long)] + print: bool, }, } diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 4bc26704..bd973694 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -14,6 +14,31 @@ fn main() -> anyhow::Result<()> { let args = Args::default(); match args { + Args::Build => { + // 1. load and parse modules + // * lib - contains modules, types, and functions + // * contracts - contains validators + // * scripts - contains native scripts dsl + // 2. type check everything + // 3. generate uplc and policy/address if relevant + todo!() + } + + Args::Dev => { + // launch a development server + // this should allow people to test + // their contracts over http + todo!() + } + + Args::New { name } => { + if !name.exists() { + fs::create_dir_all(name.join("lib"))?; + fs::create_dir_all(name.join("policies"))?; + fs::create_dir_all(name.join("scripts"))?; + } + } + Args::Uplc(uplc) => match uplc { UplcCommand::Flat { input, print, out } => { let code = std::fs::read_to_string(&input)?; @@ -48,6 +73,7 @@ fn main() -> anyhow::Result<()> { fs::write(&out_name, &bytes)?; } } + UplcCommand::Fmt { input, print } => { let code = std::fs::read_to_string(&input)?; @@ -61,6 +87,7 @@ fn main() -> anyhow::Result<()> { fs::write(&input, pretty)?; } } + UplcCommand::Unflat { input, print, out } => { let bytes = std::fs::read(&input)?; @@ -82,6 +109,7 @@ fn main() -> anyhow::Result<()> { fs::write(&out_name, pretty)?; } } + UplcCommand::Eval { input, flat } => { let program = if flat { let bytes = std::fs::read(&input)?; diff --git a/crates/lang/Cargo.toml b/crates/lang/Cargo.toml index d2f2d709..d04d8465 100644 --- a/crates/lang/Cargo.toml +++ b/crates/lang/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" chumsky = "0.8.0" internment = "0.7.0" miette = "5.2.0" +vec1 = "1.8.0" diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs index c8f8c0e4..d4eae330 100644 --- a/crates/lang/src/ast.rs +++ b/crates/lang/src/ast.rs @@ -1,47 +1,505 @@ -pub struct Module { - pub name: Vec, - pub docs: Vec, - pub is_script: bool, - pub is_lib: bool, - pub is_policy: bool, +use std::{collections::HashMap, fmt, ops::Range, sync::Arc}; + +use internment::Intern; + +use crate::{ + expr::{TypedExpr, UntypedExpr}, + tipo::{self, PatternConstructor, Type, ValueConstructor}, +}; + +pub type TypedModule = Module; +pub type UntypedModule = Module<(), UntypedDefinition>; + +pub enum ModuleKind { + Contract, + Lib, + Script, } -pub enum Definition { +pub struct Module { + pub name: Vec, + pub docs: Vec, + pub type_info: Info, + pub definitons: Vec, + pub kind: ModuleKind, +} + +pub type TypedDefinition = Definition, TypedExpr, String, String>; +pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>; + +pub enum Definition { Fn { - arguments: Vec, + location: Span, + arguments: Vec>>, body: Expr, doc: Option, name: String, public: bool, - return_annotation: Option<()>, - return_type: (), + return_annotation: Option, + return_type: T, }, TypeAlias { + location: Span, alias: String, - annotation: (), + annotation: Annotation, doc: Option, parameters: Vec, public: bool, - tipo: (), + tipo: T, }, DataType { - constructors: Vec<()>, + location: Span, + constructors: Vec>, doc: Option, name: String, opaque: bool, parameters: Vec, public: bool, - typed_parameters: Vec<()>, + typed_parameters: Vec, }, Use { module: Vec, as_name: Option, - // unqualified: Vec, - // package: PackageName, + unqualified: Vec, + package: PackageName, + }, + + ModuleConstant { + doc: Option, + location: Span, + public: bool, + name: String, + annotation: Option, + value: Box>, + tipo: T, }, } -pub enum Expr {} +pub type TypedConstant = Constant, String>; +pub type UntypedConstant = Constant<(), ()>; + +pub enum Constant { + Int { + location: Span, + value: String, + }, + + String { + location: Span, + value: String, + }, + + Pair { + location: Span, + elements: Vec, + }, + + List { + location: Span, + elements: Vec, + tipo: T, + }, + + Record { + location: Span, + module: Option, + name: String, + args: Vec>, + tag: RecordTag, + tipo: T, + field_map: Option, + }, + + ByteString { + location: Span, + // segments: Vec>, + }, + + Var { + location: Span, + module: Option, + name: String, + constructor: Option>, + tipo: T, + }, +} + +pub struct CallArg { + pub label: Option, + pub location: Span, + pub value: A, +} + +pub struct FieldMap { + pub arity: usize, + pub fields: HashMap, +} + +pub struct RecordConstructor { + pub location: Span, + pub name: String, + pub arguments: Vec>, + pub documentation: Option, +} + +pub struct RecordConstructorArg { + pub label: Option, + // ast + pub annotation: Annotation, + pub location: Span, + pub tipo: T, + pub doc: Option, +} + +pub struct Arg { + pub names: ArgName, + pub location: Span, + pub annotation: Option, + pub tipo: T, +} + +pub enum ArgName { + Discard { name: String }, + LabeledDiscard { label: String, name: String }, + Named { name: String }, + NamedLabeled { name: String, label: String }, +} + +pub struct UnqualifiedImport { + pub location: Span, + pub name: String, + pub as_name: Option, + pub layer: Layer, +} + +// TypeAst +pub enum Annotation { + Constructor { + location: Span, + module: Option, + name: String, + arguments: Vec, + }, + + Fn { + location: Span, + arguments: Vec, + ret: Box, + }, + + Var { + location: Span, + name: String, + }, + + Tuple { + location: Span, + elems: Vec, + }, + + Hole { + location: Span, + name: String, + }, +} + +pub enum Layer { + Value, + Type, +} + +impl Default for Layer { + fn default() -> Self { + Layer::Value + } +} + +pub enum BinOp { + // Boolean logic + And, + Or, + + // Equality + Eq, + NotEq, + + // Order comparison + LtInt, + LtEqInt, + GtEqInt, + GtInt, + + // Maths + AddInt, + SubInt, + MultInt, + DivInt, + ModInt, +} + +pub enum Pattern { + Int { + location: Span, + value: String, + }, + + Float { + location: Span, + value: String, + }, + + String { + location: Span, + value: String, + }, + + /// The creation of a variable. + /// e.g. `assert [this_is_a_var, .._] = x` + Var { + location: Span, + name: String, + }, + + /// A reference to a variable in a bit string. This is always a variable + /// being used rather than a new variable being assigned. + VarUsage { + location: Span, + name: String, + tipo: Type, + }, + + /// A name given to a sub-pattern using the `as` keyword. + /// e.g. `assert #(1, [_, _] as the_list) = x` + Assign { + name: String, + location: Span, + pattern: Box, + }, + + /// A pattern that binds to any value but does not assign a variable. + /// Always starts with an underscore. + Discard { + name: String, + location: Span, + }, + + List { + location: Span, + elements: Vec, + tail: Option>, + }, + + /// The constructor for a custom type. Starts with an uppercase letter. + Constructor { + location: Span, + name: String, + arguments: Vec>, + module: Option, + constructor: Constructor, + with_spread: bool, + tipo: Type, + }, + + Tuple { + location: Span, + elems: Vec, + }, +} + +pub enum AssignmentKind { + Let, + Assert, +} + +pub type MultiPattern = Vec>; + +pub type UntypedMultiPattern = MultiPattern<(), ()>; +pub type TypedMultiPattern = MultiPattern>; + +pub type TypedClause = Clause, String>; + +pub type UntypedClause = Clause; + +pub struct Clause { + pub location: Span, + pub pattern: MultiPattern, + pub alternative_patterns: Vec>, + pub guard: Option>, + pub then: Expr, +} + +pub enum ClauseGuard { + Equals { + location: Span, + left: Box, + right: Box, + }, + + NotEquals { + location: Span, + left: Box, + right: Box, + }, + + GtInt { + location: Span, + left: Box, + right: Box, + }, + + GtEqInt { + location: Span, + left: Box, + right: Box, + }, + + LtInt { + location: Span, + left: Box, + right: Box, + }, + + LtEqInt { + location: Span, + left: Box, + right: Box, + }, + + Or { + location: Span, + left: Box, + right: Box, + }, + + And { + location: Span, + left: Box, + right: Box, + }, + + Var { + location: Span, + tipo: Type, + name: String, + }, + + TupleIndex { + location: Span, + index: u64, + tipo: Type, + tuple: Box, + }, + + Constant(Constant), +} + +pub struct TypedRecordUpdateArg { + pub label: String, + pub location: Span, + pub value: TypedExpr, + pub index: usize, +} + +pub struct UntypedRecordUpdateArg { + pub label: String, + // pub location: SrcSpan, + pub value: UntypedExpr, +} + +pub struct RecordUpdateSpread { + pub base: Box, + pub location: Span, +} + +pub enum TodoKind { + Keyword, + EmptyFunction, +} + +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct SrcId(Intern>); + +impl SrcId { + #[cfg(test)] + pub fn empty() -> Self { + SrcId(Intern::new(Vec::new())) + } +} + +#[derive(Copy, Clone, PartialEq, Eq)] +pub struct Span { + pub src: SrcId, + pub start: usize, + pub end: usize, +} + +impl Span { + #[cfg(test)] + pub fn empty() -> Self { + use chumsky::Span; + + Self::new(SrcId::empty(), 0..0) + } + + pub fn src(&self) -> SrcId { + self.src + } + + pub fn range(&self) -> Range { + use chumsky::Span; + + self.start()..self.end() + } + + pub fn union(self, other: Self) -> Self { + use chumsky::Span; + + assert_eq!( + self.src, other.src, + "attempted to union spans with different sources" + ); + + Self { + start: self.start().min(other.start()), + end: self.end().max(other.end()), + ..self + } + } +} + +impl fmt::Debug for Span { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}:{:?}", self.src, self.range()) + } +} + +impl chumsky::Span for Span { + type Context = SrcId; + + type Offset = usize; + + fn new(context: Self::Context, range: Range) -> Self { + assert!(range.start <= range.end); + + Self { + src: context, + start: range.start, + end: range.end, + } + } + + fn context(&self) -> Self::Context { + self.src + } + + fn start(&self) -> Self::Offset { + self.start + } + + fn end(&self) -> Self::Offset { + self.end + } +} diff --git a/crates/lang/src/build.rs b/crates/lang/src/build.rs new file mode 100644 index 00000000..9070f46a --- /dev/null +++ b/crates/lang/src/build.rs @@ -0,0 +1,4 @@ +pub enum Origin { + Src, + Test, +} diff --git a/crates/lang/src/error.rs b/crates/lang/src/error.rs new file mode 100644 index 00000000..3c441615 --- /dev/null +++ b/crates/lang/src/error.rs @@ -0,0 +1,109 @@ +use std::{collections::HashSet, fmt}; + +use crate::{ast::Span, token::Token}; + +#[derive(Debug)] +pub struct ParseError { + kind: ErrorKind, + span: Span, + while_parsing: Option<(Span, &'static str)>, + expected: HashSet, + label: Option<&'static str>, +} + +impl ParseError { + pub fn merge(mut self, other: Self) -> Self { + // TODO: Use HashSet + for expected in other.expected.into_iter() { + self.expected.insert(expected); + } + self + } +} + +impl PartialEq for ParseError { + fn eq(&self, other: &Self) -> bool { + self.kind == other.kind && self.span == other.span && self.label == other.label + } +} + +impl> chumsky::Error for ParseError { + type Span = Span; + + type Label = &'static str; + + fn expected_input_found>>( + span: Self::Span, + expected: Iter, + found: Option, + ) -> Self { + Self { + kind: found + .map(Into::into) + .map(ErrorKind::Unexpected) + .unwrap_or(ErrorKind::UnexpectedEnd), + span, + while_parsing: None, + expected: expected + .into_iter() + .map(|x| x.map(Into::into).unwrap_or(Pattern::End)) + .collect(), + label: None, + } + } + + fn with_label(mut self, label: Self::Label) -> Self { + self.label.get_or_insert(label); + self + } + + fn merge(self, other: Self) -> Self { + ParseError::merge(self, other) + } +} + +#[derive(Debug, PartialEq, Eq)] +pub enum ErrorKind { + UnexpectedEnd, + Unexpected(Pattern), + Unclosed { + start: Pattern, + before_span: Span, + before: Option, + }, + NoEndBranch, +} + +#[derive(Debug, PartialEq, Eq, Hash)] +pub enum Pattern { + Char(char), + Token(Token), + Literal, + TypeIdent, + TermIdent, + End, +} + +impl From for Pattern { + fn from(c: char) -> Self { + Self::Char(c) + } +} +impl From for Pattern { + fn from(tok: Token) -> Self { + Self::Token(tok) + } +} + +impl fmt::Display for Pattern { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Pattern::Token(token) => write!(f, "{}", token), + Pattern::Char(c) => write!(f, "{:?}", c), + Pattern::Literal => write!(f, "literal"), + Pattern::TypeIdent => write!(f, "type name"), + Pattern::TermIdent => write!(f, "identifier"), + Pattern::End => write!(f, "end of input"), + } + } +} diff --git a/crates/lang/src/expr.rs b/crates/lang/src/expr.rs new file mode 100644 index 00000000..e3fd064e --- /dev/null +++ b/crates/lang/src/expr.rs @@ -0,0 +1,269 @@ +use std::sync::Arc; + +use vec1::Vec1; + +use crate::{ + ast::{ + Annotation, Arg, AssignmentKind, BinOp, CallArg, Clause, Pattern, RecordUpdateSpread, Span, + TodoKind, TypedRecordUpdateArg, UntypedRecordUpdateArg, + }, + tipo::{ModuleValueConstructor, PatternConstructor, Type, ValueConstructor}, +}; + +pub enum TypedExpr { + Int { + location: Span, + tipo: Arc, + value: String, + }, + + Float { + location: Span, + tipo: Arc, + value: String, + }, + + String { + location: Span, + tipo: Arc, + value: String, + }, + + Sequence { + location: Span, + expressions: Vec, + }, + + /// A chain of pipe expressions. + /// By this point the type checker has expanded it into a series of + /// assignments and function calls, but we still have a Pipeline AST node as + /// even though it is identical to `Sequence` we want to use different + /// locations when showing it in error messages, etc. + Pipeline { + location: Span, + expressions: Vec, + }, + + Var { + location: Span, + constructor: ValueConstructor, + name: String, + }, + + Fn { + location: Span, + tipo: Arc, + is_capture: bool, + args: Vec>>, + body: Box, + return_annotation: Option, + }, + + List { + location: Span, + tipo: Arc, + elements: Vec, + tail: Option>, + }, + + Call { + location: Span, + tipo: Arc, + fun: Box, + args: Vec>, + }, + + BinOp { + location: Span, + tipo: Arc, + name: BinOp, + left: Box, + right: Box, + }, + + Assignment { + location: Span, + tipo: Arc, + value: Box, + pattern: Pattern>, + kind: AssignmentKind, + }, + + Try { + location: Span, + tipo: Arc, + value: Box, + then: Box, + pattern: Pattern>, + }, + + When { + location: Span, + tipo: Arc, + subjects: Vec, + clauses: Vec, String>>, + }, + + RecordAccess { + location: Span, + tipo: Arc, + label: String, + index: u64, + record: Box, + }, + + ModuleSelect { + location: Span, + tipo: Arc, + label: String, + module_name: String, + module_alias: String, + constructor: ModuleValueConstructor, + }, + + Tuple { + location: Span, + tipo: Arc, + elems: Vec, + }, + + TupleIndex { + location: Span, + tipo: Arc, + index: u64, + tuple: Box, + }, + + Todo { + location: Span, + label: Option, + tipo: Arc, + }, + + RecordUpdate { + location: Span, + tipo: Arc, + spread: Box, + args: Vec, + }, + + Negate { + location: Span, + value: Box, + }, +} + +pub enum UntypedExpr { + Int { + location: Span, + value: String, + }, + + Float { + location: Span, + value: String, + }, + + String { + location: Span, + value: String, + }, + + Sequence { + location: Span, + expressions: Vec, + }, + + Var { + location: Span, + name: String, + }, + + Fn { + location: Span, + is_capture: bool, + arguments: Vec>, + body: Box, + return_annotation: Option, + }, + + List { + location: Span, + elements: Vec, + tail: Option>, + }, + + Call { + location: Span, + fun: Box, + arguments: Vec>, + }, + + BinOp { + location: Span, + name: BinOp, + left: Box, + right: Box, + }, + + PipeLine { + expressions: Vec1, + }, + + Assignment { + location: Span, + value: Box, + pattern: Pattern<(), ()>, + kind: AssignmentKind, + annotation: Option, + }, + + Try { + location: Span, + value: Box, + pattern: Pattern<(), ()>, + then: Box, + annotation: Option, + }, + + Case { + location: Span, + subjects: Vec, + clauses: Vec>, + }, + + FieldAccess { + location: Span, + label: String, + container: Box, + }, + + Tuple { + location: Span, + elems: Vec, + }, + + TupleIndex { + location: Span, + index: u64, + tuple: Box, + }, + + Todo { + kind: TodoKind, + location: Span, + label: Option, + }, + + RecordUpdate { + location: Span, + constructor: Box, + spread: RecordUpdateSpread, + arguments: Vec, + }, + + Negate { + location: Span, + value: Box, + }, +} diff --git a/crates/lang/src/lexer.rs b/crates/lang/src/lexer.rs new file mode 100644 index 00000000..958538ba --- /dev/null +++ b/crates/lang/src/lexer.rs @@ -0,0 +1,163 @@ +use chumsky::prelude::*; +use internment::Intern; + +use crate::{ast::Span, error::ParseError, token::Token}; + +pub fn lexer() -> impl Parser, Error = ParseError> { + let int = text::int(10) + .map(Intern::new) + .map(|value| Token::Int { value }); + + let op = choice(( + just("==").to(Token::EqualEqual), + just('=').to(Token::Equal), + just("..").to(Token::Dot), + just('.').to(Token::Dot), + just("!=").to(Token::NotEqual), + just('!').to(Token::Bang), + just("<=").to(Token::LessEqual), + just('<').to(Token::Less), + just(">=").to(Token::GreaterEqual), + just('>').to(Token::Greater), + just('+').to(Token::Plus), + just("->").to(Token::RArrow), + just('-').to(Token::Minus), + just('*').to(Token::Star), + just('/').to(Token::Slash), + just('%').to(Token::Percent), + just("|>").to(Token::Pipe), + )); + + let grouping = choice(( + just('(').to(Token::LeftParen), + just(')').to(Token::RightParen), + just('[').to(Token::LeftSquare), + just(']').to(Token::RightSquare), + just('{').to(Token::LeftBrace), + just('}').to(Token::RightBrace), + )); + + let escape = just('\\').ignore_then( + just('\\') + .or(just('/')) + .or(just('"')) + .or(just('b').to('\x08')) + .or(just('f').to('\x0C')) + .or(just('n').to('\n')) + .or(just('r').to('\r')) + .or(just('t').to('\t')), + ); + + let string = just('"') + .ignore_then(filter(|c| *c != '\\' && *c != '"').or(escape).repeated()) + .then_ignore(just('"')) + .collect::() + .map(Intern::new) + .map(|value| Token::String { value }) + .labelled("string"); + + let keyword = text::ident().map(|s: String| match s.as_str() { + "as" => Token::As, + "assert" => Token::Assert, + "const" => Token::Const, + "fn" => Token::Fn, + "if" => Token::If, + "is" => Token::Is, + "let" => Token::Let, + "opaque" => Token::Opaque, + "pub" => Token::Pub, + "use" => Token::Use, + "todo" => Token::Todo, + "try" => Token::Try, + "type" => Token::Type, + "when" => Token::When, + _ => { + if s.chars().next().map_or(false, |c| c.is_uppercase()) { + Token::UpName { + // TODO: do not allow _ in upname + name: Intern::new(s), + } + } else if s.starts_with('_') { + Token::DiscardName { + // TODO: do not allow uppercase letters in discard name + name: Intern::new(s), + } + } else { + Token::Name { + // TODO: do not allow uppercase letters in name + name: Intern::new(s), + } + } + } + }); + + let token = choice((keyword, int, op, grouping, string)) + .or(any().map(Token::Error).validate(|t, span, emit| { + emit(ParseError::expected_input_found(span, None, Some(t))); + t + })) + .map_with_span(move |token, span| (token, span)) + .padded() + .recover_with(skip_then_retry_until([])); + + let comments = just("//") + .then_ignore( + just('(') + .ignore_then(take_until(just(")#")).ignored()) + .or(none_of('\n').ignored().repeated().ignored()), + ) + .padded() + .ignored() + .repeated(); + + token + .padded_by(comments) + .repeated() + .padded() + .then_ignore(end()) +} + +#[cfg(test)] +mod tests { + use chumsky::prelude::*; + use internment::Intern; + + use crate::{ + ast::{Span, SrcId}, + lexer, + token::Token, + }; + + #[test] + fn simple() { + let code = "pub type |> >=\n{ Thing _na_thing name"; + let len = code.chars().count(); + + let span = |i| Span::new(SrcId::empty(), i..i + 1); + + assert_eq!( + lexer::lexer() + .parse(chumsky::Stream::from_iter( + span(len), + code.chars().enumerate().map(|(i, c)| (c, span(i))), + )) + .map(|tokens| tokens.into_iter().map(|(tok, _)| tok).collect::>()), + Ok(vec![ + Token::Pub, + Token::Type, + Token::Pipe, + Token::GreaterEqual, + Token::LeftBrace, + Token::UpName { + name: Intern::new("Thing".to_string()) + }, + Token::DiscardName { + name: Intern::new("_na_thing".to_string()) + }, + Token::Name { + name: Intern::new("name".to_string()) + } + ]), + ); + } +} diff --git a/crates/lang/src/lib.rs b/crates/lang/src/lib.rs index 660c3de9..49da21d2 100644 --- a/crates/lang/src/lib.rs +++ b/crates/lang/src/lib.rs @@ -1,10 +1,8 @@ pub mod ast; - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} +pub mod build; +pub mod error; +pub mod expr; +pub mod lexer; +pub mod parser; +pub mod tipo; +pub mod token; diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs new file mode 100644 index 00000000..e2dcf2f6 --- /dev/null +++ b/crates/lang/src/parser.rs @@ -0,0 +1,7 @@ +use chumsky::prelude::*; + +use crate::{ast, error::ParseError, token::Token}; + +pub fn module_parser() -> impl Parser { + let imports = just(Token::Use).ignore_then(); +} diff --git a/crates/lang/src/tipo.rs b/crates/lang/src/tipo.rs new file mode 100644 index 00000000..85299bae --- /dev/null +++ b/crates/lang/src/tipo.rs @@ -0,0 +1,159 @@ +use std::{cell::RefCell, collections::HashMap, sync::Arc}; + +use crate::{ + ast::{Constant, FieldMap, Span, TypedConstant}, + build::Origin, +}; + +pub enum Type { + /// A nominal (named) type such as `Int`, `Float`, or a programmer defined + /// custom type such as `Person`. The type can take other types as + /// arguments (aka "generics" or "parametric polymorphism"). + /// + /// If the type is defined in the Gleam prelude the `module` field will be + /// empty, otherwise it will contain the name of the module that + /// defines the type. + /// + App { + public: bool, + module: Vec, + name: String, + args: Vec>, + }, + + /// The type of a function. It takes arguments and returns a value. + /// + Fn { + args: Vec>, + retrn: Arc, + }, + + /// A type variable. See the contained `TypeVar` enum for more information. + /// + Var { tipo: Arc> }, + + /// A tuple is an ordered collection of 0 or more values, each of which + /// can have a different type, so the `tuple` type is the sum of all the + /// contained types. + /// + Tuple { elems: Vec> }, +} + +pub enum TypeVar { + /// Unbound is an unbound variable. It is one specific type but we don't + /// know what yet in the inference process. It has a unique id which can be used to + /// identify if two unbound variable Rust values are the same Gleam type variable + /// instance or not. + /// + Unbound { id: u64 }, + /// Link is type variable where it was an unbound variable but we worked out + /// that it is some other type and now we point to that one. + /// + Link { tipo: Arc }, + /// A Generic variable stands in for any possible type and cannot be + /// specialised to any one type + /// + /// # Example + /// + /// ```gleam + /// type Cat(a) { + /// Cat(name: a) + /// } + /// // a is TypeVar::Generic + /// ``` + /// + Generic { id: u64 }, +} + +pub struct ValueConstructor { + pub public: bool, + pub variant: ValueConstructorVariant, + pub tipo: Arc, +} + +pub enum ValueConstructorVariant { + /// A locally defined variable or function parameter + LocalVariable { location: Span }, + + /// A module constant + ModuleConstant { + location: Span, + module: String, + literal: Constant, String>, + }, + + /// A function belonging to the module + ModuleFn { + name: String, + field_map: Option, + module: Vec, + arity: usize, + location: Span, + }, + + /// A constructor for a custom type + Record { + name: String, + arity: usize, + field_map: Option, + location: Span, + module: String, + }, +} + +pub struct Module { + pub name: Vec, + pub origin: Origin, + pub package: String, + pub types: HashMap, + pub types_constructors: HashMap>, + pub values: HashMap, + pub accessors: HashMap, +} + +pub struct TypeConstructor { + pub public: bool, + pub origin: Span, + pub module: Vec, + pub parameters: Vec>, + pub typ: Arc, +} + +pub struct AccessorsMap { + pub public: bool, + pub tipo: Arc, + pub accessors: HashMap, +} + +pub struct RecordAccessor { + // TODO: smaller int. Doesn't need to be this big + pub index: u64, + pub label: String, + pub tipo: Arc, +} + +pub enum PatternConstructor { + Record { + name: String, + field_map: Option, + }, +} + +pub enum ModuleValueConstructor { + Record { + name: String, + arity: usize, + type_: Arc, + field_map: Option, + location: Span, + }, + + Fn { + location: Span, + }, + + Constant { + literal: TypedConstant, + location: Span, + }, +} diff --git a/crates/lang/src/token.rs b/crates/lang/src/token.rs new file mode 100644 index 00000000..3b2d947b --- /dev/null +++ b/crates/lang/src/token.rs @@ -0,0 +1,149 @@ +use std::fmt; + +use internment::Intern; + +#[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)] +pub enum Token { + Error(char), + Name { name: Intern }, + UpName { name: Intern }, + DiscardName { name: Intern }, + Int { value: Intern }, + String { value: Intern }, + // Groupings + LeftParen, // ( + RightParen, // ) + LeftSquare, // [ + RightSquare, // } + LeftBrace, // { + RightBrace, // } + // Int Operators + Plus, + Minus, + Star, + Slash, + Less, + Greater, + LessEqual, + GreaterEqual, + Percent, + // ByteString Operators + PlusDot, // '+.' + MinusDot, // '-.' + StarDot, // '*.' + SlashDot, // '/.' + LessDot, // '<.' + GreaterDot, // '>.' + LessEqualDot, // '<=.' + GreaterEqualDot, // '>=.' + // Other Punctuation + Colon, + Comma, + Hash, // '#' + Bang, // '!' + Equal, + EqualEqual, // '==' + NotEqual, // '!=' + Vbar, // '|' + VbarVbar, // '||' + AmperAmper, // '&&' + Pipe, // '|>' + Dot, // '.' + RArrow, // '->' + DotDot, // '..' + EndOfFile, + // Extra + CommentNormal, + CommentDoc, + CommentModule, + EmptyLine, + // Keywords (alphabetically): + As, + Assert, + Const, + Fn, + If, + Is, + Let, + Opaque, + Pub, + Use, + Todo, + Try, + Type, + When, +} + +impl fmt::Display for Token { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + Token::Error(c) => { + write!(f, "\"{}\"", c)?; + + return Ok(()); + } + Token::Name { name } => &**name, + Token::UpName { name } => &**name, + Token::DiscardName { name } => &**name, + Token::Int { value } => &**value, + Token::String { value } => &**value, + Token::LeftParen => "(", + Token::RightParen => ")", + Token::LeftSquare => "[", + Token::RightSquare => "]", + Token::LeftBrace => "{", + Token::RightBrace => "}", + Token::Plus => "+", + Token::Minus => "-", + Token::Star => "*", + Token::Slash => "/", + Token::Less => "<", + Token::Greater => ">", + Token::LessEqual => "<=", + Token::GreaterEqual => ">=", + Token::Percent => "%", + Token::PlusDot => "+.", + Token::MinusDot => "-.", + Token::StarDot => "*.", + Token::SlashDot => "/.", + Token::LessDot => "<.", + Token::GreaterDot => ">.", + Token::LessEqualDot => "<=.", + Token::GreaterEqualDot => ">=.", + Token::Colon => ":", + Token::Comma => ",", + Token::Hash => "#", + Token::Bang => "!", + Token::Equal => "=", + Token::EqualEqual => "==", + Token::NotEqual => "!=", + Token::Vbar => "|", + Token::VbarVbar => "||", + Token::AmperAmper => "&&", + Token::Pipe => "|>", + Token::Dot => ".", + Token::RArrow => "->", + Token::DotDot => "..", + Token::EndOfFile => "EOF", + Token::CommentNormal => "//", + Token::CommentDoc => "///", + Token::CommentModule => "////", + Token::EmptyLine => "EMPTYLINE", + Token::As => "as", + Token::Assert => "assert", + Token::When => "when", + Token::Is => "is", + Token::Const => "const", + Token::Fn => "fn", + Token::If => "if", + Token::Use => "import", + Token::Let => "let", + Token::Opaque => "opaque", + Token::Pub => "pub", + Token::Todo => "todo", + Token::Try => "try", + Token::Type => "type", + }; + write!(f, "\"{}\"", s) + } +} From 1d1a6fc4044c49e748ad2af682a9a19433a7529b Mon Sep 17 00:00:00 2001 From: rvcas Date: Sat, 13 Aug 2022 01:13:18 -0400 Subject: [PATCH 08/18] feat: parse imports --- crates/lang/src/ast.rs | 24 ++++++- crates/lang/src/expr.rs | 1 + crates/lang/src/lexer.rs | 15 ++-- crates/lang/src/parser.rs | 145 +++++++++++++++++++++++++++++++++++++- crates/lang/src/tipo.rs | 4 ++ crates/lang/src/token.rs | 10 +-- 6 files changed, 186 insertions(+), 13 deletions(-) diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs index d4eae330..f33d21ec 100644 --- a/crates/lang/src/ast.rs +++ b/crates/lang/src/ast.rs @@ -10,23 +10,26 @@ use crate::{ pub type TypedModule = Module; pub type UntypedModule = Module<(), UntypedDefinition>; +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum ModuleKind { Contract, Lib, Script, } +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Module { pub name: Vec, pub docs: Vec, pub type_info: Info, - pub definitons: Vec, + pub definitions: Vec, pub kind: ModuleKind, } pub type TypedDefinition = Definition, TypedExpr, String, String>; pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>; +#[derive(Debug, Clone, PartialEq)] pub enum Definition { Fn { location: Span, @@ -61,6 +64,7 @@ pub enum Definition { }, Use { + location: Span, module: Vec, as_name: Option, unqualified: Vec, @@ -81,6 +85,7 @@ pub enum Definition { pub type TypedConstant = Constant, String>; pub type UntypedConstant = Constant<(), ()>; +#[derive(Debug, Clone, PartialEq)] pub enum Constant { Int { location: Span, @@ -127,17 +132,20 @@ pub enum Constant { }, } +#[derive(Debug, Clone, PartialEq, Eq)] pub struct CallArg { pub label: Option, pub location: Span, pub value: A, } +#[derive(Debug, Clone, PartialEq, Eq)] pub struct FieldMap { pub arity: usize, pub fields: HashMap, } +#[derive(Debug, Clone, PartialEq)] pub struct RecordConstructor { pub location: Span, pub name: String, @@ -145,6 +153,7 @@ pub struct RecordConstructor { pub documentation: Option, } +#[derive(Debug, Clone, PartialEq)] pub struct RecordConstructorArg { pub label: Option, // ast @@ -154,6 +163,7 @@ pub struct RecordConstructorArg { pub doc: Option, } +#[derive(Debug, Clone, PartialEq)] pub struct Arg { pub names: ArgName, pub location: Span, @@ -161,6 +171,7 @@ pub struct Arg { pub tipo: T, } +#[derive(Debug, Clone, PartialEq, Eq)] pub enum ArgName { Discard { name: String }, LabeledDiscard { label: String, name: String }, @@ -168,6 +179,7 @@ pub enum ArgName { NamedLabeled { name: String, label: String }, } +#[derive(Debug, Clone, PartialEq, Eq)] pub struct UnqualifiedImport { pub location: Span, pub name: String, @@ -176,6 +188,7 @@ pub struct UnqualifiedImport { } // TypeAst +#[derive(Debug, Clone, PartialEq)] pub enum Annotation { Constructor { location: Span, @@ -206,6 +219,7 @@ pub enum Annotation { }, } +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Layer { Value, Type, @@ -217,6 +231,7 @@ impl Default for Layer { } } +#[derive(Debug, Clone, PartialEq, Eq)] pub enum BinOp { // Boolean logic And, @@ -240,6 +255,7 @@ pub enum BinOp { ModInt, } +#[derive(Debug, Clone, PartialEq)] pub enum Pattern { Int { location: Span, @@ -309,6 +325,7 @@ pub enum Pattern { }, } +#[derive(Debug, Clone, PartialEq, Eq)] pub enum AssignmentKind { Let, Assert, @@ -323,6 +340,7 @@ pub type TypedClause = Clause, String>; pub type UntypedClause = Clause; +#[derive(Debug, Clone, PartialEq)] pub struct Clause { pub location: Span, pub pattern: MultiPattern, @@ -331,6 +349,7 @@ pub struct Clause { pub then: Expr, } +#[derive(Debug, Clone, PartialEq)] pub enum ClauseGuard { Equals { location: Span, @@ -403,17 +422,20 @@ pub struct TypedRecordUpdateArg { pub index: usize, } +#[derive(Debug, Clone, PartialEq)] pub struct UntypedRecordUpdateArg { pub label: String, // pub location: SrcSpan, pub value: UntypedExpr, } +#[derive(Debug, Clone, PartialEq)] pub struct RecordUpdateSpread { pub base: Box, pub location: Span, } +#[derive(Debug, Clone, PartialEq, Eq)] pub enum TodoKind { Keyword, EmptyFunction, diff --git a/crates/lang/src/expr.rs b/crates/lang/src/expr.rs index e3fd064e..a6a067f6 100644 --- a/crates/lang/src/expr.rs +++ b/crates/lang/src/expr.rs @@ -153,6 +153,7 @@ pub enum TypedExpr { }, } +#[derive(Debug, Clone, PartialEq)] pub enum UntypedExpr { Int { location: Span, diff --git a/crates/lang/src/lexer.rs b/crates/lang/src/lexer.rs index 958538ba..58d9ab0d 100644 --- a/crates/lang/src/lexer.rs +++ b/crates/lang/src/lexer.rs @@ -26,6 +26,7 @@ pub fn lexer() -> impl Parser, Error = ParseError> { just('/').to(Token::Slash), just('%').to(Token::Percent), just("|>").to(Token::Pipe), + just(',').to(Token::Comma), )); let grouping = choice(( @@ -75,7 +76,7 @@ pub fn lexer() -> impl Parser, Error = ParseError> { if s.chars().next().map_or(false, |c| c.is_uppercase()) { Token::UpName { // TODO: do not allow _ in upname - name: Intern::new(s), + name: s, } } else if s.starts_with('_') { Token::DiscardName { @@ -85,7 +86,7 @@ pub fn lexer() -> impl Parser, Error = ParseError> { } else { Token::Name { // TODO: do not allow uppercase letters in name - name: Intern::new(s), + name: s, } } } @@ -93,7 +94,11 @@ pub fn lexer() -> impl Parser, Error = ParseError> { let token = choice((keyword, int, op, grouping, string)) .or(any().map(Token::Error).validate(|t, span, emit| { - emit(ParseError::expected_input_found(span, None, Some(t))); + emit(ParseError::expected_input_found( + span, + None, + Some(t.clone()), + )); t })) .map_with_span(move |token, span| (token, span)) @@ -149,13 +154,13 @@ mod tests { Token::GreaterEqual, Token::LeftBrace, Token::UpName { - name: Intern::new("Thing".to_string()) + name: "Thing".to_string() }, Token::DiscardName { name: Intern::new("_na_thing".to_string()) }, Token::Name { - name: Intern::new("name".to_string()) + name: "name".to_string() } ]), ); diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index e2dcf2f6..c5473892 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -2,6 +2,147 @@ use chumsky::prelude::*; use crate::{ast, error::ParseError, token::Token}; -pub fn module_parser() -> impl Parser { - let imports = just(Token::Use).ignore_then(); +pub fn module_parser( + kind: ast::ModuleKind, +) -> impl Parser { + let unqualified_import = choice(( + select! {Token::Name { name } => name}.then( + just(Token::As) + .ignore_then(select! {Token::Name { name } => name}) + .or_not(), + ), + select! {Token::UpName { name } => name}.then( + just(Token::As) + .ignore_then(select! {Token::UpName { name } => name}) + .or_not(), + ), + )) + .map_with_span(|(name, as_name), span| ast::UnqualifiedImport { + name, + location: span, + as_name, + layer: Default::default(), + }); + + let unqualified_imports = just(Token::Dot) + .ignore_then( + unqualified_import + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftBrace), just(Token::RightBrace)), + ) + .or_not(); + + let as_name = just(Token::As) + .ignore_then(select! {Token::Name { name } => name}) + .or_not(); + + let module_path = select! {Token::Name { name } => name} + .separated_by(just(Token::Slash)) + .then(unqualified_imports) + .then(as_name); + + let import = just(Token::Use).ignore_then(module_path).map_with_span( + |((module, unqualified), as_name), span| ast::UntypedDefinition::Use { + module, + as_name, + unqualified: unqualified.unwrap_or_default(), + package: (), + location: span, + }, + ); + + choice((import,)) + .repeated() + .then_ignore(end()) + .map(move |definitions| ast::UntypedModule { + kind, + definitions, + docs: vec![], + name: vec![], + type_info: (), + }) +} + +#[cfg(test)] +mod tests { + use chumsky::prelude::*; + + use crate::{ + ast::{self, Span, SrcId}, + lexer, + parser::module_parser, + }; + + #[test] + fn simple() { + let code = r#" + use std/list + use std/address.{Address as A, thing as w} + use std/tx as t + "#; + let len = code.chars().count(); + + let span = |i| Span::new(SrcId::empty(), i..i + 1); + + let tokens = lexer::lexer() + .parse(chumsky::Stream::from_iter( + span(len), + code.chars().enumerate().map(|(i, c)| (c, span(i))), + )) + .unwrap(); + + dbg!(tokens.clone()); + + let res = module_parser(ast::ModuleKind::Script) + .parse(chumsky::Stream::from_iter(span(len), tokens.into_iter())) + .unwrap(); + + assert_eq!( + res, + ast::UntypedModule { + docs: vec![], + kind: ast::ModuleKind::Script, + name: vec![], + type_info: (), + definitions: vec![ + ast::UntypedDefinition::Use { + location: Span::new(SrcId::empty(), 13..25), + module: vec!["std".to_string(), "list".to_string()], + as_name: None, + unqualified: vec![], + package: (), + }, + ast::UntypedDefinition::Use { + location: Span::new(SrcId::empty(), 38..80), + module: vec!["std".to_string(), "address".to_string()], + as_name: None, + unqualified: vec![ + ast::UnqualifiedImport { + as_name: Some("A".to_string()), + location: Span::new(SrcId::empty(), 55..67), + layer: Default::default(), + name: "Address".to_string() + }, + ast::UnqualifiedImport { + as_name: Some("w".to_string()), + location: Span::new(SrcId::empty(), 69..79), + layer: Default::default(), + name: "thing".to_string() + } + ], + package: (), + }, + ast::UntypedDefinition::Use { + location: Span::new(SrcId::empty(), 93..108), + module: vec!["std".to_string(), "tx".to_string()], + as_name: Some("t".to_string()), + unqualified: vec![], + package: (), + } + ] + }, + "{:#?}", + res, + ); + } } diff --git a/crates/lang/src/tipo.rs b/crates/lang/src/tipo.rs index 85299bae..265c415c 100644 --- a/crates/lang/src/tipo.rs +++ b/crates/lang/src/tipo.rs @@ -5,6 +5,7 @@ use crate::{ build::Origin, }; +#[derive(Debug, Clone, PartialEq)] pub enum Type { /// A nominal (named) type such as `Int`, `Float`, or a programmer defined /// custom type such as `Person`. The type can take other types as @@ -39,6 +40,7 @@ pub enum Type { Tuple { elems: Vec> }, } +#[derive(Debug, Clone, PartialEq)] pub enum TypeVar { /// Unbound is an unbound variable. It is one specific type but we don't /// know what yet in the inference process. It has a unique id which can be used to @@ -65,12 +67,14 @@ pub enum TypeVar { Generic { id: u64 }, } +#[derive(Debug, Clone, PartialEq)] pub struct ValueConstructor { pub public: bool, pub variant: ValueConstructorVariant, pub tipo: Arc, } +#[derive(Debug, Clone, PartialEq)] pub enum ValueConstructorVariant { /// A locally defined variable or function parameter LocalVariable { location: Span }, diff --git a/crates/lang/src/token.rs b/crates/lang/src/token.rs index 3b2d947b..90b1f4ea 100644 --- a/crates/lang/src/token.rs +++ b/crates/lang/src/token.rs @@ -2,11 +2,11 @@ use std::fmt; use internment::Intern; -#[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)] +#[derive(Clone, Debug, PartialEq, Hash, Eq)] pub enum Token { Error(char), - Name { name: Intern }, - UpName { name: Intern }, + Name { name: String }, + UpName { name: String }, DiscardName { name: Intern }, Int { value: Intern }, String { value: Intern }, @@ -82,8 +82,8 @@ impl fmt::Display for Token { return Ok(()); } - Token::Name { name } => &**name, - Token::UpName { name } => &**name, + Token::Name { name } => name, + Token::UpName { name } => name, Token::DiscardName { name } => &**name, Token::Int { value } => &**value, Token::String { value } => &**value, From fbc9b27efe32e3070b0f9d51e16762d1b474d966 Mon Sep 17 00:00:00 2001 From: rvcas Date: Sat, 13 Aug 2022 18:36:43 -0400 Subject: [PATCH 09/18] feat: parse custom types --- crates/lang/src/ast.rs | 11 +- crates/lang/src/lexer.rs | 6 +- crates/lang/src/parser.rs | 300 ++++++++++++++++++++++++++++++++++++-- crates/lang/src/token.rs | 4 +- 4 files changed, 300 insertions(+), 21 deletions(-) diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs index f33d21ec..914478c8 100644 --- a/crates/lang/src/ast.rs +++ b/crates/lang/src/ast.rs @@ -32,10 +32,10 @@ pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>; #[derive(Debug, Clone, PartialEq)] pub enum Definition { Fn { - location: Span, arguments: Vec>>, body: Expr, doc: Option, + location: Span, name: String, public: bool, return_annotation: Option, @@ -43,19 +43,19 @@ pub enum Definition { }, TypeAlias { - location: Span, alias: String, annotation: Annotation, doc: Option, + location: Span, parameters: Vec, public: bool, tipo: T, }, DataType { - location: Span, constructors: Vec>, doc: Option, + location: Span, name: String, opaque: bool, parameters: Vec, @@ -64,11 +64,11 @@ pub enum Definition { }, Use { + as_name: Option, location: Span, module: Vec, - as_name: Option, - unqualified: Vec, package: PackageName, + unqualified: Vec, }, ModuleConstant { @@ -151,6 +151,7 @@ pub struct RecordConstructor { pub name: String, pub arguments: Vec>, pub documentation: Option, + pub sugar: bool, } #[derive(Debug, Clone, PartialEq)] diff --git a/crates/lang/src/lexer.rs b/crates/lang/src/lexer.rs index 58d9ab0d..a9f329f3 100644 --- a/crates/lang/src/lexer.rs +++ b/crates/lang/src/lexer.rs @@ -27,6 +27,7 @@ pub fn lexer() -> impl Parser, Error = ParseError> { just('%').to(Token::Percent), just("|>").to(Token::Pipe), just(',').to(Token::Comma), + just(':').to(Token::Colon), )); let grouping = choice(( @@ -81,7 +82,7 @@ pub fn lexer() -> impl Parser, Error = ParseError> { } else if s.starts_with('_') { Token::DiscardName { // TODO: do not allow uppercase letters in discard name - name: Intern::new(s), + name: s, } } else { Token::Name { @@ -125,7 +126,6 @@ pub fn lexer() -> impl Parser, Error = ParseError> { #[cfg(test)] mod tests { use chumsky::prelude::*; - use internment::Intern; use crate::{ ast::{Span, SrcId}, @@ -157,7 +157,7 @@ mod tests { name: "Thing".to_string() }, Token::DiscardName { - name: Intern::new("_na_thing".to_string()) + name: "_na_thing".to_string() }, Token::Name { name: "name".to_string() diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index c5473892..cf645e5e 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -5,6 +5,19 @@ use crate::{ast, error::ParseError, token::Token}; pub fn module_parser( kind: ast::ModuleKind, ) -> impl Parser { + choice((import_parser(), data_parser())) + .repeated() + .then_ignore(end()) + .map(move |definitions| ast::UntypedModule { + kind, + definitions, + docs: vec![], + name: vec![], + type_info: (), + }) +} + +pub fn import_parser() -> impl Parser { let unqualified_import = choice(( select! {Token::Name { name } => name}.then( just(Token::As) @@ -41,7 +54,7 @@ pub fn module_parser( .then(unqualified_imports) .then(as_name); - let import = just(Token::Use).ignore_then(module_path).map_with_span( + just(Token::Use).ignore_then(module_path).map_with_span( |((module, unqualified), as_name), span| ast::UntypedDefinition::Use { module, as_name, @@ -49,18 +62,168 @@ pub fn module_parser( package: (), location: span, }, - ); + ) +} - choice((import,)) - .repeated() - .then_ignore(end()) - .map(move |definitions| ast::UntypedModule { - kind, - definitions, - docs: vec![], - name: vec![], - type_info: (), +pub fn data_parser() -> impl Parser { + let unlabeled_constructor_type_args = type_parser() + .map_with_span(|annotation, span| ast::RecordConstructorArg { + label: None, + annotation, + tipo: (), + doc: None, + location: span, }) + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)); + + let constructors = select! {Token::UpName { name } => name} + .then( + choice(( + labeled_constructor_type_args(), + unlabeled_constructor_type_args, + )) + .or_not(), + ) + .map_with_span(|(name, arguments), span| ast::RecordConstructor { + location: span, + arguments: arguments.unwrap_or_default(), + name, + documentation: None, + sugar: false, + }) + .repeated() + .delimited_by(just(Token::LeftBrace), just(Token::RightBrace)); + + let record_sugar = labeled_constructor_type_args().map_with_span(|arguments, span| { + vec![ast::RecordConstructor { + location: span, + arguments, + documentation: None, + name: String::from("_replace"), + sugar: true, + }] + }); + + just(Token::Pub) + .ignored() + .then(just(Token::Opaque).ignored().or_not()) + .or_not() + .then( + just(Token::Type).ignore_then( + select! {Token::UpName { name } => name}.then( + select! {Token::Name { name } => name} + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .or_not(), + ), + ), + ) + .then(choice((constructors, record_sugar))) + .map_with_span(|((pub_opaque, (name, parameters)), constructors), span| { + ast::UntypedDefinition::DataType { + location: span, + constructors: constructors + .into_iter() + .map(|mut constructor| { + if constructor.sugar { + constructor.name = name.clone(); + } + + constructor + }) + .collect(), + doc: None, + name, + opaque: pub_opaque + .map(|(_, opt_opaque)| opt_opaque.is_some()) + .unwrap_or(false), + parameters: parameters.unwrap_or_default(), + public: pub_opaque.is_some(), + typed_parameters: vec![], + } + }) +} + +pub fn type_parser() -> impl Parser { + recursive(|r| { + choice(( + select! {Token::DiscardName { name } => name}.map_with_span(|name, span| { + ast::Annotation::Hole { + location: span, + name, + } + }), + just(Token::Fn) + .ignore_then( + r.clone() + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)), + ) + .then_ignore(just(Token::RArrow)) + .then(r.clone()) + .map_with_span(|(arguments, ret), span| ast::Annotation::Fn { + location: span, + arguments, + ret: Box::new(ret), + }), + select! {Token::UpName { name } => name} + .then( + r.clone() + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .or_not(), + ) + .map_with_span(|(name, arguments), span| ast::Annotation::Constructor { + location: span, + module: None, + name, + arguments: arguments.unwrap_or_default(), + }), + select! {Token::Name { name } => name} + .then( + just(Token::Dot) + .ignore_then(select! {Token::UpName {name} => name}) + .then( + r.separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .or_not(), + ) + .or_not(), + ) + .map_with_span(|(mod_name, opt_dot), span| { + if let Some((name, arguments)) = opt_dot { + ast::Annotation::Constructor { + location: span, + module: Some(mod_name), + name, + arguments: arguments.unwrap_or_default(), + } + } else { + ast::Annotation::Var { + location: span, + name: mod_name, + } + } + }), + )) + }) +} + +pub fn labeled_constructor_type_args( +) -> impl Parser>, Error = ParseError> { + select! {Token::Name {name} => name} + .then_ignore(just(Token::Colon)) + .then(type_parser()) + .map_with_span(|(name, annotation), span| ast::RecordConstructorArg { + label: Some(name), + annotation, + tipo: (), + doc: None, + location: span, + }) + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftBrace), just(Token::RightBrace)) } #[cfg(test)] @@ -79,6 +242,16 @@ mod tests { use std/list use std/address.{Address as A, thing as w} use std/tx as t + + type Option(a) { + Some(a, Int) + None + Wow { name: Int, age: Int } + } + + pub opaque type User { + name: _w + } "#; let len = code.chars().count(); @@ -138,6 +311,111 @@ mod tests { as_name: Some("t".to_string()), unqualified: vec![], package: (), + }, + ast::UntypedDefinition::DataType { + location: Span::new(SrcId::empty(), 122..246), + constructors: vec![ + ast::RecordConstructor { + location: Span::new(SrcId::empty(), 155..167), + name: "Some".to_string(), + arguments: vec![ + ast::RecordConstructorArg { + label: None, + annotation: ast::Annotation::Var { + location: Span::new(SrcId::empty(), 160..161), + name: "a".to_string(), + }, + location: Span::new(SrcId::empty(), 160..161), + tipo: (), + doc: None, + }, + ast::RecordConstructorArg { + label: None, + annotation: ast::Annotation::Constructor { + location: Span::new(SrcId::empty(), 163..166), + module: None, + name: "Int".to_string(), + arguments: vec![], + }, + location: Span::new(SrcId::empty(), 163..166), + tipo: (), + doc: None, + }, + ], + documentation: None, + sugar: false, + }, + ast::RecordConstructor { + location: Span::new(SrcId::empty(), 184..188), + name: "None".to_string(), + arguments: vec![], + documentation: None, + sugar: false, + }, + ast::RecordConstructor { + location: Span::new(SrcId::empty(), 205..232), + name: "Wow".to_string(), + arguments: vec![ + ast::RecordConstructorArg { + label: Some("name".to_string(),), + annotation: ast::Annotation::Constructor { + location: Span::new(SrcId::empty(), 217..220), + module: None, + name: "Int".to_string(), + arguments: vec![], + }, + location: Span::new(SrcId::empty(), 211..220), + tipo: (), + doc: None, + }, + ast::RecordConstructorArg { + label: Some("age".to_string(),), + annotation: ast::Annotation::Constructor { + location: Span::new(SrcId::empty(), 227..230), + module: None, + name: "Int".to_string(), + arguments: vec![], + }, + location: Span::new(SrcId::empty(), 222..230), + tipo: (), + doc: None, + }, + ], + documentation: None, + sugar: false, + }, + ], + doc: None, + name: "Option".to_string(), + opaque: false, + parameters: vec!["a".to_string(),], + public: false, + typed_parameters: vec![], + }, + ast::UntypedDefinition::DataType { + location: Span::new(SrcId::empty(), 260..321), + constructors: vec![ast::RecordConstructor { + location: Span::new(SrcId::empty(), 281..321), + name: "User".to_string(), + arguments: vec![ast::RecordConstructorArg { + label: Some("name".to_string(),), + annotation: ast::Annotation::Hole { + location: Span::new(SrcId::empty(), 305..307), + name: "_w".to_string(), + }, + location: Span::new(SrcId::empty(), 299..307), + tipo: (), + doc: None, + },], + documentation: None, + sugar: true, + },], + doc: None, + name: "User".to_string(), + opaque: true, + parameters: vec![], + public: true, + typed_parameters: vec![], } ] }, diff --git a/crates/lang/src/token.rs b/crates/lang/src/token.rs index 90b1f4ea..864f77a1 100644 --- a/crates/lang/src/token.rs +++ b/crates/lang/src/token.rs @@ -7,7 +7,7 @@ pub enum Token { Error(char), Name { name: String }, UpName { name: String }, - DiscardName { name: Intern }, + DiscardName { name: String }, Int { value: Intern }, String { value: Intern }, // Groupings @@ -84,7 +84,7 @@ impl fmt::Display for Token { } Token::Name { name } => name, Token::UpName { name } => name, - Token::DiscardName { name } => &**name, + Token::DiscardName { name } => name, Token::Int { value } => &**value, Token::String { value } => &**value, Token::LeftParen => "(", From d87bb17a27c918421f881afab4fad5a001fd2083 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 15 Aug 2022 15:02:03 -0400 Subject: [PATCH 10/18] feat: type aliases and some fn parsing --- crates/lang/src/ast.rs | 26 ++++-- crates/lang/src/parser.rs | 188 ++++++++++++++++++++++++++++++++------ 2 files changed, 182 insertions(+), 32 deletions(-) diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs index 914478c8..75ea3398 100644 --- a/crates/lang/src/ast.rs +++ b/crates/lang/src/ast.rs @@ -32,7 +32,7 @@ pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>; #[derive(Debug, Clone, PartialEq)] pub enum Definition { Fn { - arguments: Vec>>, + arguments: Vec>, body: Expr, doc: Option, location: Span, @@ -164,9 +164,11 @@ pub struct RecordConstructorArg { pub doc: Option, } +pub type UntypedArg = Arg<()>; + #[derive(Debug, Clone, PartialEq)] pub struct Arg { - pub names: ArgName, + pub arg_name: ArgName, pub location: Span, pub annotation: Option, pub tipo: T, @@ -174,10 +176,22 @@ pub struct Arg { #[derive(Debug, Clone, PartialEq, Eq)] pub enum ArgName { - Discard { name: String }, - LabeledDiscard { label: String, name: String }, - Named { name: String }, - NamedLabeled { name: String, label: String }, + Discard { + name: String, + location: Span, + }, + LabeledDiscard { + label: String, + name: String, + location: Span, + }, + Named { + name: String, + }, + NamedLabeled { + name: String, + label: String, + }, } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index cf645e5e..a994c8fe 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -1,20 +1,25 @@ use chumsky::prelude::*; -use crate::{ast, error::ParseError, token::Token}; +use crate::{ast, error::ParseError, expr, token::Token}; pub fn module_parser( kind: ast::ModuleKind, ) -> impl Parser { - choice((import_parser(), data_parser())) - .repeated() - .then_ignore(end()) - .map(move |definitions| ast::UntypedModule { - kind, - definitions, - docs: vec![], - name: vec![], - type_info: (), - }) + choice(( + import_parser(), + data_parser(), + type_alias_parser(), + fn_parser(), + )) + .repeated() + .then_ignore(end()) + .map(move |definitions| ast::UntypedModule { + kind, + definitions, + docs: vec![], + name: vec![], + type_info: (), + }) } pub fn import_parser() -> impl Parser { @@ -105,20 +110,10 @@ pub fn data_parser() -> impl Parser name}.then( - select! {Token::Name { name } => name} - .separated_by(just(Token::Comma)) - .delimited_by(just(Token::LeftParen), just(Token::RightParen)) - .or_not(), - ), - ), - ) + .then(type_name_with_args()) .then(choice((constructors, record_sugar))) .map_with_span(|((pub_opaque, (name, parameters)), constructors), span| { ast::UntypedDefinition::DataType { @@ -145,6 +140,82 @@ pub fn data_parser() -> impl Parser impl Parser { + pub_parser() + .or_not() + .then(type_name_with_args()) + .then_ignore(just(Token::Equal)) + .then(type_parser()) + .map_with_span(|((opt_pub, (alias, parameters)), annotation), span| { + ast::UntypedDefinition::TypeAlias { + alias, + annotation, + doc: None, + location: span, + parameters: parameters.unwrap_or_default(), + public: opt_pub.is_some(), + tipo: (), + } + }) +} + +pub fn fn_parser() -> impl Parser { + pub_parser() + .or_not() + .then_ignore(just(Token::Fn)) + .then(select! {Token::Name {name} => name}) + .then( + fn_param_parser() + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)), + ) + .then(just(Token::RArrow).ignore_then(type_parser()).or_not()) + .then_ignore(just(Token::LeftBrace)) + .then(expr_seq_parser()) + .then_ignore(just(Token::RightBrace)) + .map_with_span( + |((((opt_pub, name), arguments), return_annotation), body), span| { + ast::UntypedDefinition::Fn { + arguments, + body, + doc: None, + location: span, + name, + public: opt_pub.is_some(), + return_annotation, + return_type: (), + } + }, + ) +} + +pub fn fn_param_parser() -> impl Parser { + choice(( + select! {Token::Name {name} => name} + .then(select! {Token::DiscardName {name} => name}) + .map_with_span(|(label, name), span| ast::ArgName::LabeledDiscard { + label, + name, + location: span, + }), + select! {Token::DiscardName {name} => name}.map_with_span(|name, span| { + ast::ArgName::Discard { + name, + location: span, + } + }), + )) + .then(just(Token::Colon).ignore_then(type_parser()).or_not()) + .map_with_span(|(arg_name, annotation), span| ast::Arg { + location: span, + annotation, + tipo: (), + arg_name, + }) +} + +pub fn expr_seq_parser() -> impl Parser {} + pub fn type_parser() -> impl Parser { recursive(|r| { choice(( @@ -226,6 +297,22 @@ pub fn labeled_constructor_type_args( .delimited_by(just(Token::LeftBrace), just(Token::RightBrace)) } +pub fn type_name_with_args() -> impl Parser>), Error = ParseError> +{ + just(Token::Type).ignore_then( + select! {Token::UpName { name } => name}.then( + select! {Token::Name { name } => name} + .separated_by(just(Token::Comma)) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .or_not(), + ), + ) +} + +pub fn pub_parser() -> impl Parser { + just(Token::Pub).ignored() +} + #[cfg(test)] mod tests { use chumsky::prelude::*; @@ -252,6 +339,19 @@ mod tests { pub opaque type User { name: _w } + + type Thing = Option(Int) + + pub type Me = Option(String) + + pub fn add_one(a) { + a + 1 + } + + pub fn add_one(a: Int) -> Int { + [1, 2, 3] + |> list.map(fn(x) { x + a }) + } "#; let len = code.chars().count(); @@ -264,8 +364,6 @@ mod tests { )) .unwrap(); - dbg!(tokens.clone()); - let res = module_parser(ast::ModuleKind::Script) .parse(chumsky::Stream::from_iter(span(len), tokens.into_iter())) .unwrap(); @@ -416,7 +514,45 @@ mod tests { parameters: vec![], public: true, typed_parameters: vec![], - } + }, + ast::UntypedDefinition::TypeAlias { + alias: "Thing".to_string(), + annotation: ast::Annotation::Constructor { + location: Span::new(SrcId::empty(), 348..359), + module: None, + name: "Option".to_string(), + arguments: vec![ast::Annotation::Constructor { + location: Span::new(SrcId::empty(), 355..358), + module: None, + name: "Int".to_string(), + arguments: vec![], + },], + }, + doc: None, + location: Span::new(SrcId::empty(), 335..359), + parameters: vec![], + public: false, + tipo: (), + }, + ast::UntypedDefinition::TypeAlias { + alias: "Me".to_string(), + annotation: ast::Annotation::Constructor { + location: Span::new(SrcId::empty(), 387..401), + module: None, + name: "Option".to_string(), + arguments: vec![ast::Annotation::Constructor { + location: Span::new(SrcId::empty(), 394..400), + module: None, + name: "String".to_string(), + arguments: vec![], + },], + }, + doc: None, + location: Span::new(SrcId::empty(), 373..401), + parameters: vec![], + public: true, + tipo: (), + }, ] }, "{:#?}", From 3bc507c9e844e507aa7e5cb497125637873d4247 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 17 Aug 2022 21:54:24 -0400 Subject: [PATCH 11/18] feat: beginnings of expr parsing --- crates/lang/src/ast.rs | 5 ++ crates/lang/src/lexer.rs | 6 +- crates/lang/src/parser.rs | 145 +++++++++++++++++++++++++++++++++++++- crates/lang/src/token.rs | 10 ++- 4 files changed, 154 insertions(+), 12 deletions(-) diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs index 75ea3398..4264994c 100644 --- a/crates/lang/src/ast.rs +++ b/crates/lang/src/ast.rs @@ -187,10 +187,12 @@ pub enum ArgName { }, Named { name: String, + location: Span, }, NamedLabeled { name: String, label: String, + location: Span, }, } @@ -270,6 +272,9 @@ pub enum BinOp { ModInt, } +pub type UntypedPattern = Pattern<(), ()>; +pub type TypedPattern = Pattern>; + #[derive(Debug, Clone, PartialEq)] pub enum Pattern { Int { diff --git a/crates/lang/src/lexer.rs b/crates/lang/src/lexer.rs index a9f329f3..504d66af 100644 --- a/crates/lang/src/lexer.rs +++ b/crates/lang/src/lexer.rs @@ -1,12 +1,9 @@ use chumsky::prelude::*; -use internment::Intern; use crate::{ast::Span, error::ParseError, token::Token}; pub fn lexer() -> impl Parser, Error = ParseError> { - let int = text::int(10) - .map(Intern::new) - .map(|value| Token::Int { value }); + let int = text::int(10).map(|value| Token::Int { value }); let op = choice(( just("==").to(Token::EqualEqual), @@ -54,7 +51,6 @@ pub fn lexer() -> impl Parser, Error = ParseError> { .ignore_then(filter(|c| *c != '\\' && *c != '"').or(escape).repeated()) .then_ignore(just('"')) .collect::() - .map(Intern::new) .map(|value| Token::String { value }) .labelled("string"); diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index a994c8fe..0c976740 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -204,6 +204,17 @@ pub fn fn_param_parser() -> impl Parser name} + .then(select! {Token::Name {name} => name}) + .map_with_span(|(label, name), span| ast::ArgName::NamedLabeled { + label, + name, + location: span, + }), + select! {Token::Name {name} => name}.map_with_span(|name, span| ast::ArgName::Named { + name, + location: span, + }), )) .then(just(Token::Colon).ignore_then(type_parser()).or_not()) .map_with_span(|(arg_name, annotation), span| ast::Arg { @@ -214,7 +225,27 @@ pub fn fn_param_parser() -> impl Parser impl Parser {} +pub fn expr_seq_parser() -> impl Parser { + recursive(|r| { + choice((just(Token::Try) + .ignore_then(pattern_parser()) + .then(just(Token::Colon).ignore_then(type_parser()).or_not()) + .then_ignore(just(Token::Equal)) + .then(expr_parser()) + .then(r) + .map_with_span(|(((pattern, annotation), value), then_), span| { + expr::UntypedExpr::Try { + location: span, + value: Box::new(value), + pattern, + then: Box::new(then_), + annotation, + } + }),)) + }) +} + +pub fn expr_parser() -> impl Parser {} pub fn type_parser() -> impl Parser { recursive(|r| { @@ -313,6 +344,118 @@ pub fn pub_parser() -> impl Parser { just(Token::Pub).ignored() } +pub fn pattern_parser() -> impl Parser { + recursive(|r| { + let constructor_pattern_arg_parser = choice(( + select! {Token::Name {name} => name} + .then_ignore(just(Token::Colon)) + .then(r.clone()) + .map_with_span(|(name, pattern), span| ast::CallArg { + location: span, + label: Some(name), + value: pattern, + }), + r.map_with_span(|pattern, span| ast::CallArg { + location: span, + value: pattern, + label: None, + }), + )); + + let constructor_pattern_args_parser = constructor_pattern_arg_parser + .separated_by(just(Token::Comma)) + .allow_trailing() + .then( + just(Token::DotDot) + .then_ignore(just(Token::Comma).or_not()) + .ignored() + .or_not(), + ) + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .or_not() + .map(|opt_args| { + opt_args + .map(|(a, b)| (a, b.is_some())) + .unwrap_or_else(|| (vec![], false)) + }); + + let constructor_pattern_parser = + select! {Token::UpName { name } => name}.then(constructor_pattern_args_parser); + + choice(( + select! { Token::Name {name} => name } + .then( + just(Token::Dot) + .ignore_then(constructor_pattern_parser.clone()) + .or_not(), + ) + .map_with_span(|(name, opt_pattern), span| { + if let Some((c_name, (arguments, with_spread))) = opt_pattern { + ast::UntypedPattern::Constructor { + location: span, + name: c_name, + arguments, + module: Some(name), + constructor: (), + with_spread, + tipo: (), + } + } else { + ast::UntypedPattern::Var { + location: span, + name, + } + } + }), + constructor_pattern_parser.map_with_span(|(name, (arguments, with_spread)), span| { + ast::UntypedPattern::Constructor { + location: span, + name, + arguments, + module: None, + constructor: (), + with_spread, + tipo: (), + } + }), + select! {Token::DiscardName {name} => name}.map_with_span(|name, span| { + ast::UntypedPattern::Discard { + name, + location: span, + } + }), + select! {Token::String {value} => value}.map_with_span(|value, span| { + ast::UntypedPattern::String { + location: span, + value, + } + }), + select! {Token::Int {value} => value}.map_with_span(|value, span| { + ast::UntypedPattern::Int { + location: span, + value, + } + }), + )) + .then( + just(Token::As) + .ignore_then(select! { Token::Name {name} => name}) + .or_not(), + ) + .map_with_span(|(pattern, opt_as), span| { + if let Some(name) = opt_as { + ast::UntypedPattern::Assign { + name, + location: span, + pattern: Box::new(pattern), + } + } else { + pattern + } + }) + }) +} + #[cfg(test)] mod tests { use chumsky::prelude::*; diff --git a/crates/lang/src/token.rs b/crates/lang/src/token.rs index 864f77a1..cf6856e0 100644 --- a/crates/lang/src/token.rs +++ b/crates/lang/src/token.rs @@ -1,15 +1,13 @@ use std::fmt; -use internment::Intern; - #[derive(Clone, Debug, PartialEq, Hash, Eq)] pub enum Token { Error(char), Name { name: String }, UpName { name: String }, DiscardName { name: String }, - Int { value: Intern }, - String { value: Intern }, + Int { value: String }, + String { value: String }, // Groupings LeftParen, // ( RightParen, // ) @@ -85,8 +83,8 @@ impl fmt::Display for Token { Token::Name { name } => name, Token::UpName { name } => name, Token::DiscardName { name } => name, - Token::Int { value } => &**value, - Token::String { value } => &**value, + Token::Int { value } => value, + Token::String { value } => value, Token::LeftParen => "(", Token::RightParen => ")", Token::LeftSquare => "[", From 59a9bac9b5d8a8d3759dda19f4cabba9c573bcc3 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 17 Aug 2022 22:34:26 -0400 Subject: [PATCH 12/18] feat: finish expr_seq_parser --- crates/lang/src/expr.rs | 54 +++++++++++++++++++++++++++++++++++++++ crates/lang/src/parser.rs | 41 ++++++++++++++++++----------- 2 files changed, 80 insertions(+), 15 deletions(-) diff --git a/crates/lang/src/expr.rs b/crates/lang/src/expr.rs index a6a067f6..2cd2247b 100644 --- a/crates/lang/src/expr.rs +++ b/crates/lang/src/expr.rs @@ -268,3 +268,57 @@ pub enum UntypedExpr { value: Box, }, } + +impl UntypedExpr { + pub fn append_in_sequence(self, next: Self) -> Self { + let location = Span { + start: self.location().start, + end: next.location().end, + ..self.location() + }; + + match self { + Self::Sequence { + mut expressions, .. + } => { + expressions.push(next); + Self::Sequence { + location, + expressions, + } + } + _ => Self::Sequence { + location, + expressions: vec![self, next], + }, + } + } + + pub fn location(&self) -> Span { + match self { + Self::Try { then, .. } => then.location(), + Self::PipeLine { expressions, .. } => expressions.last().location(), + Self::Fn { location, .. } + | Self::Var { location, .. } + | Self::Int { location, .. } + | Self::Todo { location, .. } + | Self::Case { location, .. } + | Self::Call { location, .. } + | Self::List { location, .. } + | Self::Float { location, .. } + | Self::BinOp { location, .. } + | Self::Tuple { location, .. } + | Self::String { location, .. } + | Self::Assignment { location, .. } + | Self::TupleIndex { location, .. } + | Self::FieldAccess { location, .. } + | Self::RecordUpdate { location, .. } + | Self::Negate { location, .. } => *location, + Self::Sequence { + location, + expressions, + .. + } => expressions.last().map(Self::location).unwrap_or(*location), + } + } +} diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index 0c976740..448ec3b2 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -227,26 +227,37 @@ pub fn fn_param_parser() -> impl Parser impl Parser { recursive(|r| { - choice((just(Token::Try) - .ignore_then(pattern_parser()) - .then(just(Token::Colon).ignore_then(type_parser()).or_not()) - .then_ignore(just(Token::Equal)) - .then(expr_parser()) - .then(r) - .map_with_span(|(((pattern, annotation), value), then_), span| { - expr::UntypedExpr::Try { - location: span, - value: Box::new(value), - pattern, - then: Box::new(then_), - annotation, - } - }),)) + choice(( + just(Token::Try) + .ignore_then(pattern_parser()) + .then(just(Token::Colon).ignore_then(type_parser()).or_not()) + .then_ignore(just(Token::Equal)) + .then(expr_parser()) + .then(r.clone()) + .map_with_span(|(((pattern, annotation), value), then_), span| { + expr::UntypedExpr::Try { + location: span, + value: Box::new(value), + pattern, + then: Box::new(then_), + annotation, + } + }), + expr_parser() + .then(r.repeated()) + .map_with_span(|(expr, exprs), span| { + exprs + .into_iter() + .fold(expr, |acc, elem| acc.append_in_sequence(elem)) + }), + )) }) } pub fn expr_parser() -> impl Parser {} +pub fn expr_unit_parser() -> impl Parser {} + pub fn type_parser() -> impl Parser { recursive(|r| { choice(( From ce72d8cca83bd4f4a46c124b8d6a886fa6b17f24 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 17 Aug 2022 22:47:02 -0400 Subject: [PATCH 13/18] chore: fix lock file --- Cargo.lock | 66 ++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd4f828a..f577f37f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,12 +25,17 @@ dependencies = [ [[package]] name = "aiken" <<<<<<< HEAD +<<<<<<< HEAD version = "0.0.11" ======= +======= +>>>>>>> 188e619 (chore: fix lock file) <<<<<<< HEAD version = "0.0.10" ======= <<<<<<< HEAD +======= +>>>>>>> 360364e (chore: fix lock file) version = "0.0.8" >>>>>>> c50961c (feat: add deps) >>>>>>> 508f3c6 (feat: add deps) @@ -39,18 +44,6 @@ dependencies = [ "clap", "uplc", ] -======= -version = "0.0.7" -<<<<<<< HEAD -dependencies = ["anyhow", "clap", "uplc"] ->>>>>>> 27331bc (feat: add deps) -======= -dependencies = [ - "anyhow", - "clap", - "uplc", -] ->>>>>>> 1ba348e (chore: update lock file) [[package]] name = "aiken-lang" @@ -64,9 +57,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.60" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" +checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" [[package]] name = "arrayvec" @@ -99,9 +92,9 @@ checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" [[package]] name = "bech32" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5738be7561b0eeb501ef1d5c5db3f24e01ceb55fededd9b00039aada34966ad" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" [[package]] name = "bit-set" @@ -147,9 +140,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.16" +version = "3.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3dbbb6653e7c55cc8595ad3e1f7be8f32aba4eb7ff7f0fd1163d4f3d137c0a9" +checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" dependencies = [ "atty", "bitflags", @@ -164,9 +157,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.15" +version = "3.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" +checksum = "13547f7012c01ab4a0e8f8967730ada8f9fdf419e8b6c792788f39cf4e46eefa" dependencies = [ "heck", "proc-macro-error", @@ -344,9 +337,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.127" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "lock_api" @@ -369,9 +362,9 @@ dependencies = [ [[package]] name = "miette" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2c9d50e919ffdc4d2d83b83972a13e8ba86ba8245a205bee9e314d593c15a8" +checksum = "a28d6092d7e94a90bb9ea8e6c26c99d5d112d49dda2afdb4f7ea8cf09e1a5a6d" dependencies = [ "miette-derive", "once_cell", @@ -381,9 +374,9 @@ dependencies = [ [[package]] name = "miette-derive" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c8d10c73bcc9f0ab5c918521dab23d178062a56e6b328eb37106d497280bd94" +checksum = "4f2485ed7d1fe80704928e3eb86387439609bd0c6bb96db8208daa364cfd1e09" dependencies = [ "proc-macro2", "quote", @@ -442,15 +435,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "pallas-codec" @@ -727,9 +720,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.142" +version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2" +checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" [[package]] name = "serde_json" @@ -843,6 +836,7 @@ checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] <<<<<<< HEAD +<<<<<<< HEAD name = "uplc" <<<<<<< HEAD version = "0.0.11" @@ -852,6 +846,8 @@ version = "0.0.10" ======= version = "0.0.8" ======= +======= +>>>>>>> 360364e (chore: fix lock file) name = "unicode-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -859,6 +855,7 @@ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] <<<<<<< HEAD +<<<<<<< HEAD >>>>>>> 27331bc (feat: add deps) <<<<<<< HEAD >>>>>>> c50961c (feat: add deps) @@ -870,9 +867,10 @@ dependencies = [ ======= >>>>>>> 2f7eda3 (chore: update lock file) ======= +======= +>>>>>>> 360364e (chore: fix lock file) name = "uplc" -version = "0.0.7" ->>>>>>> 1ba348e (chore: update lock file) +version = "0.0.8" dependencies = [ "cryptoxide", "flat-rs", From c92ed49c9ca8c0be8b603053d74335da04174bfc Mon Sep 17 00:00:00 2001 From: rvcas Date: Tue, 30 Aug 2022 18:24:07 -0400 Subject: [PATCH 14/18] chore: lock file again --- Cargo.lock | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f577f37f..dfdec353 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,7 @@ dependencies = [ name = "aiken" <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD version = "0.0.11" ======= ======= @@ -39,6 +40,9 @@ version = "0.0.10" version = "0.0.8" >>>>>>> c50961c (feat: add deps) >>>>>>> 508f3c6 (feat: add deps) +======= +version = "0.0.10" +>>>>>>> 75036f5 (chore: lock file again) dependencies = [ "anyhow", "clap", @@ -140,9 +144,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.17" +version = "3.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" +checksum = "68d43934757334b5c0519ff882e1ab9647ac0258b47c24c4f490d78e42697fd5" dependencies = [ "atty", "bitflags", @@ -157,9 +161,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.17" +version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13547f7012c01ab4a0e8f8967730ada8f9fdf419e8b6c792788f39cf4e46eefa" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" dependencies = [ "heck", "proc-macro-error", @@ -222,24 +226,12 @@ dependencies = [ [[package]] name = "flat-rs" -<<<<<<< HEAD version = "0.0.10" dependencies = [ "anyhow", "proptest", "thiserror", ] -======= -version = "0.0.7" -<<<<<<< HEAD -dependencies = ["anyhow", "thiserror"] ->>>>>>> c50961c (feat: add deps) -======= -dependencies = [ - "anyhow", - "thiserror", -] ->>>>>>> 2f7eda3 (chore: update lock file) [[package]] name = "fnv" @@ -343,9 +335,9 @@ checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" dependencies = [ "autocfg", "scopeguard", @@ -720,15 +712,15 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.143" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -837,6 +829,7 @@ checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD name = "uplc" <<<<<<< HEAD version = "0.0.11" @@ -848,6 +841,8 @@ version = "0.0.8" ======= ======= >>>>>>> 360364e (chore: fix lock file) +======= +>>>>>>> 75036f5 (chore: lock file again) name = "unicode-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -856,6 +851,7 @@ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD >>>>>>> 27331bc (feat: add deps) <<<<<<< HEAD >>>>>>> c50961c (feat: add deps) @@ -869,8 +865,10 @@ dependencies = [ ======= ======= >>>>>>> 360364e (chore: fix lock file) +======= +>>>>>>> 75036f5 (chore: lock file again) name = "uplc" -version = "0.0.8" +version = "0.0.10" dependencies = [ "cryptoxide", "flat-rs", From d54aaff5de6111a5bc76672a00c7c25704e75bb2 Mon Sep 17 00:00:00 2001 From: rvcas Date: Thu, 1 Sep 2022 18:51:21 -0400 Subject: [PATCH 15/18] feat: fill in expr unit parser a bit --- crates/lang/src/parser.rs | 43 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index 448ec3b2..f320ffc5 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -1,6 +1,11 @@ use chumsky::prelude::*; -use crate::{ast, error::ParseError, expr, token::Token}; +use crate::{ + ast::{self, TodoKind}, + error::ParseError, + expr, + token::Token, +}; pub fn module_parser( kind: ast::ModuleKind, @@ -256,7 +261,41 @@ pub fn expr_seq_parser() -> impl Parser impl Parser {} -pub fn expr_unit_parser() -> impl Parser {} +pub fn expr_unit_parser() -> impl Parser { + choice(( + select! {Token::String {value} => value}.map_with_span(|value, span| { + expr::UntypedExpr::String { + location: span, + value, + } + }), + select! { Token::Int {value} => value}.map_with_span(|value, span| { + expr::UntypedExpr::Int { + location: span, + value, + } + }), + select! { + Token::Name { name } => name, + Token::UpName { name } => name, + } + .map_with_span(|name, span| expr::UntypedExpr::Var { + location: span, + name, + }), + just(Token::Todo) + .ignore_then( + select! {Token::String {value} => value} + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .or_not(), + ) + .map_with_span(|label, span| expr::UntypedExpr::Todo { + kind: TodoKind::Keyword, + location: span, + label, + }), + )) +} pub fn type_parser() -> impl Parser { recursive(|r| { From 9751b1827f6fdfeea930c04d5dc8c0caeea698e3 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 7 Sep 2022 17:53:52 -0400 Subject: [PATCH 16/18] chore --- Cargo.lock | 74 ++++++++---------------------------------------------- 1 file changed, 11 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dfdec353..e361b432 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,25 +24,7 @@ dependencies = [ [[package]] name = "aiken" -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD version = "0.0.11" -======= -======= ->>>>>>> 188e619 (chore: fix lock file) -<<<<<<< HEAD -version = "0.0.10" -======= -<<<<<<< HEAD -======= ->>>>>>> 360364e (chore: fix lock file) -version = "0.0.8" ->>>>>>> c50961c (feat: add deps) ->>>>>>> 508f3c6 (feat: add deps) -======= -version = "0.0.10" ->>>>>>> 75036f5 (chore: lock file again) dependencies = [ "anyhow", "clap", @@ -61,9 +43,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.62" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" +checksum = "b9a8f622bcf6ff3df478e9deba3e03e4e04b300f8e6a139e192c05fa3490afc7" [[package]] name = "arrayvec" @@ -144,9 +126,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.19" +version = "3.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68d43934757334b5c0519ff882e1ab9647ac0258b47c24c4f490d78e42697fd5" +checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" dependencies = [ "atty", "bitflags", @@ -427,9 +409,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" [[package]] name = "os_str_bytes" @@ -781,18 +763,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.32" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" +checksum = "8c1b05ca9d106ba7d2e31a9dab4a64e7be2cce415321966ea3132c49a656e252" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.32" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" +checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487" dependencies = [ "proc-macro2", "quote", @@ -827,48 +809,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -name = "uplc" -<<<<<<< HEAD -version = "0.0.11" -======= -<<<<<<< HEAD -version = "0.0.10" -======= -version = "0.0.8" -======= -======= ->>>>>>> 360364e (chore: fix lock file) -======= ->>>>>>> 75036f5 (chore: lock file again) name = "unicode-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> 27331bc (feat: add deps) -<<<<<<< HEAD ->>>>>>> c50961c (feat: add deps) ->>>>>>> 508f3c6 (feat: add deps) -dependencies = [ -<<<<<<< HEAD -<<<<<<< HEAD - "cryptoxide", -======= ->>>>>>> 2f7eda3 (chore: update lock file) -======= -======= ->>>>>>> 360364e (chore: fix lock file) -======= ->>>>>>> 75036f5 (chore: lock file again) name = "uplc" -version = "0.0.10" +version = "0.0.11" dependencies = [ "cryptoxide", "flat-rs", From 4f26957806c5ca73e34cd7b097dfa3a86f0e1cf3 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 26 Sep 2022 11:14:42 -0400 Subject: [PATCH 17/18] feat: some expr with precendence parsing --- crates/cli/src/args.rs | 6 +++ crates/lang/src/parser.rs | 80 +++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 8 deletions(-) diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index ef4c92ac..c8a6b5f3 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -81,6 +81,9 @@ pub enum UplcCommand { /// Print output instead of saving to file #[clap(short, long)] print: bool, + + #[clap(short, long)] + cbor_hex: bool, }, /// Format an Untyped Plutus Core program Fmt { @@ -103,6 +106,9 @@ pub enum UplcCommand { /// Print output instead of saving to file #[clap(short, long)] print: bool, + + #[clap(short, long)] + cbor_hex: bool, }, } diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index f320ffc5..00ed7872 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -1,7 +1,7 @@ use chumsky::prelude::*; use crate::{ - ast::{self, TodoKind}, + ast::{self, BinOp, TodoKind}, error::ParseError, expr, token::Token, @@ -259,7 +259,42 @@ pub fn expr_seq_parser() -> impl Parser impl Parser {} +pub fn expr_parser() -> impl Parser { + recursive(|r| { + let op = choice(( + just(Token::Star).to(BinOp::MultInt), + just(Token::Slash).to(BinOp::DivInt), + just(Token::Percent).to(BinOp::ModInt), + )); + + let product = expr_unit_parser() + .then(op.then(expr_unit_parser()).repeated()) + .foldl(|a, (op, b)| expr::UntypedExpr::BinOp { + location: a.location().union(b.location()), + name: op, + left: Box::new(a), + right: Box::new(b), + }) + .boxed(); + + let op = choice(( + just(Token::Plus).to(BinOp::AddInt), + just(Token::Minus).to(BinOp::SubInt), + )); + + let sum = product + .clone() + .then(op.then(product).repeated()) + .foldl(|a, (op, b)| expr::UntypedExpr::BinOp { + location: a.location().union(b.location()), + name: op, + left: Box::new(a), + right: Box::new(b), + }); + + sum + }) +} pub fn expr_unit_parser() -> impl Parser { choice(( @@ -512,7 +547,7 @@ mod tests { use crate::{ ast::{self, Span, SrcId}, - lexer, + expr, lexer, parser::module_parser, }; @@ -524,13 +559,13 @@ mod tests { use std/tx as t type Option(a) { - Some(a, Int) - None - Wow { name: Int, age: Int } + Some(a, Int) + None + Wow { name: Int, age: Int } } pub opaque type User { - name: _w + name: _w } type Thing = Option(Int) @@ -538,7 +573,7 @@ mod tests { pub type Me = Option(String) pub fn add_one(a) { - a + 1 + a + 1 } pub fn add_one(a: Int) -> Int { @@ -746,6 +781,35 @@ mod tests { public: true, tipo: (), }, + ast::UntypedDefinition::Fn { + arguments: vec![ast::Arg { + arg_name: ast::ArgName::Named { + name: "a".to_string(), + location: Span::new(SrcId::empty(), 430..431), + }, + location: Span::new(SrcId::empty(), 430..431), + annotation: None, + tipo: (), + },], + body: expr::UntypedExpr::BinOp { + location: Span::new(SrcId::empty(), 451..456), + name: ast::BinOp::AddInt, + left: Box::new(expr::UntypedExpr::Var { + location: Span::new(SrcId::empty(), 451..452), + name: "a".to_string(), + }), + right: Box::new(expr::UntypedExpr::Int { + location: Span::new(SrcId::empty(), 455..456), + value: "1".to_string(), + }), + }, + doc: None, + location: Span::new(SrcId::empty(), 415..470), + name: "add_one".to_string(), + public: true, + return_annotation: None, + return_type: (), + }, ] }, "{:#?}", From 119a6f1e774d15164a8fcc163de2d53217df577d Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 26 Sep 2022 17:04:54 -0400 Subject: [PATCH 18/18] feat: use pretty assert --- Cargo.lock | 44 +++++++++++++++++++++++ crates/lang/Cargo.toml | 3 ++ crates/lang/src/error.rs | 1 + crates/lang/src/parser.rs | 76 ++++++++++++++++++--------------------- 4 files changed, 82 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70b1f094..9998bb0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,7 @@ dependencies = [ "chumsky", "internment", "miette", + "pretty_assertions", "vec1", ] @@ -205,6 +206,22 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "129eabb7b0b78644a3a7e7cf220714aba47463bb281f69fa7a71ca5d12564cca" +[[package]] +name = "ctor" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "fastrand" version = "1.8.0" @@ -407,6 +424,15 @@ version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +[[package]] +name = "output_vt100" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +dependencies = [ + "winapi", +] + [[package]] name = "pallas-addresses" version = "0.14.0-alpha.4" @@ -544,6 +570,18 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "pretty_assertions" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" +dependencies = [ + "ctor", + "diff", + "output_vt100", + "yansi", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -968,3 +1006,9 @@ name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/crates/lang/Cargo.toml b/crates/lang/Cargo.toml index d04d8465..3168e866 100644 --- a/crates/lang/Cargo.toml +++ b/crates/lang/Cargo.toml @@ -10,3 +10,6 @@ chumsky = "0.8.0" internment = "0.7.0" miette = "5.2.0" vec1 = "1.8.0" + +[dev-dependencies] +pretty_assertions = "1.3.0" diff --git a/crates/lang/src/error.rs b/crates/lang/src/error.rs index 3c441615..ecfce194 100644 --- a/crates/lang/src/error.rs +++ b/crates/lang/src/error.rs @@ -6,6 +6,7 @@ use crate::{ast::Span, token::Token}; pub struct ParseError { kind: ErrorKind, span: Span, + #[allow(dead_code)] while_parsing: Option<(Span, &'static str)>, expected: HashSet, label: Option<&'static str>, diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index 00ed7872..c2c21f2d 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -250,7 +250,7 @@ pub fn expr_seq_parser() -> impl Parser impl Parser impl Parser { - recursive(|r| { + recursive(|_r| { let op = choice(( just(Token::Star).to(BinOp::MultInt), just(Token::Slash).to(BinOp::DivInt), @@ -282,7 +282,7 @@ pub fn expr_parser() -> impl Parser impl Parser impl Parser Int { - [1, 2, 3] - |> list.map(fn(x) { x + a }) - } "#; let len = code.chars().count(); @@ -639,31 +633,31 @@ mod tests { package: (), }, ast::UntypedDefinition::DataType { - location: Span::new(SrcId::empty(), 122..246), + location: Span::new(SrcId::empty(), 122..240), constructors: vec![ ast::RecordConstructor { - location: Span::new(SrcId::empty(), 155..167), + location: Span::new(SrcId::empty(), 153..165), name: "Some".to_string(), arguments: vec![ ast::RecordConstructorArg { label: None, annotation: ast::Annotation::Var { - location: Span::new(SrcId::empty(), 160..161), + location: Span::new(SrcId::empty(), 158..159), name: "a".to_string(), }, - location: Span::new(SrcId::empty(), 160..161), + location: Span::new(SrcId::empty(), 158..159), tipo: (), doc: None, }, ast::RecordConstructorArg { label: None, annotation: ast::Annotation::Constructor { - location: Span::new(SrcId::empty(), 163..166), + location: Span::new(SrcId::empty(), 161..164), module: None, name: "Int".to_string(), arguments: vec![], }, - location: Span::new(SrcId::empty(), 163..166), + location: Span::new(SrcId::empty(), 161..164), tipo: (), doc: None, }, @@ -672,37 +666,37 @@ mod tests { sugar: false, }, ast::RecordConstructor { - location: Span::new(SrcId::empty(), 184..188), + location: Span::new(SrcId::empty(), 180..184), name: "None".to_string(), arguments: vec![], documentation: None, sugar: false, }, ast::RecordConstructor { - location: Span::new(SrcId::empty(), 205..232), + location: Span::new(SrcId::empty(), 199..226), name: "Wow".to_string(), arguments: vec![ ast::RecordConstructorArg { label: Some("name".to_string(),), annotation: ast::Annotation::Constructor { - location: Span::new(SrcId::empty(), 217..220), + location: Span::new(SrcId::empty(), 211..214), module: None, name: "Int".to_string(), arguments: vec![], }, - location: Span::new(SrcId::empty(), 211..220), + location: Span::new(SrcId::empty(), 205..214), tipo: (), doc: None, }, ast::RecordConstructorArg { label: Some("age".to_string(),), annotation: ast::Annotation::Constructor { - location: Span::new(SrcId::empty(), 227..230), + location: Span::new(SrcId::empty(), 221..224), module: None, name: "Int".to_string(), arguments: vec![], }, - location: Span::new(SrcId::empty(), 222..230), + location: Span::new(SrcId::empty(), 216..224), tipo: (), doc: None, }, @@ -719,17 +713,17 @@ mod tests { typed_parameters: vec![], }, ast::UntypedDefinition::DataType { - location: Span::new(SrcId::empty(), 260..321), + location: Span::new(SrcId::empty(), 254..313), constructors: vec![ast::RecordConstructor { - location: Span::new(SrcId::empty(), 281..321), + location: Span::new(SrcId::empty(), 275..313), name: "User".to_string(), arguments: vec![ast::RecordConstructorArg { - label: Some("name".to_string(),), + label: Some("name".to_string()), annotation: ast::Annotation::Hole { - location: Span::new(SrcId::empty(), 305..307), + location: Span::new(SrcId::empty(), 297..299), name: "_w".to_string(), }, - location: Span::new(SrcId::empty(), 299..307), + location: Span::new(SrcId::empty(), 291..299), tipo: (), doc: None, },], @@ -746,18 +740,18 @@ mod tests { ast::UntypedDefinition::TypeAlias { alias: "Thing".to_string(), annotation: ast::Annotation::Constructor { - location: Span::new(SrcId::empty(), 348..359), + location: Span::new(SrcId::empty(), 340..351), module: None, name: "Option".to_string(), arguments: vec![ast::Annotation::Constructor { - location: Span::new(SrcId::empty(), 355..358), + location: Span::new(SrcId::empty(), 347..350), module: None, name: "Int".to_string(), arguments: vec![], },], }, doc: None, - location: Span::new(SrcId::empty(), 335..359), + location: Span::new(SrcId::empty(), 327..351), parameters: vec![], public: false, tipo: (), @@ -765,18 +759,18 @@ mod tests { ast::UntypedDefinition::TypeAlias { alias: "Me".to_string(), annotation: ast::Annotation::Constructor { - location: Span::new(SrcId::empty(), 387..401), + location: Span::new(SrcId::empty(), 379..393), module: None, name: "Option".to_string(), arguments: vec![ast::Annotation::Constructor { - location: Span::new(SrcId::empty(), 394..400), + location: Span::new(SrcId::empty(), 386..392), module: None, name: "String".to_string(), arguments: vec![], },], }, doc: None, - location: Span::new(SrcId::empty(), 373..401), + location: Span::new(SrcId::empty(), 365..393), parameters: vec![], public: true, tipo: (), @@ -785,26 +779,26 @@ mod tests { arguments: vec![ast::Arg { arg_name: ast::ArgName::Named { name: "a".to_string(), - location: Span::new(SrcId::empty(), 430..431), + location: Span::new(SrcId::empty(), 422..423), }, - location: Span::new(SrcId::empty(), 430..431), + location: Span::new(SrcId::empty(), 422..423), annotation: None, tipo: (), },], body: expr::UntypedExpr::BinOp { - location: Span::new(SrcId::empty(), 451..456), + location: Span::new(SrcId::empty(), 441..446), name: ast::BinOp::AddInt, left: Box::new(expr::UntypedExpr::Var { - location: Span::new(SrcId::empty(), 451..452), + location: Span::new(SrcId::empty(), 441..442), name: "a".to_string(), }), right: Box::new(expr::UntypedExpr::Int { - location: Span::new(SrcId::empty(), 455..456), + location: Span::new(SrcId::empty(), 445..446), value: "1".to_string(), }), }, doc: None, - location: Span::new(SrcId::empty(), 415..470), + location: Span::new(SrcId::empty(), 407..460), name: "add_one".to_string(), public: true, return_annotation: None, @@ -812,8 +806,6 @@ mod tests { }, ] }, - "{:#?}", - res, ); } }