From 60b63a769995bfc155726a30e39f44379a78c6b1 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 10 Aug 2021 21:32:12 +0200 Subject: [PATCH] Restructured project (#37) * Separation to two crates - `ablescript`: library, language - `ablescript_cli` - cli: repl and executor for files * Added lints (back) to library - unsafe_code and unwrap_used are forbidden --- Cargo.lock | 123 +++++++++++++++++---------- Cargo.toml | 20 +---- ablescript/Cargo.toml | 16 ++++ {src => ablescript/src}/ast.rs | 0 {src => ablescript/src}/base_55.rs | 0 {src => ablescript/src}/brian.rs | 0 {src => ablescript/src}/consts.rs | 0 {src => ablescript/src}/error.rs | 0 {src => ablescript/src}/interpret.rs | 0 {src => ablescript/src}/lexer.rs | 0 ablescript/src/lib.rs | 12 +++ {src => ablescript/src}/parser.rs | 0 {src => ablescript/src}/rickroll | 0 {src => ablescript/src}/variables.rs | 0 ablescript_cli/Cargo.toml | 18 ++++ {src => ablescript_cli/src}/main.rs | 17 +--- {src => ablescript_cli/src}/repl.rs | 3 +- 17 files changed, 132 insertions(+), 77 deletions(-) create mode 100644 ablescript/Cargo.toml rename {src => ablescript/src}/ast.rs (100%) rename {src => ablescript/src}/base_55.rs (100%) rename {src => ablescript/src}/brian.rs (100%) rename {src => ablescript/src}/consts.rs (100%) rename {src => ablescript/src}/error.rs (100%) rename {src => ablescript/src}/interpret.rs (100%) rename {src => ablescript/src}/lexer.rs (100%) create mode 100644 ablescript/src/lib.rs rename {src => ablescript/src}/parser.rs (100%) rename {src => ablescript/src}/rickroll (100%) rename {src => ablescript/src}/variables.rs (100%) create mode 100644 ablescript_cli/Cargo.toml rename {src => ablescript_cli/src}/main.rs (89%) rename {src => ablescript_cli/src}/repl.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index 78ceab8..0329313 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,12 +3,19 @@ version = 3 [[package]] -name = "able-script" +name = "ablescript" version = "0.2.0" dependencies = [ - "clap", "logos", "rand", +] + +[[package]] +name = "ablescript_cli" +version = "0.2.0" +dependencies = [ + "ablescript", + "clap", "rustyline", ] @@ -34,9 +41,9 @@ dependencies = [ [[package]] name = "beef" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6736e2428df2ca2848d846c43e88745121a6654696e349ce0054a420815a7409" +checksum = "bed554bd50246729a1ec158d08aa3235d1b69d94ad120ebe187e28894787e736" [[package]] name = "bitflags" @@ -46,9 +53,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" [[package]] name = "cfg-if" @@ -71,6 +78,17 @@ dependencies = [ "vec_map", ] +[[package]] +name = "clipboard-win" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4ea1881992efc993e4dc50a324cdbd03216e41bdc8385720ff47efc9bd2ca8" +dependencies = [ + "error-code", + "str-buf", + "winapi", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -99,26 +117,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" [[package]] -name = "fnv" -version = "1.0.7" +name = "error-code" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +checksum = "b5115567ac25674e0043e472be13d14e537f37ea8aa4bdc4aef0c89add1db1ff" +dependencies = [ + "libc", + "str-buf", +] [[package]] -name = "fs2" -version = "0.4.3" +name = "fd-lock" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +checksum = "0010f02effd88c702318c5dde0463206be67495d0b4d906ba7c0a8f166cc7f06" dependencies = [ "libc", "winapi", ] [[package]] -name = "getrandom" -version = "0.2.2" +name = "fnv" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if", "libc", @@ -127,18 +155,18 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "libc" -version = "0.2.93" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" [[package]] name = "log" @@ -175,9 +203,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "nibble_vec" @@ -208,9 +236,9 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" dependencies = [ "unicode-xid", ] @@ -236,9 +264,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", @@ -248,9 +276,9 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", "rand_core", @@ -258,27 +286,27 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom", ] [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ "rand_core", ] [[package]] name = "redox_syscall" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ "bitflags", ] @@ -295,20 +323,21 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.23" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustyline" -version = "8.0.0" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e1b597fcd1eeb1d6b25b493538e5aa19629eb08932184b85fef931ba87e893" +checksum = "fbd4eaf7a7738f76c98e4f0395253ae853be3eb018f7b0bb57fe1b6c17e31874" dependencies = [ "bitflags", "cfg-if", + "clipboard-win", "dirs-next", - "fs2", + "fd-lock", "libc", "log", "memchr", @@ -334,6 +363,12 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +[[package]] +name = "str-buf" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a" + [[package]] name = "strsim" version = "0.8.0" @@ -342,9 +377,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.69" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" dependencies = [ "proc-macro2", "quote", @@ -362,9 +397,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" @@ -374,9 +409,9 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "utf8-ranges" diff --git a/Cargo.toml b/Cargo.toml index 7738841..d893b91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,2 @@ -[package] -name = "able-script" -version = "0.2.0" -authors = ["able "] -edition = "2018" - -description = "The best programming language" -license-file = "LICENSE" -documentation = "https://ablecorp.us/able-script-the-book/" -repository = "https://github.com/AbleCorp/able-script" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -clap = "2.33" -logos = "0.12" -rand = "0.8" -rustyline = "8.0.0" +[workspace] +members = ["ablescript", "ablescript_cli"] \ No newline at end of file diff --git a/ablescript/Cargo.toml b/ablescript/Cargo.toml new file mode 100644 index 0000000..66a6381 --- /dev/null +++ b/ablescript/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ablescript" +version = "0.2.0" +authors = ["able "] +edition = "2018" + +description = "The best programming language" +license-file = "LICENSE" +documentation = "https://ablecorp.us/able-script-the-book/" +repository = "https://github.com/AbleCorp/able-script" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +logos = "0.12" +rand = "0.8" \ No newline at end of file diff --git a/src/ast.rs b/ablescript/src/ast.rs similarity index 100% rename from src/ast.rs rename to ablescript/src/ast.rs diff --git a/src/base_55.rs b/ablescript/src/base_55.rs similarity index 100% rename from src/base_55.rs rename to ablescript/src/base_55.rs diff --git a/src/brian.rs b/ablescript/src/brian.rs similarity index 100% rename from src/brian.rs rename to ablescript/src/brian.rs diff --git a/src/consts.rs b/ablescript/src/consts.rs similarity index 100% rename from src/consts.rs rename to ablescript/src/consts.rs diff --git a/src/error.rs b/ablescript/src/error.rs similarity index 100% rename from src/error.rs rename to ablescript/src/error.rs diff --git a/src/interpret.rs b/ablescript/src/interpret.rs similarity index 100% rename from src/interpret.rs rename to ablescript/src/interpret.rs diff --git a/src/lexer.rs b/ablescript/src/lexer.rs similarity index 100% rename from src/lexer.rs rename to ablescript/src/lexer.rs diff --git a/ablescript/src/lib.rs b/ablescript/src/lib.rs new file mode 100644 index 0000000..7a4e40b --- /dev/null +++ b/ablescript/src/lib.rs @@ -0,0 +1,12 @@ +#![forbid(unsafe_code, clippy::unwrap_used)] + +pub mod ast; +pub mod interpret; +pub mod parser; + +mod base_55; +mod brian; +mod consts; +mod error; +mod lexer; +mod variables; diff --git a/src/parser.rs b/ablescript/src/parser.rs similarity index 100% rename from src/parser.rs rename to ablescript/src/parser.rs diff --git a/src/rickroll b/ablescript/src/rickroll similarity index 100% rename from src/rickroll rename to ablescript/src/rickroll diff --git a/src/variables.rs b/ablescript/src/variables.rs similarity index 100% rename from src/variables.rs rename to ablescript/src/variables.rs diff --git a/ablescript_cli/Cargo.toml b/ablescript_cli/Cargo.toml new file mode 100644 index 0000000..1561e2c --- /dev/null +++ b/ablescript_cli/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "ablescript_cli" +version = "0.2.0" +authors = ["able "] +edition = "2018" + +description = "The best programming language" +license-file = "LICENSE" +documentation = "https://ablecorp.us/able-script-the-book/" +repository = "https://github.com/AbleCorp/able-script" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ablescript = { path = "../ablescript" } + +clap = "2.33" +rustyline = "8.0.0" diff --git a/src/main.rs b/ablescript_cli/src/main.rs similarity index 89% rename from src/main.rs rename to ablescript_cli/src/main.rs index 6863062..079dc5c 100644 --- a/src/main.rs +++ b/ablescript_cli/src/main.rs @@ -1,22 +1,11 @@ #![forbid(unsafe_code, clippy::unwrap_used)] - -mod ast; -mod base_55; -mod brian; -mod consts; -mod error; -mod interpret; -mod lexer; -mod parser; mod repl; -mod variables; use std::process::exit; +use ablescript::interpret::ExecEnv; +use ablescript::parser::Parser; use clap::{App, Arg}; -use interpret::ExecEnv; -use logos::Source; -use parser::Parser; fn main() { // variables::test(); // NOTE(Able): Add this as a test case @@ -64,7 +53,7 @@ fn main() { "Error `{:?}` occurred at span: {:?} = `{:?}`", e.kind, e.span.clone(), - source.slice(e.span) + &source[e.span] ); } } diff --git a/src/repl.rs b/ablescript_cli/src/repl.rs similarity index 96% rename from src/repl.rs rename to ablescript_cli/src/repl.rs index fdebf5d..c98a31e 100644 --- a/src/repl.rs +++ b/ablescript_cli/src/repl.rs @@ -1,6 +1,7 @@ use rustyline::Editor; -use crate::{interpret::ExecEnv, parser::Parser}; +use ablescript::interpret::ExecEnv; +use ablescript::parser::Parser; pub fn repl(ast_print: bool) { let mut rl = Editor::<()>::new();