diff --git a/Cargo.toml b/Cargo.toml index 5cf15e1e..68837a2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhai" -version = "0.13.0" +version = "0.14.1" edition = "2018" authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung"] description = "Embedded scripting for Rust" diff --git a/README.md b/README.md index e27bf079..cd95c92f 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Rhai's current features set: to do checked arithmetic operations); for [`no-std`](#optional-features) builds, a number of additional dependencies are pulled in to provide for functionalities that used to be in `std`. -**Note:** Currently, the version is 0.13.0, so the language and API's may change before they stabilize. +**Note:** Currently, the version is 0.14.1, so the language and API's may change before they stabilize. Installation ------------ @@ -39,7 +39,7 @@ Install the Rhai crate by adding this line to `dependencies`: ```toml [dependencies] -rhai = "0.13.0" +rhai = "0.14.1" ``` Use the latest released crate version on [`crates.io`](https::/crates.io/crates/rhai/): diff --git a/src/parser.rs b/src/parser.rs index 550feeb0..35b2d2e8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -221,11 +221,11 @@ impl Stack { }) .and_then(|(i, _)| NonZeroUsize::new(i + 1)) } - /// Find a sub-scope by name in the `Stack`, searching in reverse. + /// Find a module by name in the `Stack`, searching in reverse. /// The return value is the offset to be deducted from `Stack::len`, /// i.e. the top element of the `Stack` is offset 1. /// Return zero when the variable name is not found in the `Stack`. - pub fn find_sub_scope(&self, name: &str) -> Option { + pub fn find_module(&self, name: &str) -> Option { self.0 .iter() .rev() @@ -1115,7 +1115,7 @@ fn parse_primary<'a>( modules = Some(Box::new(vec)); let root = modules.as_ref().unwrap().iter().next().unwrap(); - index = stack.find_sub_scope(&root.0); + index = stack.find_module(&root.0); } Expr::Variable(Box::new(id2), modules, index, pos2) @@ -1831,12 +1831,23 @@ fn parse_let<'a>( ScopeEntryType::Constant => { Err(PERR::ForbiddenConstantExpr(name).into_err(init_value.position())) } - // Variable cannot be a sub-scope + // Variable cannot be a module ScopeEntryType::Module => unreachable!(), } } else { // let name - Ok(Stmt::Let(Box::new(name), None, pos)) + match var_type { + ScopeEntryType::Normal => { + stack.push((name.clone(), ScopeEntryType::Normal)); + Ok(Stmt::Let(Box::new(name), None, pos)) + } + ScopeEntryType::Constant => { + stack.push((name.clone(), ScopeEntryType::Constant)); + Ok(Stmt::Const(Box::new(name), Box::new(Expr::Unit(pos)), pos)) + } + // Variable cannot be a module + ScopeEntryType::Module => unreachable!(), + } } }