diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ad93c79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + paths: + - "src/**" + - "tests/**" + - "features/**" + - "Cargo.*" + - ".rustfmt.toml" + - "README.md" + - ".github/workflows/ci.yml" + +env: + # We use environment variables to specify the Rust version and other settings once + RUST_TOOLCHAIN: 1.94.0 + CARGO_TERM_COLOR: always + +jobs: + check: + name: Lint & Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + components: rustfmt clippy + + - name: Check formatting + run: cargo fmt -- --check + + - name: Run clippy + run: cargo clippy --all-targets -- -D warnings + + - name: Run tests + run: cargo test diff --git a/Cargo.lock b/Cargo.lock index 4eb5a29..80a849b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,38 +443,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78" dependencies = [ "cfg-if", - "rustix 1.1.3", + "rustix 1.1.4", "windows-sys 0.59.0", ] [[package]] name = "flt" version = "0.0.2" -dependencies = [ - "bigdecimal", - "ctor", - "cucumber", - "env_logger", - "log", - "nom", - "regex", - "thiserror", - "tokio", -] - -[[package]] -name = "flt-cli" -version = "0.0.2" dependencies = [ "bigdecimal", "clap", + "ctor", "cucumber", "env_logger", "eyre", - "flt", "futures", "log", + "nom", + "regex", "rustyline", + "thiserror", "tokio", ] @@ -653,9 +641,9 @@ dependencies = [ [[package]] name = "indenter" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5" [[package]] name = "inflections" @@ -719,9 +707,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "linux-raw-sys" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "lock_api" @@ -1047,14 +1035,14 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ "bitflags", "errno", "libc", - "linux-raw-sys 0.11.0", + "linux-raw-sys 0.12.1", "windows-sys 0.61.2", ] diff --git a/Cargo.toml b/Cargo.toml index bba6b31..38bbcff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,31 @@ -[workspace] -resolver = "2" +[package] +name = "flt" +version = "0.0.2" +edition = "2021" +description = "a 'lite' functional language" +license = "MIT" -members = [ - "flt", - "flt-cli" -] +[dependencies] +bigdecimal = "0.4" +env_logger = "0.11.6" +log = "0.4.22" +nom = "8.0.0" +regex = "1.11.1" +thiserror = "2.0.9" +clap = { version = "4.5.23", features = ["cargo", "derive"] } +rustyline = "17.0" +eyre = "0.6.12" + +[dev-dependencies] +bigdecimal = "0.4" +ctor = "0.6.3" +cucumber = "0.22.1" +tokio = { version = "1.42.0", features = ["full"] } +futures = "0.3.31" + +[[test]] +name = "features" +harness = false [workspace.lints.clippy] unwrap_used = "deny" diff --git a/flt/features/ast.feature b/features/ast/ast.feature similarity index 100% rename from flt/features/ast.feature rename to features/ast/ast.feature diff --git a/flt/features/binary.feature b/features/ast/binary.feature similarity index 100% rename from flt/features/binary.feature rename to features/ast/binary.feature diff --git a/flt/features/comments.feature b/features/ast/comments.feature similarity index 100% rename from flt/features/comments.feature rename to features/ast/comments.feature diff --git a/flt/features/functions.feature b/features/ast/functions.feature similarity index 100% rename from flt/features/functions.feature rename to features/ast/functions.feature diff --git a/flt/features/maps.feature b/features/ast/maps.feature similarity index 100% rename from flt/features/maps.feature rename to features/ast/maps.feature diff --git a/flt/features/unary.feature b/features/ast/unary.feature similarity index 100% rename from flt/features/unary.feature rename to features/ast/unary.feature diff --git a/flt-cli/features/cli.feature b/features/cli.feature similarity index 100% rename from flt-cli/features/cli.feature rename to features/cli.feature diff --git a/flt-cli/features/repl/basic.feature b/features/repl/basic.feature similarity index 100% rename from flt-cli/features/repl/basic.feature rename to features/repl/basic.feature diff --git a/flt-cli/Cargo.toml b/flt-cli/Cargo.toml deleted file mode 100644 index d9052b5..0000000 --- a/flt-cli/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "flt-cli" -version = "0.0.2" -edition = "2021" -description = "the flt CLI" -license = "MIT" - -[lints] -workspace = true - -[dependencies] -bigdecimal = "0.4" -clap = { version = "4.5.23", features = ["cargo", "derive"] } -flt = { version = "0.0.2", path = "../flt" } -rustyline = "17.0" -env_logger = "0.11.6" -eyre = "0.6.12" -log = "0.4.22" - -[dev-dependencies] -cucumber = "0.22.1" -futures = "0.3.31" -tokio = { version = "1.42.0", features = ["full"] } - -[[test]] -name = "cli" -harness = false - -[[test]] -name = "repl" -harness = false diff --git a/flt/Cargo.toml b/flt/Cargo.toml deleted file mode 100644 index 5704628..0000000 --- a/flt/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "flt" -version = "0.0.2" -edition = "2021" -description = "a 'lite' functional language" -license = "MIT" - -[lints] -workspace = true - -[dependencies] -bigdecimal = "0.4" -env_logger = "0.11.6" -log = "0.4.22" -nom = "8.0.0" -regex = "1.11.1" -thiserror = "2.0.9" - -[dev-dependencies] -bigdecimal = "0.4" -ctor = "0.6.3" -cucumber = "0.22.1" -tokio = { version = "1.42.0", features = ["full"] } - -[[test]] -name = "features" -harness = false diff --git a/flt/language_evolution.md b/language_evolution.md similarity index 100% rename from flt/language_evolution.md rename to language_evolution.md diff --git a/flt/src/ast.rs b/src/ast.rs similarity index 100% rename from flt/src/ast.rs rename to src/ast.rs diff --git a/flt/src/ast/expr.rs b/src/ast/expr.rs similarity index 100% rename from flt/src/ast/expr.rs rename to src/ast/expr.rs diff --git a/flt/src/ast/identifier.rs b/src/ast/identifier.rs similarity index 100% rename from flt/src/ast/identifier.rs rename to src/ast/identifier.rs diff --git a/flt/src/ast/literal.rs b/src/ast/literal.rs similarity index 100% rename from flt/src/ast/literal.rs rename to src/ast/literal.rs diff --git a/flt/src/ast/number.rs b/src/ast/number.rs similarity index 100% rename from flt/src/ast/number.rs rename to src/ast/number.rs diff --git a/flt/src/ast/operands.rs b/src/ast/operands.rs similarity index 100% rename from flt/src/ast/operands.rs rename to src/ast/operands.rs diff --git a/flt-cli/src/main.rs b/src/bin/flt.rs similarity index 98% rename from flt-cli/src/main.rs rename to src/bin/flt.rs index 381b421..cdc0249 100644 --- a/flt-cli/src/main.rs +++ b/src/bin/flt.rs @@ -1,8 +1,6 @@ -mod eval; - use std::process::ExitCode; -use eval::eval; +use flt::eval::eval; use flt::parser::parse_expr; use rustyline::error::ReadlineError; use rustyline::DefaultEditor; diff --git a/flt/src/errors.rs b/src/errors.rs similarity index 100% rename from flt/src/errors.rs rename to src/errors.rs diff --git a/flt-cli/src/eval/mod.rs b/src/eval/mod.rs similarity index 97% rename from flt-cli/src/eval/mod.rs rename to src/eval/mod.rs index b2cf4fa..83fdaea 100644 --- a/flt-cli/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -1,11 +1,11 @@ +use crate::ast::BinaryOp; +use crate::ast::Expr; +use crate::ast::Literal; +use crate::ast::UnaryOp; +use crate::errors::Error; +use crate::errors::RuntimeError; +use crate::utils::escape_string; use bigdecimal::BigDecimal; -use flt::ast::BinaryOp; -use flt::ast::Expr; -use flt::ast::Literal; -use flt::ast::UnaryOp; -use flt::errors::Error; -use flt::errors::RuntimeError; -use flt::utils::escape_string; pub fn eval(expr: &Expr) -> Result { let lit = eval_to_literal(expr)?; @@ -131,11 +131,11 @@ fn binary_string(l: &Literal, r: &Literal) -> Result { #[cfg(test)] mod tests { - use flt::ast::BinaryOp; - use flt::ast::Expr; - use flt::ast::UnaryOp; - use flt::errors::Error; - use flt::errors::RuntimeError; + use crate::ast::BinaryOp; + use crate::ast::Expr; + use crate::ast::UnaryOp; + use crate::errors::Error; + use crate::errors::RuntimeError; use super::eval; diff --git a/flt/src/lib.rs b/src/lib.rs similarity index 61% rename from flt/src/lib.rs rename to src/lib.rs index 9993c89..7ebf75b 100644 --- a/flt/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ -#[doc = include_str!("../../README.md")] +#[doc = include_str!("../README.md")] pub mod ast; pub mod errors; +pub mod eval; pub mod parser; pub mod utils; diff --git a/flt/src/parser.rs b/src/parser.rs similarity index 100% rename from flt/src/parser.rs rename to src/parser.rs diff --git a/flt/src/parser/boolean.rs b/src/parser/boolean.rs similarity index 100% rename from flt/src/parser/boolean.rs rename to src/parser/boolean.rs diff --git a/flt/src/parser/comment.rs b/src/parser/comment.rs similarity index 100% rename from flt/src/parser/comment.rs rename to src/parser/comment.rs diff --git a/flt/src/parser/expr.rs b/src/parser/expr.rs similarity index 100% rename from flt/src/parser/expr.rs rename to src/parser/expr.rs diff --git a/flt/src/parser/function.rs b/src/parser/function.rs similarity index 100% rename from flt/src/parser/function.rs rename to src/parser/function.rs diff --git a/flt/src/parser/identifier.rs b/src/parser/identifier.rs similarity index 100% rename from flt/src/parser/identifier.rs rename to src/parser/identifier.rs diff --git a/flt/src/parser/literal.rs b/src/parser/literal.rs similarity index 100% rename from flt/src/parser/literal.rs rename to src/parser/literal.rs diff --git a/flt/src/parser/map.rs b/src/parser/map.rs similarity index 100% rename from flt/src/parser/map.rs rename to src/parser/map.rs diff --git a/flt/src/parser/number.rs b/src/parser/number.rs similarity index 100% rename from flt/src/parser/number.rs rename to src/parser/number.rs diff --git a/flt/src/parser/operands.rs b/src/parser/operands.rs similarity index 100% rename from flt/src/parser/operands.rs rename to src/parser/operands.rs diff --git a/flt/src/parser/string.rs b/src/parser/string.rs similarity index 100% rename from flt/src/parser/string.rs rename to src/parser/string.rs diff --git a/flt/src/parser/symbol.rs b/src/parser/symbol.rs similarity index 100% rename from flt/src/parser/symbol.rs rename to src/parser/symbol.rs diff --git a/flt/src/utils.rs b/src/utils.rs similarity index 100% rename from flt/src/utils.rs rename to src/utils.rs diff --git a/flt-cli/tests/cli.rs b/tests/cli.rs similarity index 100% rename from flt-cli/tests/cli.rs rename to tests/cli.rs diff --git a/flt/tests/features.rs b/tests/features.rs similarity index 100% rename from flt/tests/features.rs rename to tests/features.rs diff --git a/flt-cli/tests/repl.rs b/tests/repl.rs similarity index 100% rename from flt-cli/tests/repl.rs rename to tests/repl.rs