Fix builds.

This commit is contained in:
Stephen Chung 2021-04-04 15:06:13 +08:00
parent e6c878edf3
commit 20aaf1826a
7 changed files with 25 additions and 22 deletions

View File

@ -1,6 +1,8 @@
Rhai Release Notes Rhai Release Notes
================== ==================
This version adds string interpolation.
Version 0.19.16 Version 0.19.16
=============== ===============

View File

@ -140,6 +140,7 @@ fn main() {
// Set a file module resolver without caching // Set a file module resolver without caching
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "no_std"))]
{ {
let mut resolver = rhai::module_resolvers::FileModuleResolver::new(); let mut resolver = rhai::module_resolvers::FileModuleResolver::new();
resolver.enable_cache(false); resolver.enable_cache(false);

View File

@ -36,14 +36,6 @@ mod string_functions {
format!("{}{}", string, s).into() format!("{}{}", string, s).into()
} }
} }
#[rhai_fn(name = "+=")]
pub fn append(ctx: NativeCallContext, string: &mut ImmutableString, mut item: Dynamic) {
let s = print_with_func(FUNC_TO_STRING, &ctx, &mut item);
if !s.is_empty() {
string.make_mut().push_str(&s);
}
}
#[rhai_fn(name = "+", pure)] #[rhai_fn(name = "+", pure)]
pub fn add_prepend( pub fn add_prepend(
ctx: NativeCallContext, ctx: NativeCallContext,
@ -59,16 +51,13 @@ mod string_functions {
s.into() s.into()
} }
} }
#[rhai_fn(name = "+=")]
pub fn prepend(ctx: NativeCallContext, item: &mut Dynamic, string: &str) {
let mut s = print_with_func(FUNC_TO_STRING, &ctx, item);
if !string.is_empty() { #[rhai_fn(name = "+", name = "append")]
s.make_mut().push_str(string); pub fn add_append_str(string1: ImmutableString, string2: ImmutableString) -> ImmutableString {
} string1 + string2
} }
#[rhai_fn(name = "+")] #[rhai_fn(name = "+", name = "append")]
pub fn add_append_unit(string: ImmutableString, _item: ()) -> ImmutableString { pub fn add_append_unit(string: ImmutableString, _item: ()) -> ImmutableString {
string string
} }
@ -76,8 +65,6 @@ mod string_functions {
pub fn add_prepend_unit(_item: (), string: ImmutableString) -> ImmutableString { pub fn add_prepend_unit(_item: (), string: ImmutableString) -> ImmutableString {
string string
} }
#[rhai_fn(name = "+=")]
pub fn add_append_assign_unit(_string: &mut ImmutableString, _item: ()) {}
#[rhai_fn(name = "len", get = "len")] #[rhai_fn(name = "len", get = "len")]
pub fn len(string: &str) -> INT { pub fn len(string: &str) -> INT {

View File

@ -1056,7 +1056,6 @@ fn parse_primary(
} }
} }
println!("Interpolated string: {:?}", segments);
Expr::InterpolatedString(Box::new(segments)) Expr::InterpolatedString(Box::new(segments))
} }

View File

@ -1,7 +1,5 @@
//! Main module defining the lexer and parser. //! Main module defining the lexer and parser.
use std::iter::FusedIterator;
use crate::engine::{ use crate::engine::{
Precedence, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, Precedence, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL,
KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF, KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF,
@ -10,7 +8,7 @@ use crate::stdlib::{
borrow::Cow, borrow::Cow,
cell::Cell, cell::Cell,
char, fmt, format, char, fmt, format,
iter::Peekable, iter::{FusedIterator, Peekable},
num::NonZeroUsize, num::NonZeroUsize,
ops::{Add, AddAssign}, ops::{Add, AddAssign},
str::{Chars, FromStr}, str::{Chars, FromStr},

View File

@ -367,5 +367,21 @@ fn test_string_interpolated() -> Result<(), Box<EvalAltResult>> {
"hello 42 worlds!" "hello 42 worlds!"
); );
assert_eq!(
engine.eval::<String>(
r#"
let x = 42;
let y = 123;
`
Undeniable logic:
1) Hello, ${let w = `${x} world`; if x > 1 { w += "s" } w}!
2) If ${y} > ${x} then it is ${y > x}!
`
"#
)?,
"Undeniable logic:\n1) Hello, 42 worlds!\n2) If 123 > 42 then it is true!\n",
);
Ok(()) Ok(())
} }