From da9fc260b5c13f497b4db1f18378bf50c8d2b37b Mon Sep 17 00:00:00 2001 From: stratact <stratact1@gmail.com> Date: Sat, 23 Mar 2019 20:48:41 +0000 Subject: [PATCH] Support string concat and concat-head operations --- examples/string_ops.ion | 18 ++++++++++++++++++ examples/string_ops.out | 8 ++++++++ src/lib/shell/mod.rs | 15 ++++++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 examples/string_ops.ion create mode 100644 examples/string_ops.out diff --git a/examples/string_ops.ion b/examples/string_ops.ion new file mode 100644 index 00000000..fe405966 --- /dev/null +++ b/examples/string_ops.ion @@ -0,0 +1,18 @@ +let string = world +echo $string +let string ++= ! +echo $string +let string ::= "Hello, " +echo $string + +let string1 = Doctor +let string2 = order +echo $string1 +echo $string2 +let string1 ++= "'s" +let string2 ++= "s" +echo $string1 +echo $string2 +let string1 ++= " " +let string2 ::= $string1 +echo $string2 diff --git a/examples/string_ops.out b/examples/string_ops.out new file mode 100644 index 00000000..a926417d --- /dev/null +++ b/examples/string_ops.out @@ -0,0 +1,8 @@ +world +world! +Hello, world! +Doctor +order +Doctor's +orders +Doctor's orders diff --git a/src/lib/shell/mod.rs b/src/lib/shell/mod.rs index 4de5cd4e..59e1f0bf 100644 --- a/src/lib/shell/mod.rs +++ b/src/lib/shell/mod.rs @@ -474,9 +474,18 @@ impl Shell { match lhs { Value::Str(lhs) => { if let Value::Str(rhs) = rhs { - let action = math(&key.kind, operator, &rhs).map_err(|why| why.to_string())?; - let value = parse(&lhs, &*action).map_err(|why| why.to_string())?; - *lhs = value.into(); + match operator { + Operator::Concatenate => lhs.push_str(&rhs), + Operator::ConcatenateHead => { + *lhs = rhs + lhs; + } + _ => { + let action = + math(&key.kind, operator, &rhs).map_err(|why| why.to_string())?; + let value = parse(&lhs, &*action).map_err(|why| why.to_string())?; + *lhs = value.into(); + } + } } Ok(()) } -- GitLab