Fix no_module builds.

This commit is contained in:
Stephen Chung 2021-10-29 17:01:29 +08:00
parent a5ae002cb7
commit dc2e824ce2
5 changed files with 14 additions and 6 deletions

View File

@ -717,6 +717,7 @@ impl AST {
///
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[allow(dead_code)]
#[inline]
pub(crate) fn iter_fn_def(&self) -> impl Iterator<Item = &ScriptFnDef> {
self.functions

View File

@ -262,6 +262,7 @@ pub const KEYWORD_IS_DEF_VAR: &str = "is_def_var";
pub const KEYWORD_IS_DEF_FN: &str = "is_def_fn";
pub const KEYWORD_THIS: &str = "this";
#[cfg(not(feature = "no_function"))]
#[cfg(not(feature = "no_module"))]
pub const KEYWORD_GLOBAL: &str = "global";
#[cfg(not(feature = "no_object"))]
pub const FN_GET: &str = "get$";
@ -1178,10 +1179,11 @@ impl Engine {
Expr::Variable(Some(_), _, _) => {
self.search_scope_only(scope, mods, state, lib, this_ptr, expr)
}
Expr::Variable(None, var_pos, v) => match v.as_ref() {
Expr::Variable(None, _var_pos, v) => match v.as_ref() {
// Normal variable access
(_, None, _) => self.search_scope_only(scope, mods, state, lib, this_ptr, expr),
// Qualified variable access
#[cfg(not(feature = "no_module"))]
(_, Some((namespace, hash_var)), var_name) => {
if let Some(module) = self.search_imports(mods, state, namespace) {
// foo:bar::baz::VARIABLE
@ -1190,7 +1192,7 @@ impl Engine {
let mut target = target.clone();
// Module variables are constant
target.set_access_mode(AccessMode::ReadOnly);
Ok((target.into(), *var_pos))
Ok((target.into(), *_var_pos))
}
Err(mut err) => {
match *err {
@ -1204,7 +1206,7 @@ impl Engine {
}
_ => (),
}
Err(err.fill_position(*var_pos))
Err(err.fill_position(*_var_pos))
}
}
} else if namespace.len() == 1 && namespace[0].name == KEYWORD_GLOBAL {
@ -1213,7 +1215,7 @@ impl Engine {
let mut target: Target = value.clone().into();
// Module variables are constant
target.set_access_mode(AccessMode::ReadOnly);
Ok((target.into(), *var_pos))
Ok((target.into(), *_var_pos))
} else {
Err(EvalAltResult::ErrorVariableNotFound(
format!(
@ -1234,6 +1236,8 @@ impl Engine {
.into())
}
}
#[cfg(feature = "no_module")]
(_, Some((_, _)), _) => unreachable!("no_module is active"),
},
_ => unreachable!("Expr::Variable expected, but gets {:?}", expr),
}

View File

@ -9,7 +9,7 @@ use crate::parse::IdentifierBuilder;
use crate::token::Token;
use crate::{
calc_fn_params_hash, calc_qualified_fn_hash, combine_hashes, Dynamic, EvalAltResult,
Identifier, ImmutableString, NativeCallContext, Position, Shared, StaticVec,
Identifier, ImmutableString, NativeCallContext, Shared, StaticVec,
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@ -455,10 +455,11 @@ impl Module {
/// Get a reference to a namespace-qualified variable.
/// Name and Position in [`EvalAltResult`] are [`None`] and [`NONE`][Position::NONE] and must be set afterwards.
#[cfg(not(feature = "no_module"))]
#[inline]
pub(crate) fn get_qualified_var(&self, hash_var: u64) -> Result<&Dynamic, Box<EvalAltResult>> {
self.all_variables.get(&hash_var).ok_or_else(|| {
EvalAltResult::ErrorVariableNotFound(String::new(), Position::NONE).into()
EvalAltResult::ErrorVariableNotFound(String::new(), crate::Position::NONE).into()
})
}

View File

@ -1379,6 +1379,7 @@ fn parse_primary(
parse_fn_call(input, state, lib, name, false, ns, settings.level_up())?
}
// module access
#[cfg(not(feature = "no_module"))]
(Expr::Variable(_, var_pos, x), Token::DoubleColon) => {
let (id2, pos2) = parse_var_name(input)?;
let (_, mut namespace, var_name) = *x;

View File

@ -1829,6 +1829,7 @@ fn get_next_token_inner(
}
('=', _) => return Some((Token::Equals, start_pos)),
#[cfg(not(feature = "no_module"))]
(':', ':') => {
eat_next(stream, pos);