From f55f9e0512b0de1b760f11dc722d1c3975587942 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 22 Feb 2022 22:39:03 +0100 Subject: [PATCH 1/2] Changed string delimiters You know what could be cursed? Using Rust's block comment syntax as String delimiters! --- ablescript/src/lexer.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ablescript/src/lexer.rs b/ablescript/src/lexer.rs index 729a016..2029bf1 100644 --- a/ablescript/src/lexer.rs +++ b/ablescript/src/lexer.rs @@ -122,7 +122,7 @@ pub enum Token { Abool(Abool), /// String - #[regex("\"(\\.|[^\"])*\"", get_string)] + #[regex("/\\*(\\.|[^\\*/])*\\*/", get_string)] String(String), /// Integer @@ -149,7 +149,11 @@ fn get_value(lexer: &mut Lexer) -> Option { } fn get_string(lexer: &mut Lexer) -> String { - lexer.slice().trim_matches('"').to_owned() + lexer + .slice() + .trim_start_matches("/*") + .trim_end_matches("*/") + .to_owned() } fn get_abool(lexer: &mut Lexer) -> Option { From cb6fcceb7987067aff69b063ed25f01f24b4b5da Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 22 Feb 2022 22:49:56 +0100 Subject: [PATCH 2/2] Fixed tests and examples --- able-script-test/by-arity-chain.able | 28 ++++++++++++------------- able-script-test/carts.able | 6 +++--- able-script-test/functio.able | 2 +- able-script-test/hello-world.able | 2 +- able-script-test/melo-hello.able | 2 +- able-script-test/pass-by-reference.able | 14 ++++++------- ablescript/src/interpret.rs | 4 ++-- ablescript/src/parser.rs | 12 +++++------ 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/able-script-test/by-arity-chain.able b/able-script-test/by-arity-chain.able index 2dca191..8e1665b 100644 --- a/able-script-test/by-arity-chain.able +++ b/able-script-test/by-arity-chain.able @@ -1,44 +1,44 @@ functio arity_0() { - "this function has arity 0" print; + /*this function has arity 0*/ print; } functio arity_1(arg1) { - "this function has arity 1" print; + /*this function has arity 1*/ print; arg1 print; } functio arity_2(arg1, arg2) { - "this function has arity 2" print; + /*this function has arity 2*/ print; arg1 print; arg2 print; } functio arity_3(arg1, arg2, arg3) { - "this function has arity 3" print; + /*this function has arity 3*/ print; arg1 print; arg2 print; arg3 print; } owo arity_0(); -owo arity_1("foo"); -owo arity_2("foo", "bar"); -owo arity_3("foo", "bar", "baz"); +owo arity_1(/*foo*/); +owo arity_2(/*foo*/, /*bar*/); +owo arity_3(/*foo*/, /*bar*/, /*baz*/); var i1 = arity_0 * arity_1; -i1("second"); +i1(/*second*/); -"----" print; +/*----*/ print; var i2 = arity_1 * arity_0; -i2("first"); +i2(/*first*/); -"----" print; +/*----*/ print; var ifancy = arity_3 * arity_3; -ifancy("left1", "right1", "left2", "right2", "left3", "right3"); +ifancy(/*left1*/, /*right1*/, /*left2*/, /*right2*/, /*left3*/, /*right3*/); -"----" print; +/*---*/" print; var another = arity_0 * arity_3; -another("right1", "right2", "right3"); +another(/*right1*/, /*right2*/, /*right3*/); diff --git a/able-script-test/carts.able b/able-script-test/carts.able index b12ef8d..94f102d 100644 --- a/able-script-test/carts.able +++ b/able-script-test/carts.able @@ -1,8 +1,8 @@ functio helloable() { - "Hello, Able!" print; + "ยด/*Hello, Able!*/ print; } -var cart = ["able" <= 42, helloable <= "hello"]; +var cart = [/*able*/ <= 42, helloable <= /*hello*/]; cart[42] print; -cart["hello"](); +cart[/*hello*/](); diff --git a/able-script-test/functio.able b/able-script-test/functio.able index b31584c..5f2635b 100644 --- a/able-script-test/functio.able +++ b/able-script-test/functio.able @@ -1,4 +1,4 @@ functio hello(words){ words print; } -hello("wonk"); +hello(/*wonk*/); diff --git a/able-script-test/hello-world.able b/able-script-test/hello-world.able index d32b8b8..cf2fc47 100644 --- a/able-script-test/hello-world.able +++ b/able-script-test/hello-world.able @@ -1,2 +1,2 @@ -var hello = "world"; +var hello = /*world*/; hello print; diff --git a/able-script-test/melo-hello.able b/able-script-test/melo-hello.able index e8fc7b9..2e6279d 100644 --- a/able-script-test/melo-hello.able +++ b/able-script-test/melo-hello.able @@ -1,3 +1,3 @@ -var hi = "wonk"; +var hi = /*wonk*/; melo hi; hi print; owo Should error out diff --git a/able-script-test/pass-by-reference.able b/able-script-test/pass-by-reference.able index 25c77a7..cf51edb 100644 --- a/able-script-test/pass-by-reference.able +++ b/able-script-test/pass-by-reference.able @@ -7,17 +7,17 @@ functio swap(left, right) { right = tmp; } -var foo = "hello"; -var bar = "world"; +var foo = /*hello*/; +var bar = /*world*/; swap(foo, bar); -if (foo != "world") { - "FAILED" print; - "foo should be 'world', is actually:" print; +if (foo != /*world*/) { + /*FAILED*/ print; + /*foo should be 'world', is actually:*/ print; foo print; } -if (foo == "world") { - "OK" print; +if (foo == /*world*/) { + /*OK*/ print; } diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index ba9191f..0d0b149 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -673,7 +673,7 @@ mod tests { span: 1..1 }) .unwrap(), - Value::Int(-2147483648) + Value::Int(-9223372036854775808) ); // And the same for divide by zero. @@ -728,7 +728,7 @@ mod tests { ); // Assigning an existing variable. - eval(&mut env, "foo = \"hi\";").unwrap(); + eval(&mut env, "foo = /*hi*/;").unwrap(); assert_eq!( env.get_var(&Ident { ident: "foo".to_owned(), diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index 7597e79..d9612f3 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -579,7 +579,7 @@ mod tests { #[test] fn simple_math() { - let code = r#"1 * (a + 3) / 666 print;"#; + let code = "1 * (a + 3) / 666 print;"; let expected = &[Stmt { kind: StmtKind::Print(Expr { kind: ExprKind::BinOp { @@ -624,7 +624,7 @@ mod tests { #[test] fn variable_declaration() { - let code = r#"var a = 42;"#; + let code = "var a = 42;"; let expected = &[Stmt { kind: StmtKind::Var { ident: Ident { @@ -645,7 +645,7 @@ mod tests { #[test] fn if_flow() { - let code = r#"if (a == always) { "Buy Able products!" print; }"#; + let code = "if (a == always) { /*Buy Able products!*/ print; }"; let expected = &[Stmt { kind: StmtKind::If { cond: Expr { @@ -681,7 +681,7 @@ mod tests { #[test] fn tdark() { - let code = r#"T-Dark { var lang = "lang" + lang; }"#; + let code = "T-Dark { var lang = /*lang*/ + lang; }"; let expected = &[Stmt { kind: StmtKind::Var { ident: Ident { @@ -712,7 +712,7 @@ mod tests { #[test] fn cart_construction() { - let code = r#"["able" <= 1, "script" <= 3 - 1] print;"#; + let code = "[/*able*/ <= 1, /*script*/ <= 3 - 1] print;"; let expected = &[Stmt { kind: StmtKind::Print(Expr { kind: ExprKind::Cart(vec![ @@ -758,7 +758,7 @@ mod tests { #[test] fn cart_index() { - let code = r#"["able" <= "ablecorp"]["ablecorp"] print;"#; + let code = "[/*able*/ <= /*ablecorp*/][/*ablecorp*/] print;"; let expected = &[Stmt { kind: StmtKind::Print(Expr { kind: ExprKind::Index {