From 0d6b7b9bfc6e2af4c88278ac219ec628d363745f Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 9 Feb 2021 15:52:16 +0100 Subject: [PATCH 1/4] ci: only build master branch --- .builds/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.builds/ci.yml b/.builds/ci.yml index 9332efc..6f8c9fc 100644 --- a/.builds/ci.yml +++ b/.builds/ci.yml @@ -3,7 +3,7 @@ packages: - rust - node sources: - - https://git.sr.ht/~garritfra/sabre + - https://git.sr.ht/~garritfra/sabre#master tasks: - build: | cd sabre From cebbfce596be90de019ab2c90200c48bf3856ac1 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 9 Feb 2021 16:41:08 +0100 Subject: [PATCH 2/4] ci: add github actions --- .builds/ci.yml | 1 - .github/workflows/ci.yml | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.builds/ci.yml b/.builds/ci.yml index 6f8c9fc..7d3bf99 100644 --- a/.builds/ci.yml +++ b/.builds/ci.yml @@ -6,6 +6,5 @@ sources: - https://git.sr.ht/~garritfra/sabre#master tasks: - build: | - cd sabre cargo build cargo test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bd39dac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +on: [push, pull_request] + +name: Continuous integration + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: test + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- # -D warnings <-- Uncomment to fail when there is a clippy warning From fe78c6ade313dcdb5f67f49455b19e060047d5a5 Mon Sep 17 00:00:00 2001 From: Garrit Franke <32395585+garritfra@users.noreply.github.com> Date: Tue, 9 Feb 2021 17:34:47 +0100 Subject: [PATCH 3/4] GitHub actions (#3) * ci: fix clippy * ci: fix clippy warning * ci: add status badge to readme Co-authored-by: Garrit Franke --- README.md | 2 +- src/command/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f7f0d2..72aec95 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # The Sabre Programming language [![](https://img.shields.io/crates/v/sabre-lang.svg)](https://crates.io/crates/sabre-lang) -[![builds.sr.ht status](https://builds.sr.ht/~garritfra/sabre/commits/ci.yml.svg)](https://builds.sr.ht/~garritfra/sabre/commits/ci.yml?) +![Continuous integration](https://github.com/garritfra/sabre/workflows/Continuous%20integration/badge.svg?branch=master) [![docs](https://img.shields.io/badge/docs-mdBook-blue.svg)](https://garritfra.github.io/sabre/latest) [![Chat on Matrix](https://img.shields.io/badge/chat-on%20Matrix-green)](https://matrix.to/#/#sabre:matrix.slashdev.space?via=matrix.slashdev.space) diff --git a/src/command/build.rs b/src/command/build.rs index d562d75..287ecdb 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -39,7 +39,7 @@ pub fn build(in_file: &PathBuf, out_file: &PathBuf) -> Result<(), String> { let output = generator::generate(program); let mut file = std::fs::File::create(out_file).expect("create failed"); - file.write(output.as_bytes()).expect("write failed"); + file.write_all(output.as_bytes()).expect("write failed"); file.flush().expect("Could not flush file"); Ok(()) From 79d01c4f6c45842007b77880fc1d8ca0830770ef Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 9 Feb 2021 17:42:04 +0100 Subject: [PATCH 4/4] feat: array as function call parameter --- TODO | 1 - examples/playground.sb | 9 +++++---- src/generator/js.rs | 2 +- src/parser/rules.rs | 6 ++++++ src/parser/tests.rs | 1 - 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index a9b4bec..6e9d5cb 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ # Bugs - Nested expressions can have invalid parens. E.g.: 6 % 3 == 0 should be true; is false (See test_complex_nested_expressions) -- Arrays as function arguments don't work (See test_array_as_argument) # Cleanups - Improve error reporting (See ./util/string_util::highlight_position_in_file) diff --git a/examples/playground.sb b/examples/playground.sb index 6b9a030..3ed3f25 100644 --- a/examples/playground.sb +++ b/examples/playground.sb @@ -1,8 +1,9 @@ fn main() { + my_print([1, 2, 3]) +} - let arr = [1, 2, 3] - - for x in arr { - _printf(x) +fn my_print(x: int[]) { + for i in x { + println(i) } } \ No newline at end of file diff --git a/src/generator/js.rs b/src/generator/js.rs index bb649bd..8649982 100644 --- a/src/generator/js.rs +++ b/src/generator/js.rs @@ -212,7 +212,7 @@ fn generate_function_call(func: String, args: Vec) -> String { Expression::ArrayAccess(name, expr) => generate_array_access(name, *expr), Expression::FunctionCall(n, a) => generate_function_call(n, a), Expression::Str(s) | Expression::Variable(s) => s, - Expression::Array(_) => todo!(), + Expression::Array(elements) => generate_array(elements), Expression::BinOp(left, op, right) => generate_bin_op(*left, op, *right), }) .collect::>() diff --git a/src/parser/rules.rs b/src/parser/rules.rs index dcf1596..218c951 100644 --- a/src/parser/rules.rs +++ b/src/parser/rules.rs @@ -188,6 +188,12 @@ impl Parser { args.push(self.parse_expression()?) } TokenKind::Keyword(Keyword::Boolean) => args.push(self.parse_expression()?), + TokenKind::SquareBraceOpen => { + // TODO: Expression parsing currently uses `next` instead of `peek`. + // We have to eat that token here until that is resolved + self.match_token(TokenKind::SquareBraceOpen)?; + args.push(self.parse_array()?); + } _ => { return Err(self.make_error(TokenKind::BraceClose, next)); } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 0f2d54d..210b96b 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -766,7 +766,6 @@ fn test_complex_nested_expressions() { } #[test] -#[ignore] fn test_array_as_argument() { let raw = " fn main() {