From 74913581c2e38bcfee813b0403bc77ead55919c7 Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 12:17:49 +0800 Subject: [PATCH 01/11] + helper --- Cargo.lock | 1 + three_body_e2021/Cargo.toml | 5 ++- three_body_e2021/src/bin/repl/helper.rs | 45 +++++++++++++++++++ .../src/bin/{main.rs => repl/mod.rs} | 7 ++- 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 three_body_e2021/src/bin/repl/helper.rs rename three_body_e2021/src/bin/{main.rs => repl/mod.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index b3dd082..fa1ab7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,6 +1088,7 @@ version = "0.3.0" dependencies = [ "rand", "rustyline 12.0.0", + "rustyline-derive", "unicode-xid", ] diff --git a/three_body_e2021/Cargo.toml b/three_body_e2021/Cargo.toml index f946d49..7fb75b9 100644 --- a/three_body_e2021/Cargo.toml +++ b/three_body_e2021/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] rustyline = { version = "12.0.0", optional = true } +rustyline-derive = { version = "0.4.0", optional = true } unicode-xid = { version = "0.2.1" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -14,10 +15,10 @@ rand = { version = "0.7.3" } [[bin]] name = "3body" -path = "src/bin/main.rs" +path = "src/bin/repl/mod.rs" required-features = ["repl"] [features] default = ["repl"] -repl = ["rustyline"] +repl = ["rustyline", "rustyline-derive"] wasm = [] \ No newline at end of file diff --git a/three_body_e2021/src/bin/repl/helper.rs b/three_body_e2021/src/bin/repl/helper.rs new file mode 100644 index 0000000..0ae6fb4 --- /dev/null +++ b/three_body_e2021/src/bin/repl/helper.rs @@ -0,0 +1,45 @@ +#[cfg(feature = "repl")] +extern crate rustyline; +#[cfg(feature = "repl")] +extern crate rustyline_derive; + +use three_body_e2021::lexer::Lexer; +use three_body_e2021::parser::ParseError; +use three_body_e2021::parser::Parser; +use three_body_e2021::token::Token; + +#[derive(rustyline_derive::Helper, rustyline_derive::Hinter, rustyline_derive::Highlighter, rustyline_derive::Completer)] +pub struct Helper { +} + +impl Helper { + pub fn new() -> Self { + Self {} + } +} + +impl rustyline::validate::Validator for Helper { + fn validate( + &self, + ctx: &mut rustyline::validate::ValidationContext, + ) -> rustyline::Result { + let mut parser = Parser::new(Lexer::new(ctx.input())); + let _ = parser.parse(); + let errors = parser.get_errors(); + + Ok(match errors.len() { + 0 => rustyline::validate::ValidationResult::Valid(None), + _ => match &errors[0] { + ParseError::UnexpectedToken { + want: _, + got: Token::Eof, + } => rustyline::validate::ValidationResult::Incomplete, + x => rustyline::validate::ValidationResult::Invalid(Some(format!("{:?}???", x))), + }, + }) + } + + fn validate_while_typing(&self) -> bool { + false + } +} diff --git a/three_body_e2021/src/bin/main.rs b/three_body_e2021/src/bin/repl/mod.rs similarity index 95% rename from three_body_e2021/src/bin/main.rs rename to three_body_e2021/src/bin/repl/mod.rs index cbbd40b..1f5d058 100644 --- a/three_body_e2021/src/bin/main.rs +++ b/three_body_e2021/src/bin/repl/mod.rs @@ -1,6 +1,8 @@ #[cfg(feature = "repl")] extern crate rustyline; +pub mod helper; + use three_body_e2021::evaluator::builtins::new_builtins; use three_body_e2021::evaluator::env; use three_body_e2021::evaluator::Evaluator; @@ -10,8 +12,11 @@ use three_body_e2021::parser::Parser; use std::cell::RefCell; use std::rc::Rc; + fn main() { - let mut rl = rustyline::DefaultEditor::new().expect("should exist"); + let mut rl = rustyline::Editor::new().expect("should exist"); + + rl.set_helper(Some(helper::Helper::new())); let mut evaluator = Evaluator { env: Rc::new(RefCell::new(env::Env::from(new_builtins()))), From c7110e1e234dc1e2a6275f7e4f7c991f565a2f2b Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 12:37:16 +0800 Subject: [PATCH 02/11] + single quotation marks string token consume --- three_body_e2021/src/lexer/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/three_body_e2021/src/lexer/mod.rs b/three_body_e2021/src/lexer/mod.rs index 12420a3..0671345 100644 --- a/three_body_e2021/src/lexer/mod.rs +++ b/three_body_e2021/src/lexer/mod.rs @@ -107,6 +107,9 @@ impl Lexer { '"' => { return self.consume_string(); }, + '\'' => { + return self.consume_single_quotation_marks_string(); + }, '[' => Token::LBracket, ']' => Token::RBracket, '.' => Token::Dot, @@ -256,8 +259,24 @@ impl Lexer { self.walk_char(); } } + // infinity loop bug when let a = "3 } + fn consume_single_quotation_marks_string(&mut self) -> Token { + self.walk_char(); + let start_pos = self.pos; + + loop { + if self.ch == '\'' { + let end_pos = self.pos; + let literal = self.input[start_pos..end_pos].iter().collect::(); + self.walk_char(); + return Token::String(literal); + } else { + self.walk_char(); + } + } + } } #[cfg(test)] @@ -311,6 +330,7 @@ if (5 < 10) { 10 > 10; "foobar"; "foo bar"; +'foo bar'; [1, 2]; @@ -411,6 +431,8 @@ if (5 < 10) { Token::Semicolon, Token::String(String::from("foo bar")), Token::Semicolon, + Token::String(String::from("foo bar")), + Token::Semicolon, Token::Blank, Token::LBracket, Token::Int(1), From b52ef03be0751fea3896f1f63e2a257d6de9b0e3 Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 12:52:33 +0800 Subject: [PATCH 03/11] + brew ci --- .github/workflows/Brew.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/Brew.yml diff --git a/.github/workflows/Brew.yml b/.github/workflows/Brew.yml new file mode 100644 index 0000000..85cd49d --- /dev/null +++ b/.github/workflows/Brew.yml @@ -0,0 +1,29 @@ +on: + release: + types: [ released ] + +jobs: + homebrew: + name: Bump Homebrew formula + if: ${{ github.event_name != 'push' || !contains(github.ref, '-') }} + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Extract version + id: extract-version + run: | + echo "tag-name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - uses: mislav/bump-homebrew-formula-action@v3 + with: + formula-name: three-body + formula-path: Formula/t/three-body.rb + homebrew-tap: Homebrew/homebrew-core + base-branch: master + download-url: https://github.com/rustq/3body-lang/releases/download/${{ steps.extract-version.outputs.tag-name }}/3body-lang.tar.gz + commit-message: | + {{formulaName}} {{version}} + env: + COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 796a9e4df4ede5bfbdbbd097fe62046f8bb98844 Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 12:54:09 +0800 Subject: [PATCH 04/11] 0.3.1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- three_body_e2021/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa1ab7f..cd75579 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1084,7 +1084,7 @@ dependencies = [ [[package]] name = "three_body_e2021" -version = "0.3.0" +version = "0.3.1" dependencies = [ "rand", "rustyline 12.0.0", @@ -1094,7 +1094,7 @@ dependencies = [ [[package]] name = "three_body_lang" -version = "0.3.0" +version = "0.3.1" dependencies = [ "rand", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index afbc5fd..2884269 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ cargo-features = ["named-profiles"] [package] name = "three_body_lang" description = "Three Body Language written in Rust" -version = "0.3.0" +version = "0.3.1" authors = ["meloalright", "rustq"] license = "MIT" diff --git a/three_body_e2021/Cargo.toml b/three_body_e2021/Cargo.toml index 7fb75b9..2112b45 100644 --- a/three_body_e2021/Cargo.toml +++ b/three_body_e2021/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "three_body_e2021" -version = "0.3.0" +version = "0.3.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From c6452b3960387998e60a8e09c732f541d6122292 Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 12:57:58 +0800 Subject: [PATCH 05/11] Rename HomeBrew CI --- .github/workflows/{Brew.yml => HomeBrew.yml} | 2 ++ 1 file changed, 2 insertions(+) rename .github/workflows/{Brew.yml => HomeBrew.yml} (98%) diff --git a/.github/workflows/Brew.yml b/.github/workflows/HomeBrew.yml similarity index 98% rename from .github/workflows/Brew.yml rename to .github/workflows/HomeBrew.yml index 85cd49d..2d9d6d2 100644 --- a/.github/workflows/Brew.yml +++ b/.github/workflows/HomeBrew.yml @@ -1,3 +1,5 @@ +name: HomeBrew + on: release: types: [ released ] From 2881d5955ab7e046a7723f0adcc8692b48a1a667 Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 13:00:35 +0800 Subject: [PATCH 06/11] Update HomeBrew CI --- .github/workflows/HomeBrew.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/HomeBrew.yml b/.github/workflows/HomeBrew.yml index 2d9d6d2..9ca144e 100644 --- a/.github/workflows/HomeBrew.yml +++ b/.github/workflows/HomeBrew.yml @@ -28,4 +28,4 @@ jobs: {{formulaName}} {{version}} env: COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 5827821304c13b56c0eecca0c0c2bc5fc41748ac Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 13:13:02 +0800 Subject: [PATCH 07/11] Update HomeBrew CI again --- .github/workflows/HomeBrew.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/HomeBrew.yml b/.github/workflows/HomeBrew.yml index 9ca144e..378dcdb 100644 --- a/.github/workflows/HomeBrew.yml +++ b/.github/workflows/HomeBrew.yml @@ -26,6 +26,8 @@ jobs: download-url: https://github.com/rustq/3body-lang/releases/download/${{ steps.extract-version.outputs.tag-name }}/3body-lang.tar.gz commit-message: | {{formulaName}} {{version}} + + Created by https://github.com/mislav/bump-homebrew-formula-action env: COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 06619faf24fd0fa60bb8e9e1bfdfe1815a1deedd Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 13:16:13 +0800 Subject: [PATCH 08/11] Update Homebrew CI again --- .github/workflows/HomeBrew.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/HomeBrew.yml b/.github/workflows/HomeBrew.yml index 378dcdb..90a8894 100644 --- a/.github/workflows/HomeBrew.yml +++ b/.github/workflows/HomeBrew.yml @@ -1,4 +1,4 @@ -name: HomeBrew +name: Homebrew on: release: From 3ec4acf0c70ec7f14f0553aa98e5524ee6dfd3d3 Mon Sep 17 00:00:00 2001 From: MeloAlright Date: Sat, 28 Oct 2023 13:17:02 +0800 Subject: [PATCH 09/11] Rename HomeBrew.yml to Homebrew.yml --- .github/workflows/{HomeBrew.yml => Homebrew.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{HomeBrew.yml => Homebrew.yml} (95%) diff --git a/.github/workflows/HomeBrew.yml b/.github/workflows/Homebrew.yml similarity index 95% rename from .github/workflows/HomeBrew.yml rename to .github/workflows/Homebrew.yml index 90a8894..111a8cf 100644 --- a/.github/workflows/HomeBrew.yml +++ b/.github/workflows/Homebrew.yml @@ -30,4 +30,4 @@ jobs: Created by https://github.com/mislav/bump-homebrew-formula-action env: COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 5dd50aa52bc80c70d23acb1f38382a5302256684 Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 13:44:53 +0800 Subject: [PATCH 10/11] Update Homebrew CI again --- .github/workflows/Homebrew.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Homebrew.yml b/.github/workflows/Homebrew.yml index 111a8cf..c04b7e6 100644 --- a/.github/workflows/Homebrew.yml +++ b/.github/workflows/Homebrew.yml @@ -22,7 +22,7 @@ jobs: formula-name: three-body formula-path: Formula/t/three-body.rb homebrew-tap: Homebrew/homebrew-core - base-branch: master + base-branch: main download-url: https://github.com/rustq/3body-lang/releases/download/${{ steps.extract-version.outputs.tag-name }}/3body-lang.tar.gz commit-message: | {{formulaName}} {{version}} From 94665756a17ed073983d5096640813fcbf2b6b0e Mon Sep 17 00:00:00 2001 From: meloalright Date: Sat, 28 Oct 2023 14:12:01 +0800 Subject: [PATCH 11/11] Update Homebrew CI again --- .github/workflows/Homebrew.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Homebrew.yml b/.github/workflows/Homebrew.yml index c04b7e6..111a8cf 100644 --- a/.github/workflows/Homebrew.yml +++ b/.github/workflows/Homebrew.yml @@ -22,7 +22,7 @@ jobs: formula-name: three-body formula-path: Formula/t/three-body.rb homebrew-tap: Homebrew/homebrew-core - base-branch: main + base-branch: master download-url: https://github.com/rustq/3body-lang/releases/download/${{ steps.extract-version.outputs.tag-name }}/3body-lang.tar.gz commit-message: | {{formulaName}} {{version}}