diff --git a/examples/string_ops.ion b/examples/string_ops.ion new file mode 100644 index 0000000000000000000000000000000000000000..fe4059669b72dac55189d234a5931b7bd1e45f63 --- /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 0000000000000000000000000000000000000000..a926417dccf90ffe54c72d8fd3e8cdd2b65e8b26 --- /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 4de5cd4e8d393b499652258f903d1438033a93cb..59e1f0bf1211bb98901c966b3d4f01dea2a38d7e 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(()) }