Merge pull request 'You know what could be cursed? Using Rust's block comment syntax as String delimiters!' (#5) from change/string-delimiters into master

Reviewed-on: https://git.ablecorp.us:443/AbleScript/able-script/pulls/5
This commit is contained in:
able 2022-02-23 14:11:14 +00:00
commit 81f713a5e2
9 changed files with 41 additions and 37 deletions

View file

@ -1,44 +1,44 @@
functio arity_0() { functio arity_0() {
"this function has arity 0" print; /*this function has arity 0*/ print;
} }
functio arity_1(arg1) { functio arity_1(arg1) {
"this function has arity 1" print; /*this function has arity 1*/ print;
arg1 print; arg1 print;
} }
functio arity_2(arg1, arg2) { functio arity_2(arg1, arg2) {
"this function has arity 2" print; /*this function has arity 2*/ print;
arg1 print; arg1 print;
arg2 print; arg2 print;
} }
functio arity_3(arg1, arg2, arg3) { functio arity_3(arg1, arg2, arg3) {
"this function has arity 3" print; /*this function has arity 3*/ print;
arg1 print; arg1 print;
arg2 print; arg2 print;
arg3 print; arg3 print;
} }
owo arity_0(); owo arity_0();
owo arity_1("foo"); owo arity_1(/*foo*/);
owo arity_2("foo", "bar"); owo arity_2(/*foo*/, /*bar*/);
owo arity_3("foo", "bar", "baz"); owo arity_3(/*foo*/, /*bar*/, /*baz*/);
var i1 = arity_0 * arity_1; var i1 = arity_0 * arity_1;
i1("second"); i1(/*second*/);
"----" print; /*----*/ print;
var i2 = arity_1 * arity_0; var i2 = arity_1 * arity_0;
i2("first"); i2(/*first*/);
"----" print; /*----*/ print;
var ifancy = arity_3 * arity_3; 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; var another = arity_0 * arity_3;
another("right1", "right2", "right3"); another(/*right1*/, /*right2*/, /*right3*/);

View file

@ -1,8 +1,8 @@
functio helloable() { functio helloable() {
"Hello, Able!" print; "´/*Hello, Able!*/ print;
} }
var cart = ["able" <= 42, helloable <= "hello"]; var cart = [/*able*/ <= 42, helloable <= /*hello*/];
cart[42] print; cart[42] print;
cart["hello"](); cart[/*hello*/]();

View file

@ -1,4 +1,4 @@
functio hello(words){ functio hello(words){
words print; words print;
} }
hello("wonk"); hello(/*wonk*/);

View file

@ -1,2 +1,2 @@
var hello = "world"; var hello = /*world*/;
hello print; hello print;

View file

@ -1,3 +1,3 @@
var hi = "wonk"; var hi = /*wonk*/;
melo hi; melo hi;
hi print; owo Should error out hi print; owo Should error out

View file

@ -7,17 +7,17 @@ functio swap(left, right) {
right = tmp; right = tmp;
} }
var foo = "hello"; var foo = /*hello*/;
var bar = "world"; var bar = /*world*/;
swap(foo, bar); swap(foo, bar);
if (foo != "world") { if (foo != /*world*/) {
"FAILED" print; /*FAILED*/ print;
"foo should be 'world', is actually:" print; /*foo should be 'world', is actually:*/ print;
foo print; foo print;
} }
if (foo == "world") { if (foo == /*world*/) {
"OK" print; /*OK*/ print;
} }

View file

@ -673,7 +673,7 @@ mod tests {
span: 1..1 span: 1..1
}) })
.unwrap(), .unwrap(),
Value::Int(-2147483648) Value::Int(-9223372036854775808)
); );
// And the same for divide by zero. // And the same for divide by zero.
@ -728,7 +728,7 @@ mod tests {
); );
// Assigning an existing variable. // Assigning an existing variable.
eval(&mut env, "foo = \"hi\";").unwrap(); eval(&mut env, "foo = /*hi*/;").unwrap();
assert_eq!( assert_eq!(
env.get_var(&Ident { env.get_var(&Ident {
ident: "foo".to_owned(), ident: "foo".to_owned(),

View file

@ -122,7 +122,7 @@ pub enum Token {
Abool(Abool), Abool(Abool),
/// String /// String
#[regex("\"(\\.|[^\"])*\"", get_string)] #[regex("/\\*(\\.|[^\\*/])*\\*/", get_string)]
String(String), String(String),
/// Integer /// Integer
@ -149,7 +149,11 @@ fn get_value<T: std::str::FromStr>(lexer: &mut Lexer<Token>) -> Option<T> {
} }
fn get_string(lexer: &mut Lexer<Token>) -> String { fn get_string(lexer: &mut Lexer<Token>) -> String {
lexer.slice().trim_matches('"').to_owned() lexer
.slice()
.trim_start_matches("/*")
.trim_end_matches("*/")
.to_owned()
} }
fn get_abool(lexer: &mut Lexer<Token>) -> Option<Abool> { fn get_abool(lexer: &mut Lexer<Token>) -> Option<Abool> {

View file

@ -579,7 +579,7 @@ mod tests {
#[test] #[test]
fn simple_math() { fn simple_math() {
let code = r#"1 * (a + 3) / 666 print;"#; let code = "1 * (a + 3) / 666 print;";
let expected = &[Stmt { let expected = &[Stmt {
kind: StmtKind::Print(Expr { kind: StmtKind::Print(Expr {
kind: ExprKind::BinOp { kind: ExprKind::BinOp {
@ -624,7 +624,7 @@ mod tests {
#[test] #[test]
fn variable_declaration() { fn variable_declaration() {
let code = r#"var a = 42;"#; let code = "var a = 42;";
let expected = &[Stmt { let expected = &[Stmt {
kind: StmtKind::Var { kind: StmtKind::Var {
ident: Ident { ident: Ident {
@ -645,7 +645,7 @@ mod tests {
#[test] #[test]
fn if_flow() { 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 { let expected = &[Stmt {
kind: StmtKind::If { kind: StmtKind::If {
cond: Expr { cond: Expr {
@ -681,7 +681,7 @@ mod tests {
#[test] #[test]
fn tdark() { fn tdark() {
let code = r#"T-Dark { var lang = "lang" + lang; }"#; let code = "T-Dark { var lang = /*lang*/ + lang; }";
let expected = &[Stmt { let expected = &[Stmt {
kind: StmtKind::Var { kind: StmtKind::Var {
ident: Ident { ident: Ident {
@ -712,7 +712,7 @@ mod tests {
#[test] #[test]
fn cart_construction() { fn cart_construction() {
let code = r#"["able" <= 1, "script" <= 3 - 1] print;"#; let code = "[/*able*/ <= 1, /*script*/ <= 3 - 1] print;";
let expected = &[Stmt { let expected = &[Stmt {
kind: StmtKind::Print(Expr { kind: StmtKind::Print(Expr {
kind: ExprKind::Cart(vec![ kind: ExprKind::Cart(vec![
@ -758,7 +758,7 @@ mod tests {
#[test] #[test]
fn cart_index() { fn cart_index() {
let code = r#"["able" <= "ablecorp"]["ablecorp"] print;"#; let code = "[/*able*/ <= /*ablecorp*/][/*ablecorp*/] print;";
let expected = &[Stmt { let expected = &[Stmt {
kind: StmtKind::Print(Expr { kind: StmtKind::Print(Expr {
kind: ExprKind::Index { kind: ExprKind::Index {