diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 4c9dcb5..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,652 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "anstream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is-terminal", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" - -[[package]] -name = "anstyle-parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" -dependencies = [ - "anstyle", - "windows-sys", -] - -[[package]] -name = "backtrace" -version = "0.3.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" - -[[package]] -name = "bytecount" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" - -[[package]] -name = "cc" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" -dependencies = [ - "libc", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "4.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd" -dependencies = [ - "clap_builder", - "clap_derive", - "once_cell", -] - -[[package]] -name = "clap_builder" -version = "4.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.3.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.28", -] - -[[package]] -name = "clap_lex" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" - -[[package]] -name = "cli" -version = "0.1.0" -dependencies = [ - "clap", - "color-eyre", - "compiler", - "tabled", -] - -[[package]] -name = "color-eyre" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" -dependencies = [ - "backtrace", - "color-spantrace", - "eyre", - "indenter", - "once_cell", - "owo-colors", - "tracing-error", -] - -[[package]] -name = "color-spantrace" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" -dependencies = [ - "once_cell", - "owo-colors", - "tracing-core", - "tracing-error", -] - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - -[[package]] -name = "compiler" -version = "0.1.0" -dependencies = [ - "nom", - "nom-unicode", - "nom_locate", - "tabled", -] - -[[package]] -name = "errno" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "eyre" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" -dependencies = [ - "indenter", - "once_cell", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "gimli" -version = "0.27.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" - -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - -[[package]] -name = "is-terminal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix", - "windows-sys", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.147" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" - -[[package]] -name = "linux-raw-sys" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "nom-unicode" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5c03a4d71ab9740c752c165329e9df13a808093b146dfbef6170ac260771ffe" -dependencies = [ - "nom", -] - -[[package]] -name = "nom_locate" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e299bf5ea7b212e811e71174c5d1a5d065c4c0ad0c8691ecb1f97e3e66025e" -dependencies = [ - "bytecount", - "memchr", - "nom", -] - -[[package]] -name = "object" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "owo-colors" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" - -[[package]] -name = "papergrid" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ccbe15f2b6db62f9a9871642746427e297b0ceb85f9a7f1ee5ff47d184d0c8" -dependencies = [ - "bytecount", - "fnv", - "unicode-width", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c516611246607d0c04186886dbb3a754368ef82c79e9827a802c6d836dd111c" - -[[package]] -name = "proc-macro-error" -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 1.0.109", - "version_check", -] - -[[package]] -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", -] - -[[package]] -name = "proc-macro2" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustix" -version = "0.38.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tabled" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d38d39c754ae037a9bc3ca1580a985db7371cd14f1229172d1db9093feb6739" -dependencies = [ - "papergrid", - "tabled_derive", - "unicode-width", -] - -[[package]] -name = "tabled_derive" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99f688a08b54f4f02f0a3c382aefdb7884d3d69609f785bd253dc033243e3fe4" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-error" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" -dependencies = [ - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" -dependencies = [ - "sharded-slab", - "thread_local", - "tracing-core", -] - -[[package]] -name = "unicode-ident" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.48.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 20613bc..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[workspace] - -members = [ - "cli", - "compiler", -] - -[workspace.package] -authors = ["Adam Chalmers "] -description = "Tooling for KCL (KittyCAD Language)" -documentation = "docs.rs/kittycad-lang" -readme = "README.md" -publish = false -repository = "https://github.com/KittyCAD/kcl" -license = "MIT" diff --git a/README.md b/README.md index 02e91d5..08ec8dc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ -# KCL tools +# KCL experimental notes -Includes a compiler and CLI tool for KCL (KittyCADlang). \ No newline at end of file +Just for notes and ideas about different ways we could evovle KCL. + +You may be looking for the actual KCL tools, [in the modeling-app repo's 'kcl' subdirectory](https://github.com/KittyCAD/modeling-app/tree/main/src/wasm-lib/kcl). diff --git a/cli/Cargo.toml b/cli/Cargo.toml deleted file mode 100644 index 66e04e4..0000000 --- a/cli/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "cli" -version = "0.1.0" -edition = "2021" -authors.workspace = true -description.workspace = true -documentation.workspace = true -publish.workspace = true -repository.workspace = true -license.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -clap = { version = "4.3", features = ["derive"] } -color-eyre = "0.6.2" -compiler = { path = "../compiler" } -tabled = "0.13.0" diff --git a/cli/src/main.rs b/cli/src/main.rs deleted file mode 100644 index 01a14e1..0000000 --- a/cli/src/main.rs +++ /dev/null @@ -1,82 +0,0 @@ -use std::{ - io::{stdin, IsTerminal, Read}, - path::PathBuf, -}; - -use clap::Parser; -use color_eyre::eyre::{bail, Result, WrapErr}; -use tabled::{Table, Tabled}; - -#[derive(Parser, Debug)] -#[command(version, about, name = "KCL Compiler", long_about = None)] -struct Args { - #[arg(long)] - file: Option, -} - -impl Args { - /// Read a KCL file from wherever the user said to. - fn read_input_source_code(&self) -> Result { - let mut input = stdin(); - let mut source_code = String::new(); - if !input.is_terminal() { - input - .read_to_string(&mut source_code) - .wrap_err("could not read from stdin")?; - Ok(source_code) - } else if let Some(ref file) = self.file { - std::fs::read_to_string(file).wrap_err(format!("could not read {}", file.display())) - } else { - bail!("You must either supply a source code file via --file, or pipe source code in via stdin") - } - } -} - -fn main() -> Result<()> { - let args = Args::parse(); - let source_code = args.read_input_source_code()?; - - // Parse the KCL file and print results. - match compiler::parse(&source_code) { - Ok((input, ast)) if input.fragment().is_empty() => { - print_program_analysis(ast); - } - Ok((remaining_input, _ast)) => { - bail!("Part of your source code was not parsed: {remaining_input}") - } - Err(errors) => { - eprintln!("Your program did not parse. Here is the chain of parser errors. This is similar to a stack trace: the top row is the deepest parser in the parse tree. The bottom row is the parse tree root."); - let table = Table::new(errors); - eprintln!("{table}"); - std::process::exit(1) - } - } - Ok(()) -} - -fn print_program_analysis(ast: compiler::AbstractSyntaxTree<'_>) { - println!("Successfully parsed your program. These are its functions."); - - #[derive(Tabled)] - struct Row<'a> { - #[tabled(rename = "Name")] - function_name: &'a str, - line: u32, - columns: String, - } - let tbl = tabled::Table::new(ast.all_functions().map( - |( - function_name, - compiler::semantics::SourceRange { - start_line, - start_column, - length, - }, - )| Row { - function_name, - line: start_line, - columns: format!("{start_column}, {}", start_column + length), - }, - )); - println!("{tbl}"); -} diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml deleted file mode 100644 index 5e74d2f..0000000 --- a/compiler/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "compiler" -version = "0.1.0" -edition = "2021" -authors.workspace = true -description.workspace = true -documentation.workspace = true -publish.workspace = true -repository.workspace = true -license.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -nom = "7.1.3" -nom-unicode = "0.3.0" -nom_locate = "4.1.0" -tabled = "0.13.0" diff --git a/compiler/src/ast.rs b/compiler/src/ast.rs deleted file mode 100644 index ac34f31..0000000 --- a/compiler/src/ast.rs +++ /dev/null @@ -1,105 +0,0 @@ -//! Abstract syntax tree that KCL files get parsed into. -use std::fmt; - -use crate::parser::Input; - -/// For now, a KCL program is just a series of function definitions. -/// TODO: It should support also: -/// - Comments -/// - Import statements -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct AbstractSyntaxTree<'i> { - pub functions: Vec>, -} - -/// A KCL identifier can have a value bound to it. -/// Basically, it's anything that can be used as the name of a constant, function or type. -/// E.g. in `x = 1` the identifier is the name `x`. -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct Identifier<'i>(pub Input<'i>); - -impl<'i> fmt::Display for Identifier<'i> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(f) - } -} - -// In tests, you can turn a Rust string into an identifier. -// In prod, use the parser, because this does not guarantee that the string is a valid identifier. -#[cfg(test)] -impl<'i> From> for Identifier<'i> { - fn from(value: Input<'i>) -> Self { - Self(value) - } -} - -#[cfg(test)] -impl<'i> Identifier<'i> { - pub(crate) fn from_span(fragment: &'i str, offset: usize, line: u32) -> Self { - // Safe, because we're only doing this in unit tests. - unsafe { Self(Input::new_from_raw_offset(offset, line, fragment, ())) } - } -} - -/// Function definition -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct FnDef<'i> { - pub fn_name: Identifier<'i>, - pub params: Vec>, - pub return_type: Identifier<'i>, - pub body: Expression<'i>, -} - -/// Parameters for declared functions -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct Parameter<'i> { - pub name: Identifier<'i>, - pub kcl_type: Identifier<'i>, -} - -/// Function invocation -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct FnInvocation<'i> { - pub fn_name: Identifier<'i>, - pub args: Vec>, -} - -/// Expressions can be evaluated (producing a value) -/// or bound to identifiers by assignments. -#[derive(Debug, Clone, Eq, PartialEq)] -pub enum Expression<'i> { - /// Numbers are expressions - Number(u64), - /// Function invocations evaluate to their return value. - FnInvocation(FnInvocation<'i>), - /// A value bound to a name is an expression. - /// It evaluates to the bound value. - Name(Identifier<'i>), - /// Let-in expressions evaluate to the `in` part. - LetIn { - r#let: Vec>, - r#in: Box>, - }, - Arithmetic { - lhs: Box>, - op: Operator, - rhs: Box>, - }, -} - -/// Expressions can be evaluated (producing a value) -/// or bound to identifiers by assignments. -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub enum Operator { - Add, - Sub, - Mul, - Div, -} - -/// Assigning a value to a binding, e.g. `n = 100`. -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct Assignment<'i> { - pub identifier: Identifier<'i>, - pub value: Expression<'i>, -} diff --git a/compiler/src/displayable_error.rs b/compiler/src/displayable_error.rs deleted file mode 100644 index cba4b03..0000000 --- a/compiler/src/displayable_error.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::fmt; - -use nom::error::VerboseErrorKind; - -use crate::parser::Input; - -#[derive(tabled::Tabled)] -pub struct DisplayableError<'i> { - pub input: Input<'i>, - pub error: DisplayErr, - pub line: u32, - pub column: usize, -} - -impl<'i> DisplayableError<'i> { - pub fn new(input: Input<'i>, error: VerboseErrorKind) -> Self { - Self { - input, - error: DisplayErr::from(error), - line: input.location_line(), - column: input.get_utf8_column(), - } - } -} - -pub struct DisplayErr(pub VerboseErrorKind); - -impl From for DisplayErr { - fn from(value: VerboseErrorKind) -> Self { - Self(value) - } -} - -impl From for VerboseErrorKind { - fn from(value: DisplayErr) -> Self { - value.0 - } -} - -impl fmt::Display for DisplayErr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.0 { - VerboseErrorKind::Context(s) => s.fmt(f), - VerboseErrorKind::Char(c) => c.fmt(f), - VerboseErrorKind::Nom(kind) => kind.description().fmt(f), - } - } -} diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs deleted file mode 100644 index 34d61b4..0000000 --- a/compiler/src/lib.rs +++ /dev/null @@ -1,25 +0,0 @@ -mod ast; -pub mod displayable_error; -mod parser; -pub mod semantics; - -pub use ast::AbstractSyntaxTree; -use displayable_error::DisplayableError; -use nom::Finish; -use parser::{Input, Parser}; - -/// Parse the AST. -/// If successful, returns the remaining unparsed input and the AST. -/// If error, return the "parser tree trace", i.e. a the stack trace of all parsers which -/// were attempting to parse when the deepest one failed. Ordered from deepest to root. -pub fn parse( - source_code: &str, -) -> Result<(parser::Input, ast::AbstractSyntaxTree), Vec> { - let input = Input::new(source_code); - AbstractSyntaxTree::parse(input).finish().map_err(|e| { - e.errors - .into_iter() - .map(|(input, e)| DisplayableError::new(input, e)) - .collect() - }) -} diff --git a/compiler/src/parser.rs b/compiler/src/parser.rs deleted file mode 100644 index 3176b3b..0000000 --- a/compiler/src/parser.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! Parse KCL source into its AST. - -use nom::error::VerboseError; - -mod implementations; - -// ----------------------------------- -// CORE TYPES -// ----------------------------------- - -/// Input to a parser. -/// -/// All parsers read from a string containing the KCL source code. They only need to borrow the -/// string -- after all, parsers just read the string, they don't modify it or deallocate it. -/// So there's no need to take ownership. So, they borrow the string (take &str) instead of -/// owning it (take String). -/// -/// Here the lifetime 'i represents the lifetime of the input (the KCL source code string). -pub type Input<'i> = nom_locate::LocatedSpan<&'i str>; - -/// Result of running a parser. -/// -/// Parsers are generic over: -/// - 'i, the lifetime of the input. The parser doesn't care how long the input lasts for, so, it -/// can run on any borrowed string input, regardless of how long the borrow lasts. -/// - O, the Output type. If the parser is successful, it returns this output (O) type. -/// This is generic because different parsers return different types, e.g. a FunctionDefinition, -/// or a FunctionInvocation, or a ParameterList or an Identifier. -/// -/// Parsers return a result, because the parser might succeed or fail. -/// -/// The result's Ok branch is (Input, O) -- the remaining input, and the Output value which was -/// successfully parsed. -/// -/// The result's Err branch is a Nom error describing which parsers Nom tried, and why they failed. -pub type Result<'i, O> = nom::IResult, O, VerboseError>>; - -/// Take KCL source code as input and parse it into an AST node. -/// By convention, Nom parsers take a parameter `i` which means "input to the parser", -/// NOT "index to an array". -pub trait Parser<'i>: Sized { - fn parse(i: Input<'i>) -> Result; -} diff --git a/compiler/src/parser/implementations.rs b/compiler/src/parser/implementations.rs deleted file mode 100644 index 3d57e53..0000000 --- a/compiler/src/parser/implementations.rs +++ /dev/null @@ -1,571 +0,0 @@ -//! Implements the Parser trait for all the AST types. -use nom::{ - branch::alt, - bytes::complete::tag, - character::complete::{self as character, char as one_char, newline}, - combinator::{all_consuming, map, map_res, opt, recognize}, - error::context, - multi::{many1, separated_list0}, - sequence::{delimited, preceded, separated_pair, terminated, tuple}, - InputTakeAtPosition, -}; - -use crate::{ast::*, parser::*}; - -/// These can't be used as names in KCL programs. -const RESERVED_KEYWORDS: [&str; 2] = ["let", "in"]; - -impl<'i> Parser<'i> for AbstractSyntaxTree<'i> { - fn parse(i: Input<'i>) -> Result { - let parser = all_consuming(terminated( - separated_list0(many1(newline), FnDef::parse), - opt(newline), - )); - context( - "program root", - map(parser, |functions| AbstractSyntaxTree { functions }), - )(i) - } -} - -impl<'i> Parser<'i> for Identifier<'i> { - fn parse(i: Input<'i>) -> Result<'i, Self> { - // Checks if the ID is in the reserved keyword list. - let is_reserved_keyword = |id: Identifier<'i>| { - let is_reserved = RESERVED_KEYWORDS - .iter() - .any(|reserved_kw| reserved_kw == id.0.fragment()); - if is_reserved { - Err(format!("{id} is a reserved keyword and cannot be used as the name of a function, binding, type etc")) - } else { - Ok(id) - } - }; - - let parser = map_res(Self::parse_maybe_reserved, is_reserved_keyword); - context("identifier", parser)(i) - } -} - -impl<'i> Identifier<'i> { - /// Like `Identifier::parse` except it doesn't check if the identifier is a reserved keyword. - fn parse_maybe_reserved(i: Input<'i>) -> Result { - /// These characters aren't allowed in identifiers. - fn not_allowed_in_identifier(item: T) -> bool { - let i = item.as_char(); - !i.is_alphanumeric() && i != '_' - } - - let parser = preceded( - // Identifiers must start with an alphabetic character. - nom_unicode::complete::alpha1, - // But after the first char, they can include numbers and underscores. - |i: Input<'i>| i.split_at_position_complete(not_allowed_in_identifier), - ); - map(recognize(parser), Self)(i) - } -} - -impl<'i> Parser<'i> for FnDef<'i> { - /// FnDef looks like - /// myCircle = (radius: Distance -> Solid2D) => circle(radius) - fn parse(i: Input<'i>) -> Result { - // Parse the parts of a function definition. - let parse_parts = tuple(( - context("function name", Identifier::parse), - context("= between function name and definition", tag(" = ")), - context( - "type signature", - bracketed(tuple(( - context( - "parameter list", - separated_list0(tag(", "), Parameter::parse), - ), - context("return type arrow ->", tag(" -> ")), - Identifier::parse, - ))), - ), - context( - "=> between function header and body", - terminated(tag(" =>"), character::multispace0), - ), - context("function body", Expression::parse), - )); - - // Convert the parts we actually need into a FnDef, ignoring the parts we don't need. - let parser = map( - parse_parts, - |(fn_name, _, (params, _, return_type), _, body)| Self { - fn_name, - params, - return_type, - body, - }, - ); - context("function definition", parser)(i) - } -} - -impl<'i> Parser<'i> for Parameter<'i> { - fn parse(i: Input<'i>) -> Result { - // Looks like `radius: Distance` - let parser = map( - separated_pair(Identifier::parse, tag(": "), Identifier::parse), - |(name, kcl_type)| Self { name, kcl_type }, - ); - context("parameter", parser)(i) - } -} - -impl<'i> Parser<'i> for FnInvocation<'i> { - fn parse(i: Input<'i>) -> Result { - let parse_parts = tuple(( - Identifier::parse, - bracketed(separated_list0(tag(", "), Expression::parse)), - )); - let parser = map(parse_parts, |(fn_name, args)| FnInvocation { - fn_name, - args, - }); - context("function invocation", parser)(i) - } -} - -impl<'i> Parser<'i> for Expression<'i> { - fn parse(i: Input<'i>) -> Result { - let parser = alt(( - Self::parse_arithmetic, - Self::parse_num, - Self::parse_let_in, - map(FnInvocation::parse, Self::FnInvocation), - map(Identifier::parse, Self::Name), - )); - context("expression", parser)(i) - } -} - -impl<'i> Parser<'i> for Operator { - fn parse(i: Input<'i>) -> Result { - let parser = map_res( - alt((one_char('+'), one_char('-'), one_char('*'), one_char('/'))), - |symbol| { - Ok(match symbol { - '+' => Self::Add, - '-' => Self::Sub, - '*' => Self::Mul, - '/' => Self::Div, - other => return Err(format!("Invalid operator {other}")), - }) - }, - ); - context("operator", parser)(i) - } -} - -impl<'i> Expression<'i> { - fn parse_arithmetic(i: Input<'i>) -> Result { - let parser = map( - bracketed(tuple(( - Self::parse, - delimited(one_char(' '), Operator::parse, one_char(' ')), - Self::parse, - ))), - |(lhs, op, rhs)| Self::Arithmetic { - lhs: Box::new(lhs), - op, - rhs: Box::new(rhs), - }, - ); - context("arithmetic", parser)(i) - } - - fn parse_let_in(i: Input<'i>) -> Result { - let parser = map( - tuple(( - tag("let"), - character::newline, - many1(tuple(( - character::multispace0, - Assignment::parse, - character::newline, - ))), - terminated( - preceded(character::multispace0, tag("in")), - character::multispace0, - ), - Expression::parse, - )), - |(_, _, assignments, _, expr)| Self::LetIn { - r#let: assignments - .into_iter() - .map(|(_, assign, _)| assign) - .collect(), - r#in: Box::new(expr), - }, - ); - context("let-in", parser)(i) - } - - fn parse_num(i: Input<'i>) -> Result { - // Numbers are a sequence of digits and underscores. - let allowed_chars = character::one_of("0123456789_"); - let number = nom::multi::many1(allowed_chars); - let parser = map_res(number, |chars| { - let digits_only = chars - .into_iter() - .filter(|c| c.is_ascii_digit()) - .collect::(); - digits_only.parse().map(Self::Number) - }); - context("number", parser)(i) - } -} - -impl<'i> Parser<'i> for Assignment<'i> { - fn parse(i: Input<'i>) -> Result { - let parts = tuple(( - Identifier::parse, - nom::bytes::complete::tag(" = "), - Expression::parse, - )); - let parser = map(parts, |(identifier, _, value)| Self { identifier, value }); - context("assignment", parser)(i) - } -} - -/// Utility parser combinator. It wraps a child parser. -/// Returns a parser which parses and discards a '(', -/// then runs the child parser, -/// then parses and discards a ')'. -/// Returns whatever the child parser returned. -pub fn bracketed, P>( - mut child_parser: P, -) -> impl FnMut(I) -> nom::IResult -where - I: nom::Slice> + nom::InputIter, - P: nom::Parser, - ::Item: nom::AsChar, -{ - use nom::Parser; - // Remember, `i` in Nom parsers always means "input". - move |i: I| { - let (i, _) = one_char('(').parse(i)?; - let (i, output) = child_parser.parse(i)?; - let (i, _) = one_char(')').parse(i)?; - Ok((i, output)) - } -} - -#[cfg(test)] -mod tests { - - use tabled::Table; - - use super::*; - use crate::displayable_error::DisplayableError; - - /// Assert that the given input successfully parses into the expected value. - fn assert_parse<'i, T>(tests: Vec<(T, Input<'i>)>) - where - T: Parser<'i> + std::fmt::Debug + PartialEq, - { - for (test_id, (expected, i)) in tests.into_iter().enumerate() { - let res: Result = T::parse(i); - let (i, actual) = match res { - Ok(t) => t, - Err(nom::Err::Error(e) | nom::Err::Failure(e)) => { - eprintln!("Could not parse the test case."); - eprintln!("Here's the error chain. Top row is the last parser tried, i.e. the bottom of the parse tree."); - eprintln!("The bottom row is the root of the parse tree."); - let err_table = Table::new( - e.errors - .into_iter() - .map(|(input, e)| DisplayableError::new(input, e)), - ); - eprintln!("{err_table}"); - panic!("Could not parse test case"); - } - Err(nom::Err::Incomplete(_)) => { - panic!("These are not streaming parsers") - } - }; - assert!( - i.is_empty(), - "Input should have been empty, but '{i}' remained. Parsed {actual:#?}." - ); - assert_eq!( - actual, expected, - "failed test {test_id}: expected {expected:#?} and got {actual:#?}" - ); - } - } - - /// Assert that the given input fails to parse. - fn assert_not_parse<'i, T>(i: Input<'i>) - where - T: Parser<'i> + std::fmt::Debug + PartialEq, - { - let _err = T::parse(i).unwrap_err(); - } - - #[test] - fn test_expr_number() { - assert_parse(vec![ - (Expression::Number(123), Input::new("12_3")), - (Expression::Number(123), Input::new("123")), - (Expression::Number(1), Input::new("1")), - (Expression::Number(2), Input::new("2")), - ]); - } - - #[test] - fn test_expr_arith() { - assert_parse(vec![ - ( - Expression::Arithmetic { - lhs: Box::new(Expression::Number(1)), - op: Operator::Add, - rhs: Box::new(Expression::Number(2)), - }, - Input::new("(1 + 2)"), - ), - (Expression::Number(123), Input::new("123")), - ]); - } - - #[test] - fn valid_function_invocations() { - assert_parse(vec![( - Expression::FnInvocation(FnInvocation { - fn_name: Identifier::from_span("sphere", 0, 1), - args: vec![Expression::Number(1), Expression::Number(2)], - }), - Input::new("sphere(1, 2)"), - )]) - } - - #[test] - fn valid_program() { - assert_parse(vec![( - AbstractSyntaxTree { - functions: vec![ - FnDef { - fn_name: Identifier::from_span("bigCircle1", 0, 1), - params: vec![ - Parameter { - name: Identifier::from_span("radius", 14, 1), - kcl_type: Identifier::from_span("Distance", 22, 1), - }, - Parameter { - name: Identifier::from_span("center", 32, 1), - kcl_type: Identifier::from_span("Point2D", 40, 1), - }, - ], - body: Expression::FnInvocation(FnInvocation { - fn_name: Identifier::from_span("circle", 63, 1), - args: vec![Expression::Name(Identifier::from_span("radius", 70, 1))], - }), - return_type: Identifier::from_span("Solid2D", 51, 1), - }, - FnDef { - fn_name: Identifier::from_span("bigCircle2", 78, 2), - params: vec![ - Parameter { - name: Identifier::from_span("radius", 92, 2), - kcl_type: Identifier::from_span("Distance", 100, 2), - }, - Parameter { - name: Identifier::from_span("center", 110, 2), - kcl_type: Identifier::from_span("Point2D", 118, 2), - }, - ], - body: Expression::FnInvocation(FnInvocation { - fn_name: Identifier::from_span("circle", 141, 2), - args: vec![Expression::Name(Identifier::from_span("radius", 148, 2))], - }), - return_type: Identifier::from_span("Solid2D", 129, 2), - }, - ], - }, - Input::new( - r#"bigCircle1 = (radius: Distance, center: Point2D -> Solid2D) => circle(radius) -bigCircle2 = (radius: Distance, center: Point2D -> Solid2D) => circle(radius) -"#, - ), - )]) - } - - #[test] - fn valid_function_definition() { - assert_parse(vec![ - ( - FnDef { - fn_name: Identifier::from_span("bigCircle", 0, 1), - params: vec![ - Parameter { - name: Identifier::from_span("radius", 13, 1), - kcl_type: Identifier::from_span("Distance", 21, 1), - }, - Parameter { - name: Identifier::from_span("center", 31, 1), - kcl_type: Identifier::from_span("Point2D", 39, 1), - }, - ], - body: Expression::FnInvocation(FnInvocation { - fn_name: Identifier::from_span("circle", 62, 1), - args: vec![Expression::Name(Identifier::from_span("radius", 69, 1))], - }), - return_type: Identifier::from_span("Solid2D", 50, 1), - }, - Input::new( - r#"bigCircle = (radius: Distance, center: Point2D -> Solid2D) => circle(radius)"#, - ), - ), - ( - FnDef { - fn_name: Identifier::from_span("bigCircle", 0, 1), - params: vec![Parameter { - name: Identifier::from_span("center", 13, 1), - kcl_type: Identifier::from_span("Point2D", 21, 1), - }], - body: Expression::LetIn { - r#let: vec![Assignment { - identifier: Identifier::from_span("radius", 84, 3), - value: Expression::Arithmetic { - lhs: Box::new(Expression::Number(14)), - op: Operator::Mul, - rhs: Box::new(Expression::Number(100)), - }, - }], - r#in: Box::new(Expression::FnInvocation(FnInvocation { - fn_name: Identifier::from_span("circle", 123, 4), - args: vec![ - Expression::Name(Identifier::from_span("radius", 130, 4)), - Expression::Name(Identifier::from_span("center", 138, 4)), - ], - })), - }, - return_type: Identifier::from_span("Solid2D", 32, 1), - }, - Input::new( - "\ - bigCircle = (center: Point2D -> Solid2D) => - let - radius = (14 * 100) - in circle(radius, center)", - ), - ), - ]) - } - - #[test] - fn let_in() { - assert_parse(vec![ - ( - Expression::LetIn { - r#let: vec![ - Assignment { - identifier: Identifier::from_span("x", 8, 2), - value: Expression::Number(1), - }, - Assignment { - identifier: Identifier::from_span("y", 18, 3), - value: Expression::Name(Identifier::from_span("x", 22, 3)), - }, - ], - r#in: Box::new(Expression::Name(Identifier::from_span("y", 27, 4))), - }, - Input::new( - r#"let - x = 1 - y = x -in y"#, - ), - ), - ( - Expression::LetIn { - r#let: vec![Assignment { - identifier: Identifier::from_span("radius", 20, 2), - value: Expression::Arithmetic { - lhs: Box::new(Expression::Number(14)), - op: Operator::Mul, - rhs: Box::new(Expression::Number(100)), - }, - }], - r#in: Box::new(Expression::FnInvocation(FnInvocation { - fn_name: Identifier::from_span("circle", 55, 3), - args: vec![ - Expression::Name(Identifier::from_span("radius", 62, 3)), - Expression::Name(Identifier::from_span("center", 70, 3)), - ], - })), - }, - Input::new( - r#"let - radius = (14 * 100) - in circle(radius, center)"#, - ), - ), - ]) - } - - #[test] - fn test_assignment() { - let valid_lhs = ["n"]; - let tests: Vec<_> = valid_lhs - .into_iter() - .flat_map(|lhs| { - vec![ - ( - Assignment { - identifier: Identifier::from_span(lhs, 0, 1), - value: Expression::FnInvocation(FnInvocation { - fn_name: Identifier::from_span("foo", 4, 1), - args: vec![Expression::Number(100)], - }), - }, - format!("{lhs} = foo(100)"), - ), - ( - Assignment { - identifier: Identifier::from_span(lhs, 0, 1), - value: Expression::Number(100), - }, - format!("{lhs} = 100"), - ), - ] - }) - .collect(); - let ref_to_tests = tests - .iter() - .map(|(exp, input)| (exp.to_owned(), Input::new(input.as_str()))) - .collect(); - assert_parse(ref_to_tests) - } - - #[test] - fn test_valid_variables() { - let tests = vec![( - Identifier::from_span("n_hello", 0, 1), - Input::new("n_hello"), - )]; - assert_parse::(tests) - } - - #[test] - fn test_invalid_variables() { - let invalid_binding_names = [ - // These are genuinely invalid. - "n(", - "123", - "n h", - "let", - "in", - "0000000aassdfasdfasdfasdf013423452342134234234234", - ]; - for identifier in invalid_binding_names { - let i = format!("{identifier} = 100"); - assert_not_parse::(Input::from(i.as_ref())) - } - } -} diff --git a/compiler/src/semantics.rs b/compiler/src/semantics.rs deleted file mode 100644 index c63ac70..0000000 --- a/compiler/src/semantics.rs +++ /dev/null @@ -1,28 +0,0 @@ -use crate::AbstractSyntaxTree; - -#[derive(Debug)] -pub struct SourceRange { - pub start_line: u32, - pub start_column: usize, - pub length: usize, -} - -impl<'i> AbstractSyntaxTree<'i> { - /// Iterates over all functions in the file. Returns each function's name, - /// and the source code range where that name is found. - pub fn all_functions(&self) -> impl Iterator + '_ { - self.functions.iter().map(|function| { - let name = function.fn_name.0.fragment(); - let start_line = function.fn_name.0.location_line(); - let start_column = function.fn_name.0.get_utf8_column(); - ( - name, - SourceRange { - start_line, - start_column, - length: name.len(), - }, - ) - }) - } -} diff --git a/deny.toml b/deny.toml deleted file mode 100644 index ddbf766..0000000 --- a/deny.toml +++ /dev/null @@ -1,272 +0,0 @@ -# This template contains all of the possible sections and their default values - -# Note that all fields that take a lint level have these possible values: -# * deny - An error will be produced and the check will fail -# * warn - A warning will be produced, but the check will not fail -# * allow - No warning or error will be produced, though in some cases a note -# will be - -# The values provided in this template are the default values that will be used -# when any section or field is not specified in your own configuration - -# Root options - -# If 1 or more target triples (and optionally, target_features) are specified, -# only the specified targets will be checked when running `cargo deny check`. -# This means, if a particular package is only ever used as a target specific -# dependency, such as, for example, the `nix` crate only being used via the -# `target_family = "unix"` configuration, that only having windows targets in -# this list would mean the nix crate, as well as any of its exclusive -# dependencies not shared by any other crates, would be ignored, as the target -# list here is effectively saying which targets you are building for. -targets = [ - # The triple can be any string, but only the target triples built in to - # rustc (as of 1.40) can be checked against actual config expressions - #{ triple = "x86_64-unknown-linux-musl" }, - # You can also specify which target_features you promise are enabled for a - # particular target. target_features are currently not validated against - # the actual valid features supported by the target architecture. - #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, -] -# When creating the dependency graph used as the source of truth when checks are -# executed, this field can be used to prune crates from the graph, removing them -# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate -# is pruned from the graph, all of its dependencies will also be pruned unless -# they are connected to another crate in the graph that hasn't been pruned, -# so it should be used with care. The identifiers are [Package ID Specifications] -# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) -#exclude = [] -# If true, metadata will be collected with `--all-features`. Note that this can't -# be toggled off if true, if you want to conditionally enable `--all-features` it -# is recommended to pass `--all-features` on the cmd line instead -all-features = false -# If true, metadata will be collected with `--no-default-features`. The same -# caveat with `all-features` applies -no-default-features = false -# If set, these feature will be enabled when collecting metadata. If `--features` -# is specified on the cmd line they will take precedence over this option. -#features = [] -# When outputting inclusion graphs in diagnostics that include features, this -# option can be used to specify the depth at which feature edges will be added. -# This option is included since the graphs can be quite large and the addition -# of features from the crate(s) to all of the graph roots can be far too verbose. -# This option can be overridden via `--feature-depth` on the cmd line -feature-depth = 1 - -# This section is considered when running `cargo deny check advisories` -# More documentation for the advisories section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html -[advisories] -# The path where the advisory database is cloned/fetched into -db-path = "~/.cargo/advisory-db" -# The url(s) of the advisory databases to use -db-urls = ["https://github.com/rustsec/advisory-db"] -# The lint level for security vulnerabilities -vulnerability = "deny" -# The lint level for unmaintained crates -unmaintained = "warn" -# The lint level for crates that have been yanked from their source registry -yanked = "warn" -# The lint level for crates with security notices. Note that as of -# 2019-12-17 there are no security notice advisories in -# https://github.com/rustsec/advisory-db -notice = "warn" -# A list of advisory IDs to ignore. Note that ignored advisories will still -# output a note when they are encountered. -ignore = [ - #"RUSTSEC-0000-0000", -] -# Threshold for security vulnerabilities, any vulnerability with a CVSS score -# lower than the range specified will be ignored. Note that ignored advisories -# will still output a note when they are encountered. -# * None - CVSS Score 0.0 -# * Low - CVSS Score 0.1 - 3.9 -# * Medium - CVSS Score 4.0 - 6.9 -# * High - CVSS Score 7.0 - 8.9 -# * Critical - CVSS Score 9.0 - 10.0 -#severity-threshold = - -# If this is true, then cargo deny will use the git executable to fetch advisory database. -# If this is false, then it uses a built-in git library. -# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. -# See Git Authentication for more information about setting up git authentication. -#git-fetch-with-cli = true - -# This section is considered when running `cargo deny check licenses` -# More documentation for the licenses section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html -[licenses] -# The lint level for crates which do not have a detectable license -unlicensed = "deny" -# List of explicitly allowed licenses -# See https://spdx.org/licenses/ for list of possible licenses -# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. -allow = [ - "MIT", - "Apache-2.0", - "Unicode-DFS-2016", - #"Apache-2.0 WITH LLVM-exception", -] -# List of explicitly disallowed licenses -# See https://spdx.org/licenses/ for list of possible licenses -# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. -deny = [ - #"Nokia", -] -# Lint level for licenses considered copyleft -copyleft = "warn" -# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses -# * both - The license will be approved if it is both OSI-approved *AND* FSF -# * either - The license will be approved if it is either OSI-approved *OR* FSF -# * osi-only - The license will be approved if is OSI-approved *AND NOT* FSF -# * fsf-only - The license will be approved if is FSF *AND NOT* OSI-approved -# * neither - This predicate is ignored and the default lint level is used -allow-osi-fsf-free = "neither" -# Lint level used when no other predicates are matched -# 1. License isn't in the allow or deny lists -# 2. License isn't copyleft -# 3. License isn't OSI/FSF, or allow-osi-fsf-free = "neither" -default = "deny" -# The confidence threshold for detecting a license from license text. -# The higher the value, the more closely the license text must be to the -# canonical license text of a valid SPDX license file. -# [possible values: any between 0.0 and 1.0]. -confidence-threshold = 0.8 -# Allow 1 or more licenses on a per-crate basis, so that particular licenses -# aren't accepted for every possible crate as with the normal allow list -exceptions = [ - # Each entry is the crate and version constraint, and its specific allow - # list - #{ allow = ["Zlib"], name = "adler32", version = "*" }, -] - -# Some crates don't have (easily) machine readable licensing information, -# adding a clarification entry for it allows you to manually specify the -# licensing information -#[[licenses.clarify]] -# The name of the crate the clarification applies to -#name = "ring" -# The optional version constraint for the crate -#version = "*" -# The SPDX expression for the license requirements of the crate -#expression = "MIT AND ISC AND OpenSSL" -# One or more files in the crate's source used as the "source of truth" for -# the license expression. If the contents match, the clarification will be used -# when running the license check, otherwise the clarification will be ignored -# and the crate will be checked normally, which may produce warnings or errors -# depending on the rest of your configuration -#license-files = [ - # Each entry is a crate relative path, and the (opaque) hash of its contents - #{ path = "LICENSE", hash = 0xbd0eed23 } -#] - -[licenses.private] -# If true, ignores workspace crates that aren't published, or are only -# published to private registries. -# To see how to mark a crate as unpublished (to the official registry), -# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. -ignore = true -# One or more private registries that you might publish crates to, if a crate -# is only published to private registries, and ignore is true, the crate will -# not have its license(s) checked -registries = [ - #"https://sekretz.com/registry -] - -# This section is considered when running `cargo deny check bans`. -# More documentation about the 'bans' section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html -[bans] -# Lint level for when multiple versions of the same crate are detected -multiple-versions = "warn" -# Lint level for when a crate version requirement is `*` -wildcards = "allow" -# The graph highlighting used when creating dotgraphs for crates -# with multiple versions -# * lowest-version - The path to the lowest versioned duplicate is highlighted -# * simplest-path - The path to the version with the fewest edges is highlighted -# * all - Both lowest-version and simplest-path are used -highlight = "all" -# The default lint level for `default` features for crates that are members of -# the workspace that is being checked. This can be overriden by allowing/denying -# `default` on a crate-by-crate basis if desired. -workspace-default-features = "allow" -# The default lint level for `default` features for external crates that are not -# members of the workspace. This can be overriden by allowing/denying `default` -# on a crate-by-crate basis if desired. -external-default-features = "allow" -# List of crates that are allowed. Use with care! -allow = [ - #{ name = "ansi_term", version = "=0.11.0" }, -] -# List of crates to deny -deny = [ - # Each entry the name of a crate and a version range. If version is - # not specified, all versions will be matched. - { name = "tokio", version = "<1" }, - { name = "clap", version = "<4" }, - { name = "time", version = "<0.3" }, - # - # Wrapper crates can optionally be specified to allow the crate when it - # is a direct dependency of the otherwise banned crate - #{ name = "ansi_term", version = "=0.11.0", wrappers = [] }, -] - -# List of features to allow/deny -# Each entry the name of a crate and a version range. If version is -# not specified, all versions will be matched. -#[[bans.features]] -#name = "reqwest" -# Features to not allow -#deny = ["json"] -# Features to allow -#allow = [ -# "rustls", -# "__rustls", -# "__tls", -# "hyper-rustls", -# "rustls", -# "rustls-pemfile", -# "rustls-tls-webpki-roots", -# "tokio-rustls", -# "webpki-roots", -#] -# If true, the allowed features must exactly match the enabled feature set. If -# this is set there is no point setting `deny` -#exact = true - -# Certain crates/versions that will be skipped when doing duplicate detection. -skip = [ - #{ name = "ansi_term", version = "=0.11.0" }, -] -# Similarly to `skip` allows you to skip certain crates during duplicate -# detection. Unlike skip, it also includes the entire tree of transitive -# dependencies starting at the specified crate, up to a certain depth, which is -# by default infinite. -skip-tree = [ - #{ name = "ansi_term", version = "=0.11.0", depth = 20 }, -] - -# This section is considered when running `cargo deny check sources`. -# More documentation about the 'sources' section can be found here: -# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html -[sources] -# Lint level for what to happen when a crate from a crate registry that is not -# in the allow list is encountered -unknown-registry = "warn" -# Lint level for what to happen when a crate from a git repository that is not -# in the allow list is encountered -unknown-git = "warn" -# List of URLs for allowed crate registries. Defaults to the crates.io index -# if not specified. If it is specified but empty, no registries are allowed. -allow-registry = ["https://github.com/rust-lang/crates.io-index"] -# List of URLs for allowed Git repositories -allow-git = [] - -[sources.allow-org] -# 1 or more github.com organizations to allow git sources for -# github = ["KittyCAD", "oxidecomputer"] -# 1 or more gitlab.com organizations to allow git sources for -# gitlab = [""] -# 1 or more bitbucket.org organizations to allow git sources for -# bitbucket = [""] diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 8a1ab63..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,8 +0,0 @@ -# We use a specific toolchain revision to ensure our tests - which -# occasionally depend on specific compiler output - remain stable -# for all developers until the toolchain is explicitly advanced. -# The intent is to keep this updated as new stable versions are relased. - -[toolchain] -channel = "1.71.0" -profile = "default" diff --git a/rustfmt.toml b/rustfmt.toml deleted file mode 100644 index f6b633a..0000000 --- a/rustfmt.toml +++ /dev/null @@ -1,2 +0,0 @@ -imports_granularity = "Crate" -group_imports = "StdExternalCrate" \ No newline at end of file diff --git a/test.kcl b/test.kcl deleted file mode 100644 index 5c3f248..0000000 --- a/test.kcl +++ /dev/null @@ -1,5 +0,0 @@ -bigCircle = (radius: Distance, center: Point2D -> Solid2D) => - circle(center, (radius * 10)) - -smallCircle = (radius: Distance, center: Point2D -> Solid2D) => - circle(Point2D(0, 0), 4)