Use variable interpolation for println!.
This commit is contained in:
parent
6b24cc151e
commit
3c2e031883
@ -38,7 +38,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
engine
|
engine
|
||||||
.gen_fn_signatures(false)
|
.gen_fn_signatures(false)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|func| println!("{}", func));
|
.for_each(|func| println!("{func}"));
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
",
|
",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("{:?}", result);
|
println!("{result:?}");
|
||||||
|
|
||||||
let result = engine.eval::<TestStruct>(
|
let result = engine.eval::<TestStruct>(
|
||||||
"
|
"
|
||||||
@ -61,7 +61,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
",
|
",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("{:?}", result);
|
println!("{result:?}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
let r2 = func(1, 2);
|
let r2 = func(1, 2);
|
||||||
let r3 = func(1, 2);
|
let r3 = func(1, 2);
|
||||||
|
|
||||||
println!("The Answers: {}, {}, {}", r1, r2, r3); // prints 40, 42, 44
|
println!("The Answers: {r1}, {r2}, {r3}"); // prints 40, 42, 44
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
engine
|
engine
|
||||||
.gen_fn_signatures(false)
|
.gen_fn_signatures(false)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|func| println!("{}", func));
|
.for_each(|func| println!("{func}"));
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
",
|
",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("result: {}", result); // prints 1085764
|
println!("result: {result}"); // prints 1085764
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
engine
|
engine
|
||||||
.gen_fn_signatures(false)
|
.gen_fn_signatures(false)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|func| println!("{}", func));
|
.for_each(|func| println!("{func}"));
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
",
|
",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("result: {}", result); // prints 1085764
|
println!("result: {result}"); // prints 1085764
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ pub fn main() {
|
|||||||
scope.push_constant("MY_CONSTANT", 42_i64);
|
scope.push_constant("MY_CONSTANT", 42_i64);
|
||||||
|
|
||||||
// Compile the handler script.
|
// Compile the handler script.
|
||||||
println!("> Loading script file: {}", path);
|
println!("> Loading script file: {path}");
|
||||||
|
|
||||||
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
||||||
Ok(ast) => ast,
|
Ok(ast) => ast,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("! Error: {}", err);
|
eprintln!("! Error: {err}");
|
||||||
println!("Cannot continue. Bye!");
|
println!("Cannot continue. Bye!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ pub fn main() {
|
|||||||
let result = engine.call_fn_raw(&mut scope, &ast, false, true, "init", Some(&mut states), []);
|
let result = engine.call_fn_raw(&mut scope, &ast, false, true, "init", Some(&mut states), []);
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
eprintln!("! {}", err)
|
eprintln!("! {err}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create handler instance
|
// Create handler instance
|
||||||
@ -152,7 +152,7 @@ pub fn main() {
|
|||||||
engine.call_fn_raw(scope, ast, false, true, event, this_ptr, [arg.into()]);
|
engine.call_fn_raw(scope, ast, false, true, event, this_ptr, [arg.into()]);
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
eprintln!("! {}", err)
|
eprintln!("! {err}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ pub fn main() {
|
|||||||
scope.push_constant("MY_CONSTANT", 42_i64);
|
scope.push_constant("MY_CONSTANT", 42_i64);
|
||||||
|
|
||||||
// Compile the handler script.
|
// Compile the handler script.
|
||||||
println!("> Loading script file: {}", path);
|
println!("> Loading script file: {path}");
|
||||||
|
|
||||||
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
||||||
Ok(ast) => ast,
|
Ok(ast) => ast,
|
||||||
@ -89,7 +89,7 @@ pub fn main() {
|
|||||||
let result = engine.call_fn_raw(&mut scope, &ast, false, false, "init", None, []);
|
let result = engine.call_fn_raw(&mut scope, &ast, false, false, "init", None, []);
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
eprintln!("! {}", err)
|
eprintln!("! {err}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create handler instance
|
// Create handler instance
|
||||||
@ -127,7 +127,7 @@ pub fn main() {
|
|||||||
let result = engine.call_fn::<()>(scope, ast, event, (arg.to_string(),));
|
let result = engine.call_fn::<()>(scope, ast, event, (arg.to_string(),));
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
eprintln!("! {}", err)
|
eprintln!("! {err}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,12 +81,12 @@ pub fn main() {
|
|||||||
scope.push("state", states);
|
scope.push("state", states);
|
||||||
|
|
||||||
// Compile the handler script.
|
// Compile the handler script.
|
||||||
println!("> Loading script file: {}", path);
|
println!("> Loading script file: {path}");
|
||||||
|
|
||||||
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
let ast = match engine.compile_file_with_scope(&mut scope, path.into()) {
|
||||||
Ok(ast) => ast,
|
Ok(ast) => ast,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("! Error: {}", err);
|
eprintln!("! Error: {err}");
|
||||||
println!("Cannot continue. Bye!");
|
println!("Cannot continue. Bye!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ pub fn main() {
|
|||||||
let result = engine.call_fn::<()>(&mut scope, &ast, "init", ());
|
let result = engine.call_fn::<()>(&mut scope, &ast, "init", ());
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
eprintln!("! {}", err)
|
eprintln!("! {err}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create handler instance
|
// Create handler instance
|
||||||
@ -141,7 +141,7 @@ pub fn main() {
|
|||||||
let result = engine.call_fn::<()>(scope, ast, event, (arg.to_string(),));
|
let result = engine.call_fn::<()>(scope, ast, event, (arg.to_string(),));
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
eprintln!("! {}", err)
|
eprintln!("! {err}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
let result = engine.eval::<i64>("40 + 2")?;
|
let result = engine.eval::<i64>("40 + 2")?;
|
||||||
|
|
||||||
println!("The Answer: {}", result); // prints 42
|
println!("The Answer: {result}"); // prints 42
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let result = engine.eval_with_scope::<i64>(&mut scope, "x += 1; x")?;
|
let result = engine.eval_with_scope::<i64>(&mut scope, "x += 1; x")?;
|
||||||
|
|
||||||
println!("result: {}", result);
|
println!("result: {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("x = {}", scope.get_value::<i64>("x").unwrap());
|
println!("x = {}", scope.get_value::<i64>("x").unwrap());
|
||||||
|
@ -36,13 +36,13 @@ fn main() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Source struct: {:#?}", x);
|
println!("Source struct: {x:#?}");
|
||||||
|
|
||||||
// Convert the 'MyStruct' into a 'Dynamic'
|
// Convert the 'MyStruct' into a 'Dynamic'
|
||||||
let map: Dynamic = to_dynamic(x).unwrap();
|
let map: Dynamic = to_dynamic(x).unwrap();
|
||||||
|
|
||||||
assert!(map.is::<Map>());
|
assert!(map.is::<Map>());
|
||||||
println!("Serialized to Dynamic: {:#?}", map);
|
println!("Serialized to Dynamic: {map:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn de() {
|
pub fn de() {
|
||||||
@ -60,7 +60,7 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("Source Dynamic: {:#?}", result);
|
println!("Source Dynamic: {result:#?}");
|
||||||
|
|
||||||
// Convert the 'Dynamic' object map into 'MyStruct'
|
// Convert the 'Dynamic' object map into 'MyStruct'
|
||||||
let x: MyStruct = from_dynamic(&result).unwrap();
|
let x: MyStruct = from_dynamic(&result).unwrap();
|
||||||
@ -77,7 +77,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
println!("Deserialized to struct: {:#?}", x);
|
println!("Deserialized to struct: {x:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ser();
|
ser();
|
||||||
|
@ -13,7 +13,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
let result = engine.eval::<i64>("add(40, 2)")?;
|
let result = engine.eval::<i64>("add(40, 2)")?;
|
||||||
|
|
||||||
println!("Answer: {}", result); // prints 42
|
println!("Answer: {result}"); // prints 42
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,10 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
.register_fn("index_of", find_substring)
|
.register_fn("index_of", find_substring)
|
||||||
// Register string functions using closures
|
// Register string functions using closures
|
||||||
.register_fn("display", |label: &str, value: i64| {
|
.register_fn("display", |label: &str, value: i64| {
|
||||||
println!("{}: {}", label, value)
|
println!("{label}: {value}")
|
||||||
})
|
})
|
||||||
.register_fn("display", |label: ImmutableString, value: &str| {
|
.register_fn("display", |label: ImmutableString, value: &str| {
|
||||||
println!(r#"{}: "{}""#, label, value) // Quote the input string
|
println!(r#"{label}: "{value}""#) // Quote the input string
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
|
@ -60,7 +60,7 @@ fn main() {
|
|||||||
let mut value: i64 = 0;
|
let mut value: i64 = 0;
|
||||||
|
|
||||||
while value < 10 {
|
while value < 10 {
|
||||||
println!("Value: {}", value);
|
println!("Value: {value}");
|
||||||
// Send value to script
|
// Send value to script
|
||||||
tx_master.send(value).unwrap();
|
tx_master.send(value).unwrap();
|
||||||
// Receive value from script
|
// Receive value from script
|
||||||
|
@ -465,13 +465,13 @@ impl fmt::Debug for Expr {
|
|||||||
let mut display_pos = format!(" @ {:?}", self.start_position());
|
let mut display_pos = format!(" @ {:?}", self.start_position());
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Self::DynamicConstant(value, ..) => write!(f, "{:?}", value),
|
Self::DynamicConstant(value, ..) => write!(f, "{value:?}"),
|
||||||
Self::BoolConstant(value, ..) => write!(f, "{:?}", value),
|
Self::BoolConstant(value, ..) => write!(f, "{value:?}"),
|
||||||
Self::IntegerConstant(value, ..) => write!(f, "{:?}", value),
|
Self::IntegerConstant(value, ..) => write!(f, "{value:?}"),
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
Self::FloatConstant(value, ..) => write!(f, "{:?}", value),
|
Self::FloatConstant(value, ..) => write!(f, "{value:?}"),
|
||||||
Self::CharConstant(value, ..) => write!(f, "{:?}", value),
|
Self::CharConstant(value, ..) => write!(f, "{value:?}"),
|
||||||
Self::StringConstant(value, ..) => write!(f, "{:?}", value),
|
Self::StringConstant(value, ..) => write!(f, "{value:?}"),
|
||||||
Self::Unit(..) => f.write_str("()"),
|
Self::Unit(..) => f.write_str("()"),
|
||||||
|
|
||||||
Self::InterpolatedString(x, ..) => {
|
Self::InterpolatedString(x, ..) => {
|
||||||
@ -502,10 +502,10 @@ impl fmt::Debug for Expr {
|
|||||||
f.write_str(&x.3)?;
|
f.write_str(&x.3)?;
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
if let Some(n) = x.1.index() {
|
if let Some(n) = x.1.index() {
|
||||||
write!(f, " #{}", n)?;
|
write!(f, " #{n}")?;
|
||||||
}
|
}
|
||||||
if let Some(n) = i.map_or_else(|| x.0, |n| NonZeroUsize::new(n.get() as usize)) {
|
if let Some(n) = i.map_or_else(|| x.0, |n| NonZeroUsize::new(n.get() as usize)) {
|
||||||
write!(f, " #{}", n)?;
|
write!(f, " #{n}")?;
|
||||||
}
|
}
|
||||||
f.write_str(")")
|
f.write_str(")")
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ impl fmt::Debug for Namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(index) = self.index {
|
if let Some(index) = self.index {
|
||||||
write!(f, "{} -> ", index)?;
|
write!(f, "{index} -> ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
f.write_str(
|
f.write_str(
|
||||||
|
@ -185,8 +185,8 @@ impl fmt::Debug for RangeCase {
|
|||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::ExclusiveInt(r, n) => write!(f, "{}..{} => {}", r.start, r.end, n),
|
Self::ExclusiveInt(r, n) => write!(f, "{}..{} => {n}", r.start, r.end),
|
||||||
Self::InclusiveInt(r, n) => write!(f, "{}..={} => {}", *r.start(), *r.end(), n),
|
Self::InclusiveInt(r, n) => write!(f, "{}..={} => {n}", *r.start(), *r.end()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ fn print_current_source(
|
|||||||
}
|
}
|
||||||
if !src.is_empty() {
|
if !src.is_empty() {
|
||||||
// Print just a line number for imported modules
|
// Print just a line number for imported modules
|
||||||
println!("{} @ {:?}", src, pos);
|
println!("{src} @ {pos:?}");
|
||||||
} else {
|
} else {
|
||||||
// Print the current source line
|
// Print the current source line
|
||||||
print_source(lines, pos, 0, window);
|
print_source(lines, pos, 0, window);
|
||||||
@ -100,17 +100,16 @@ fn print_error(input: &str, mut err: EvalAltResult) {
|
|||||||
// Print error position
|
// Print error position
|
||||||
if pos.is_none() {
|
if pos.is_none() {
|
||||||
// No position
|
// No position
|
||||||
println!("{}", err);
|
println!("{err}");
|
||||||
} else {
|
} else {
|
||||||
// Specific position - print line text
|
// Specific position - print line text
|
||||||
println!("{}{}", line_no, lines[pos.line().unwrap() - 1]);
|
println!("{line_no}{}", lines[pos.line().unwrap() - 1]);
|
||||||
|
|
||||||
// Display position marker
|
// Display position marker
|
||||||
println!(
|
println!(
|
||||||
"{0:>1$} {2}",
|
"{0:>1$} {err}",
|
||||||
"^",
|
"^",
|
||||||
line_no.len() + pos.position().unwrap(),
|
line_no.len() + pos.position().unwrap(),
|
||||||
err
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,11 +246,11 @@ fn debug_callback(
|
|||||||
BreakPoint::AtPosition { .. } => (),
|
BreakPoint::AtPosition { .. } => (),
|
||||||
BreakPoint::AtFunctionName { ref name, .. }
|
BreakPoint::AtFunctionName { ref name, .. }
|
||||||
| BreakPoint::AtFunctionCall { ref name, .. } => {
|
| BreakPoint::AtFunctionCall { ref name, .. } => {
|
||||||
println!("! Call to function {}.", name)
|
println!("! Call to function {name}.")
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
BreakPoint::AtProperty { ref name, .. } => {
|
BreakPoint::AtProperty { ref name, .. } => {
|
||||||
println!("! Property {} accessed.", name)
|
println!("! Property {name} accessed.")
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
@ -311,8 +310,8 @@ fn debug_callback(
|
|||||||
println!("{:?}", node);
|
println!("{:?}", node);
|
||||||
} else {
|
} else {
|
||||||
match source {
|
match source {
|
||||||
Some(source) => println!("{:?} {} @ {:?}", node, source, pos),
|
Some(source) => println!("{node:?} {source} @ {pos:?}"),
|
||||||
None => println!("{:?} @ {:?}", node, pos),
|
None => println!("{node:?} @ {pos:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
@ -327,7 +326,7 @@ fn debug_callback(
|
|||||||
["list" | "l", n] if n.parse::<usize>().is_ok() => {
|
["list" | "l", n] if n.parse::<usize>().is_ok() => {
|
||||||
let num = n.parse::<usize>().unwrap();
|
let num = n.parse::<usize>().unwrap();
|
||||||
if num == 0 || num > lines.len() {
|
if num == 0 || num > lines.len() {
|
||||||
eprintln!("\x1b[31mInvalid line: {}\x1b[39m", num);
|
eprintln!("\x1b[31mInvalid line: {num}\x1b[39m");
|
||||||
} else {
|
} else {
|
||||||
let pos = Position::new(num as u16, 0);
|
let pos = Position::new(num as u16, 0);
|
||||||
print_current_source(&mut context, source, pos, lines, (3, 6));
|
print_current_source(&mut context, source, pos, lines, (3, 6));
|
||||||
@ -340,17 +339,17 @@ fn debug_callback(
|
|||||||
["next" | "n"] => break Ok(DebuggerCommand::Next),
|
["next" | "n"] => break Ok(DebuggerCommand::Next),
|
||||||
["scope"] => println!("{}", context.scope()),
|
["scope"] => println!("{}", context.scope()),
|
||||||
["print" | "p", "this"] => match context.this_ptr() {
|
["print" | "p", "this"] => match context.this_ptr() {
|
||||||
Some(value) => println!("=> {:?}", value),
|
Some(value) => println!("=> {value:?}"),
|
||||||
None => println!("`this` pointer is unbound."),
|
None => println!("`this` pointer is unbound."),
|
||||||
},
|
},
|
||||||
["print" | "p", var_name] => match context.scope().get_value::<Dynamic>(var_name) {
|
["print" | "p", var_name] => match context.scope().get_value::<Dynamic>(var_name) {
|
||||||
Some(value) => println!("=> {:?}", value),
|
Some(value) => println!("=> {value:?}"),
|
||||||
None => eprintln!("Variable not found: {}", var_name),
|
None => eprintln!("Variable not found: {var_name}"),
|
||||||
},
|
},
|
||||||
["print" | "p"] => {
|
["print" | "p"] => {
|
||||||
println!("{}", context.scope().clone_visible());
|
println!("{}", context.scope().clone_visible());
|
||||||
if let Some(value) = context.this_ptr() {
|
if let Some(value) = context.this_ptr() {
|
||||||
println!("this = {:?}", value);
|
println!("this = {value:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
@ -379,7 +378,7 @@ fn debug_callback(
|
|||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
{
|
{
|
||||||
println!("{}", frame)
|
println!("{frame}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
["info" | "i", "break" | "b"] => Iterator::for_each(
|
["info" | "i", "break" | "b"] => Iterator::for_each(
|
||||||
@ -396,7 +395,7 @@ fn debug_callback(
|
|||||||
print!("{}", line_num);
|
print!("{}", line_num);
|
||||||
print_source(lines, *pos, line_num.len(), (0, 0));
|
print_source(lines, *pos, line_num.len(), (0, 0));
|
||||||
}
|
}
|
||||||
_ => println!("[{}] {}", i + 1, bp),
|
_ => println!("[{}] {bp}", i + 1),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
["enable" | "en", n] => {
|
["enable" | "en", n] => {
|
||||||
@ -414,12 +413,12 @@ fn debug_callback(
|
|||||||
.get_mut(n - 1)
|
.get_mut(n - 1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.enable(true);
|
.enable(true);
|
||||||
println!("Break-point #{} enabled.", n)
|
println!("Break-point #{n} enabled.")
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid break-point: {}\x1b[39m", n);
|
eprintln!("\x1b[31mInvalid break-point: {n}\x1b[39m");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid break-point: '{}'\x1b[39m", n);
|
eprintln!("\x1b[31mInvalid break-point: '{n}'\x1b[39m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
["disable" | "dis", n] => {
|
["disable" | "dis", n] => {
|
||||||
@ -437,12 +436,12 @@ fn debug_callback(
|
|||||||
.get_mut(n - 1)
|
.get_mut(n - 1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.enable(false);
|
.enable(false);
|
||||||
println!("Break-point #{} disabled.", n)
|
println!("Break-point #{n} disabled.")
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid break-point: {}\x1b[39m", n);
|
eprintln!("\x1b[31mInvalid break-point: {n}\x1b[39m");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid break-point: '{}'\x1b[39m", n);
|
eprintln!("\x1b[31mInvalid break-point: '{n}'\x1b[39m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
["delete" | "d", n] => {
|
["delete" | "d", n] => {
|
||||||
@ -458,12 +457,12 @@ fn debug_callback(
|
|||||||
.debugger
|
.debugger
|
||||||
.break_points_mut()
|
.break_points_mut()
|
||||||
.remove(n - 1);
|
.remove(n - 1);
|
||||||
println!("Break-point #{} deleted.", n)
|
println!("Break-point #{n} deleted.")
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid break-point: {}\x1b[39m", n);
|
eprintln!("\x1b[31mInvalid break-point: {n}\x1b[39m");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid break-point: '{}'\x1b[39m", n);
|
eprintln!("\x1b[31mInvalid break-point: '{n}'\x1b[39m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
["delete" | "d"] => {
|
["delete" | "d"] => {
|
||||||
@ -481,14 +480,14 @@ fn debug_callback(
|
|||||||
args,
|
args,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
};
|
};
|
||||||
println!("Break-point added for {}", bp);
|
println!("Break-point added for {bp}");
|
||||||
context
|
context
|
||||||
.global_runtime_state_mut()
|
.global_runtime_state_mut()
|
||||||
.debugger
|
.debugger
|
||||||
.break_points_mut()
|
.break_points_mut()
|
||||||
.push(bp);
|
.push(bp);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid number of arguments: '{}'\x1b[39m", args);
|
eprintln!("\x1b[31mInvalid number of arguments: '{args}'\x1b[39m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Property name
|
// Property name
|
||||||
@ -498,7 +497,7 @@ fn debug_callback(
|
|||||||
name: param[1..].into(),
|
name: param[1..].into(),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
};
|
};
|
||||||
println!("Break-point added for {}", bp);
|
println!("Break-point added for {bp}");
|
||||||
context
|
context
|
||||||
.global_runtime_state_mut()
|
.global_runtime_state_mut()
|
||||||
.debugger
|
.debugger
|
||||||
@ -521,14 +520,14 @@ fn debug_callback(
|
|||||||
pos: Position::new(n as u16, 0),
|
pos: Position::new(n as u16, 0),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
};
|
};
|
||||||
println!("Break-point added {}", bp);
|
println!("Break-point added {bp}");
|
||||||
context
|
context
|
||||||
.global_runtime_state_mut()
|
.global_runtime_state_mut()
|
||||||
.debugger
|
.debugger
|
||||||
.break_points_mut()
|
.break_points_mut()
|
||||||
.push(bp);
|
.push(bp);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\x1b[31mInvalid line number: '{}'\x1b[39m", n);
|
eprintln!("\x1b[31mInvalid line number: '{n}'\x1b[39m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Function name parameter
|
// Function name parameter
|
||||||
@ -537,7 +536,7 @@ fn debug_callback(
|
|||||||
name: param.trim().into(),
|
name: param.trim().into(),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
};
|
};
|
||||||
println!("Break-point added for {}", bp);
|
println!("Break-point added for {bp}");
|
||||||
context
|
context
|
||||||
.global_runtime_state_mut()
|
.global_runtime_state_mut()
|
||||||
.debugger
|
.debugger
|
||||||
@ -551,7 +550,7 @@ fn debug_callback(
|
|||||||
pos,
|
pos,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
};
|
};
|
||||||
println!("Break-point added {}", bp);
|
println!("Break-point added {bp}");
|
||||||
context
|
context
|
||||||
.global_runtime_state_mut()
|
.global_runtime_state_mut()
|
||||||
.debugger
|
.debugger
|
||||||
@ -588,7 +587,7 @@ fn debug_callback(
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let title = format!("Rhai Debugger (version {})", env!("CARGO_PKG_VERSION"));
|
let title = format!("Rhai Debugger (version {})", env!("CARGO_PKG_VERSION"));
|
||||||
println!("{}", title);
|
println!("{title}");
|
||||||
println!("{0:=<1$}", "", title.len());
|
println!("{0:=<1$}", "", title.len());
|
||||||
|
|
||||||
// Initialize scripting engine
|
// Initialize scripting engine
|
||||||
|
@ -26,17 +26,16 @@ fn print_error(input: &str, mut err: EvalAltResult) {
|
|||||||
// Print error position
|
// Print error position
|
||||||
if pos.is_none() {
|
if pos.is_none() {
|
||||||
// No position
|
// No position
|
||||||
println!("{}", err);
|
println!("{err}");
|
||||||
} else {
|
} else {
|
||||||
// Specific position - print line text
|
// Specific position - print line text
|
||||||
println!("{}{}", line_no, lines[pos.line().unwrap() - 1]);
|
println!("{line_no}{}", lines[pos.line().unwrap() - 1]);
|
||||||
|
|
||||||
// Display position marker
|
// Display position marker
|
||||||
println!(
|
println!(
|
||||||
"{0:>1$} {2}",
|
"{0:>1$} {err}",
|
||||||
"^",
|
"^",
|
||||||
line_no.len() + pos.position().unwrap(),
|
line_no.len() + pos.position().unwrap(),
|
||||||
err
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +118,7 @@ fn load_script_files(engine: &mut Engine) {
|
|||||||
for filename in env::args().skip(1) {
|
for filename in env::args().skip(1) {
|
||||||
let filename = match Path::new(&filename).canonicalize() {
|
let filename = match Path::new(&filename).canonicalize() {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error script file path: {}\n{}", filename, err);
|
eprintln!("Error script file path: {filename}\n{err}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
@ -164,7 +163,7 @@ fn load_script_files(engine: &mut Engine) {
|
|||||||
let filename = filename.to_string_lossy();
|
let filename = filename.to_string_lossy();
|
||||||
|
|
||||||
eprintln!("{:=<1$}", "", filename.len());
|
eprintln!("{:=<1$}", "", filename.len());
|
||||||
eprintln!("{}", filename);
|
eprintln!("{filename}");
|
||||||
eprintln!("{:=<1$}", "", filename.len());
|
eprintln!("{:=<1$}", "", filename.len());
|
||||||
eprintln!();
|
eprintln!();
|
||||||
|
|
||||||
@ -277,13 +276,13 @@ mod sample_functions {
|
|||||||
#[rhai_fn(name = "test")]
|
#[rhai_fn(name = "test")]
|
||||||
pub fn test2(x: &mut INT, y: INT, z: &str) {
|
pub fn test2(x: &mut INT, y: INT, z: &str) {
|
||||||
*x += y + (z.len() as INT);
|
*x += y + (z.len() as INT);
|
||||||
println!("{} {} {}", x, y, z);
|
println!("{x} {y} {z}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let title = format!("Rhai REPL tool (version {})", env!("CARGO_PKG_VERSION"));
|
let title = format!("Rhai REPL tool (version {})", env!("CARGO_PKG_VERSION"));
|
||||||
println!("{}", title);
|
println!("{title}");
|
||||||
println!("{0:=<1$}", "", title.len());
|
println!("{0:=<1$}", "", title.len());
|
||||||
|
|
||||||
#[cfg(not(feature = "no_optimize"))]
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
@ -338,11 +337,11 @@ fn main() {
|
|||||||
history_offset += 1;
|
history_offset += 1;
|
||||||
}
|
}
|
||||||
if input.contains('\n') {
|
if input.contains('\n') {
|
||||||
println!("[{}] ~~~~", replacement_index);
|
println!("[{replacement_index}] ~~~~");
|
||||||
println!("{}", input);
|
println!("{input}");
|
||||||
println!("~~~~");
|
println!("~~~~");
|
||||||
} else {
|
} else {
|
||||||
println!("[{}] {}", replacement_index, input);
|
println!("[{replacement_index}] {input}");
|
||||||
}
|
}
|
||||||
replacement_index = 0;
|
replacement_index = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -374,7 +373,7 @@ fn main() {
|
|||||||
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => break 'main_loop,
|
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => break 'main_loop,
|
||||||
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {err:?}");
|
||||||
break 'main_loop;
|
break 'main_loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -401,12 +400,12 @@ fn main() {
|
|||||||
"history" => {
|
"history" => {
|
||||||
for (i, h) in rl.history().iter().enumerate() {
|
for (i, h) in rl.history().iter().enumerate() {
|
||||||
match &h.split('\n').collect::<Vec<_>>()[..] {
|
match &h.split('\n').collect::<Vec<_>>()[..] {
|
||||||
[line] => println!("[{}] {}", history_offset + i, line),
|
[line] => println!("[{}] {line}", history_offset + i),
|
||||||
lines => {
|
lines => {
|
||||||
for (x, line) in lines.iter().enumerate() {
|
for (x, line) in lines.iter().enumerate() {
|
||||||
let number = format!("[{}]", history_offset + i);
|
let number = format!("[{}]", history_offset + i);
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
println!("{} {}", number, line.trim_end());
|
println!("{number} {}", line.trim_end());
|
||||||
} else {
|
} else {
|
||||||
println!("{0:>1$} {2}", "", number.len(), line.trim_end());
|
println!("{0:>1$} {2}", "", number.len(), line.trim_end());
|
||||||
}
|
}
|
||||||
@ -439,30 +438,30 @@ fn main() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
"scope" => {
|
"scope" => {
|
||||||
println!("{}", scope);
|
println!("{scope}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_optimize"))]
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
"astu" => {
|
"astu" => {
|
||||||
// print the last un-optimized AST
|
// print the last un-optimized AST
|
||||||
println!("{:#?}\n", ast_u);
|
println!("{ast_u:#?}\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
"ast" => {
|
"ast" => {
|
||||||
// print the last AST
|
// print the last AST
|
||||||
println!("{:#?}\n", ast);
|
println!("{ast:#?}\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
"functions" => {
|
"functions" => {
|
||||||
// print a list of all registered functions
|
// print a list of all registered functions
|
||||||
for f in engine.gen_fn_signatures(false) {
|
for f in engine.gen_fn_signatures(false) {
|
||||||
println!("{}", f)
|
println!("{f}")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
for f in main_ast.iter_functions() {
|
for f in main_ast.iter_functions() {
|
||||||
println!("{}", f)
|
println!("{f}")
|
||||||
}
|
}
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
@ -505,7 +504,7 @@ fn main() {
|
|||||||
replacement = Some(line.clone());
|
replacement = Some(line.clone());
|
||||||
replacement_index = history_offset + (rl.history().len() - 1 - n);
|
replacement_index = history_offset + (rl.history().len() - 1 - n);
|
||||||
}
|
}
|
||||||
None => eprintln!("History line not found: {}", text),
|
None => eprintln!("History line not found: {text}"),
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -561,7 +560,7 @@ fn main() {
|
|||||||
engine.eval_ast_with_scope::<Dynamic>(&mut scope, &main_ast)
|
engine.eval_ast_with_scope::<Dynamic>(&mut scope, &main_ast)
|
||||||
}) {
|
}) {
|
||||||
Ok(result) if !result.is::<()>() => {
|
Ok(result) if !result.is::<()>() => {
|
||||||
println!("=> {:?}", result);
|
println!("=> {result:?}");
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
|
@ -7,12 +7,11 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
|
|||||||
let line = pos.line().unwrap();
|
let line = pos.line().unwrap();
|
||||||
let line_no = format!("{line}: ");
|
let line_no = format!("{line}: ");
|
||||||
|
|
||||||
eprintln!("{}{}", line_no, lines[line - 1]);
|
eprintln!("{line_no}{}", lines[line - 1]);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{:>1$} {2}",
|
"{:>1$} {err_msg}",
|
||||||
"^",
|
"^",
|
||||||
line_no.len() + pos.position().unwrap(),
|
line_no.len() + pos.position().unwrap(),
|
||||||
err_msg
|
|
||||||
);
|
);
|
||||||
eprintln!();
|
eprintln!();
|
||||||
}
|
}
|
||||||
@ -24,7 +23,7 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
|
|||||||
|
|
||||||
if pos.is_none() {
|
if pos.is_none() {
|
||||||
// No position
|
// No position
|
||||||
eprintln!("{}", err);
|
eprintln!("{err}");
|
||||||
} else {
|
} else {
|
||||||
// Specific position
|
// Specific position
|
||||||
eprint_line(&lines, pos, &err.to_string())
|
eprint_line(&lines, pos, &err.to_string())
|
||||||
@ -37,7 +36,7 @@ fn main() {
|
|||||||
for filename in env::args().skip(1) {
|
for filename in env::args().skip(1) {
|
||||||
let filename = match Path::new(&filename).canonicalize() {
|
let filename = match Path::new(&filename).canonicalize() {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error script file path: {}\n{}", filename, err);
|
eprintln!("Error script file path: {filename}\n{err}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Ok(f) => match f.strip_prefix(std::env::current_dir().unwrap().canonicalize().unwrap())
|
Ok(f) => match f.strip_prefix(std::env::current_dir().unwrap().canonicalize().unwrap())
|
||||||
@ -94,7 +93,7 @@ fn main() {
|
|||||||
let filename = filename.to_string_lossy();
|
let filename = filename.to_string_lossy();
|
||||||
|
|
||||||
eprintln!("{:=<1$}", "", filename.len());
|
eprintln!("{:=<1$}", "", filename.len());
|
||||||
eprintln!("{}", filename);
|
eprintln!("{filename}");
|
||||||
eprintln!("{:=<1$}", "", filename.len());
|
eprintln!("{:=<1$}", "", filename.len());
|
||||||
eprintln!();
|
eprintln!();
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ pub const OP_INCLUSIVE_RANGE: &str = Token::InclusiveRange.literal_syntax();
|
|||||||
///
|
///
|
||||||
/// let result = engine.eval::<i64>("40 + 2")?;
|
/// let result = engine.eval::<i64>("40 + 2")?;
|
||||||
///
|
///
|
||||||
/// println!("Answer: {}", result); // prints 42
|
/// println!("Answer: {result}"); // prints 42
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
@ -236,18 +236,12 @@ impl Engine {
|
|||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
{
|
{
|
||||||
engine.print = Box::new(|s| println!("{}", s));
|
engine.print = Box::new(|s| println!("{s}"));
|
||||||
engine.debug = Box::new(|s, source, pos| {
|
engine.debug = Box::new(|s, source, pos| match (source, pos) {
|
||||||
source.map_or_else(
|
(Some(source), crate::Position::NONE) => println!("{source} | {s}"),
|
||||||
|| {
|
(Some(source), pos) => println!("{source} @ {pos:?} | {s}"),
|
||||||
if pos.is_none() {
|
(None, crate::Position::NONE) => println!("{s}"),
|
||||||
println!("{s}");
|
(None, pos) => println!("{pos:?} | {s}"),
|
||||||
} else {
|
|
||||||
println!("{pos:?} | {s}");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|source| println!("{source} @ {pos:?} | {s}"),
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,35 +148,30 @@ impl fmt::Display for BreakPoint {
|
|||||||
pos,
|
pos,
|
||||||
enabled,
|
enabled,
|
||||||
} => {
|
} => {
|
||||||
if source.is_empty() {
|
if !source.is_empty() {
|
||||||
write!(f, "@ {:?}", pos)?;
|
write!(f, "{source} ")?;
|
||||||
} else {
|
|
||||||
write!(f, "{} @ {:?}", source, pos)?;
|
|
||||||
}
|
}
|
||||||
|
write!(f, "@ {pos:?}")?;
|
||||||
if !*enabled {
|
if !*enabled {
|
||||||
f.write_str(" (disabled)")?;
|
f.write_str(" (disabled)")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Self::AtFunctionName {
|
Self::AtFunctionName { name, enabled } => {
|
||||||
name: fn_name,
|
write!(f, "{name} (...)")?;
|
||||||
enabled,
|
|
||||||
} => {
|
|
||||||
write!(f, "{} (...)", fn_name)?;
|
|
||||||
if !*enabled {
|
if !*enabled {
|
||||||
f.write_str(" (disabled)")?;
|
f.write_str(" (disabled)")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Self::AtFunctionCall {
|
Self::AtFunctionCall {
|
||||||
name: fn_name,
|
name,
|
||||||
args,
|
args,
|
||||||
enabled,
|
enabled,
|
||||||
} => {
|
} => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{} ({})",
|
"{name} ({})",
|
||||||
fn_name,
|
|
||||||
repeat("_").take(*args).collect::<Vec<_>>().join(", ")
|
repeat("_").take(*args).collect::<Vec<_>>().join(", ")
|
||||||
)?;
|
)?;
|
||||||
if !*enabled {
|
if !*enabled {
|
||||||
@ -185,11 +180,8 @@ impl fmt::Display for BreakPoint {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
Self::AtProperty {
|
Self::AtProperty { name, enabled } => {
|
||||||
name: prop,
|
write!(f, ".{name}")?;
|
||||||
enabled,
|
|
||||||
} => {
|
|
||||||
write!(f, ".{}", prop)?;
|
|
||||||
if !*enabled {
|
if !*enabled {
|
||||||
f.write_str(" (disabled)")?;
|
f.write_str(" (disabled)")?;
|
||||||
}
|
}
|
||||||
@ -251,11 +243,10 @@ impl fmt::Display for CallStackFrame {
|
|||||||
fp.finish()?;
|
fp.finish()?;
|
||||||
|
|
||||||
if !self.pos.is_none() {
|
if !self.pos.is_none() {
|
||||||
if self.source.is_empty() {
|
if !self.source.is_empty() {
|
||||||
write!(f, " @ {:?}", self.pos)?;
|
write!(f, ": {}", self.source)?;
|
||||||
} else {
|
|
||||||
write!(f, ": {} @ {:?}", self.source, self.pos)?;
|
|
||||||
}
|
}
|
||||||
|
write!(f, " @ {:?}", self.pos)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -31,10 +31,10 @@ impl fmt::Debug for CallableFunction {
|
|||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(..) => write!(f, "NativePureFunction"),
|
Self::Pure(..) => f.write_str("NativePureFunction"),
|
||||||
Self::Method(..) => write!(f, "NativeMethod"),
|
Self::Method(..) => f.write_str("NativeMethod"),
|
||||||
Self::Iterator(..) => write!(f, "NativeIterator"),
|
Self::Iterator(..) => f.write_str("NativeIterator"),
|
||||||
Self::Plugin(..) => write!(f, "PluginFunction"),
|
Self::Plugin(..) => f.write_str("PluginFunction"),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(fn_def) => fmt::Debug::fmt(fn_def, f),
|
Self::Script(fn_def) => fmt::Debug::fmt(fn_def, f),
|
||||||
@ -45,10 +45,10 @@ impl fmt::Debug for CallableFunction {
|
|||||||
impl fmt::Display for CallableFunction {
|
impl fmt::Display for CallableFunction {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(..) => write!(f, "NativePureFunction"),
|
Self::Pure(..) => f.write_str("NativePureFunction"),
|
||||||
Self::Method(..) => write!(f, "NativeMethod"),
|
Self::Method(..) => f.write_str("NativeMethod"),
|
||||||
Self::Iterator(..) => write!(f, "NativeIterator"),
|
Self::Iterator(..) => f.write_str("NativeIterator"),
|
||||||
Self::Plugin(..) => write!(f, "PluginFunction"),
|
Self::Plugin(..) => f.write_str("PluginFunction"),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(s) => fmt::Display::fmt(s, f),
|
Self::Script(s) => fmt::Display::fmt(s, f),
|
||||||
|
@ -416,7 +416,7 @@ impl Hash for Dynamic {
|
|||||||
impl fmt::Display for Dynamic {
|
impl fmt::Display for Dynamic {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
Union::Unit(..) => write!(f, ""),
|
Union::Unit(..) => Ok(()),
|
||||||
Union::Bool(ref v, ..) => fmt::Display::fmt(v, f),
|
Union::Bool(ref v, ..) => fmt::Display::fmt(v, f),
|
||||||
Union::Str(ref v, ..) => fmt::Display::fmt(v, f),
|
Union::Str(ref v, ..) => fmt::Display::fmt(v, f),
|
||||||
Union::Char(ref v, ..) => fmt::Display::fmt(v, f),
|
Union::Char(ref v, ..) => fmt::Display::fmt(v, f),
|
||||||
@ -527,7 +527,7 @@ impl fmt::Debug for Dynamic {
|
|||||||
if i > 0 && i % 8 == 0 {
|
if i > 0 && i % 8 == 0 {
|
||||||
f.write_str(" ")?;
|
f.write_str(" ")?;
|
||||||
}
|
}
|
||||||
write!(f, "{:02x}", v)
|
write!(f, "{v:02x}")
|
||||||
})?;
|
})?;
|
||||||
f.write_str("]")
|
f.write_str("]")
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,11 @@ impl Error for LexError {}
|
|||||||
impl fmt::Display for LexError {
|
impl fmt::Display for LexError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::UnexpectedInput(s) => write!(f, "Unexpected '{}'", s),
|
Self::UnexpectedInput(s) => write!(f, "Unexpected '{s}'"),
|
||||||
Self::MalformedEscapeSequence(s) => write!(f, "Invalid escape sequence: '{}'", s),
|
Self::MalformedEscapeSequence(s) => write!(f, "Invalid escape sequence: '{s}'"),
|
||||||
Self::MalformedNumber(s) => write!(f, "Invalid number: '{}'", s),
|
Self::MalformedNumber(s) => write!(f, "Invalid number: '{s}'"),
|
||||||
Self::MalformedChar(s) => write!(f, "Invalid character: '{}'", s),
|
Self::MalformedChar(s) => write!(f, "Invalid character: '{s}'"),
|
||||||
Self::MalformedIdentifier(s) => write!(f, "Variable name is not proper: '{}'", s),
|
Self::MalformedIdentifier(s) => write!(f, "Variable name is not proper: '{s}'"),
|
||||||
Self::UnterminatedString => f.write_str("Open string is not terminated"),
|
Self::UnterminatedString => f.write_str("Open string is not terminated"),
|
||||||
Self::StringTooLong(max) => write!(
|
Self::StringTooLong(max) => write!(
|
||||||
f,
|
f,
|
||||||
@ -50,7 +50,7 @@ impl fmt::Display for LexError {
|
|||||||
max
|
max
|
||||||
),
|
),
|
||||||
Self::ImproperSymbol(s, d) if d.is_empty() => {
|
Self::ImproperSymbol(s, d) if d.is_empty() => {
|
||||||
write!(f, "Invalid symbol encountered: '{}'", s)
|
write!(f, "Invalid symbol encountered: '{s}'")
|
||||||
}
|
}
|
||||||
Self::ImproperSymbol(.., d) => f.write_str(d),
|
Self::ImproperSymbol(.., d) => f.write_str(d),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user