Merge branch 'master' into plugins_dev

This commit is contained in:
Stephen Chung
2020-08-22 22:51:41 +08:00
6 changed files with 116 additions and 5 deletions

View File

@@ -1645,11 +1645,22 @@ fn parse_primary(
}
Expr::Variable(Box::new(((s, settings.pos), None, 0, None)))
}
// Module qualification
#[cfg(not(feature = "no_module"))]
Token::Identifier(s) if *next_token == Token::DoubleColon => {
// Once the identifier consumed we must enable next variables capturing
#[cfg(not(feature = "no_closure"))]
{
state.allow_capture = true;
}
Expr::Variable(Box::new(((s, settings.pos), None, 0, None)))
}
// Normal variable access
Token::Identifier(s) => {
let index = state.access_var(&s, settings.pos);
Expr::Variable(Box::new(((s, settings.pos), None, 0, index)))
}
// Function call is allowed to have reserved keyword
Token::Reserved(s) if *next_token == Token::LeftParen || *next_token == Token::Bang => {
if is_keyword_function(&s) {
@@ -1658,6 +1669,7 @@ fn parse_primary(
return Err(PERR::Reserved(s).into_err(settings.pos));
}
}
// Access to `this` as a variable is OK
Token::Reserved(s) if s == KEYWORD_THIS && *next_token != Token::LeftParen => {
if !settings.is_function_scope {
@@ -1669,9 +1681,11 @@ fn parse_primary(
Expr::Variable(Box::new(((s, settings.pos), None, 0, None)))
}
}
Token::Reserved(s) if is_valid_identifier(s.chars()) => {
return Err(PERR::Reserved(s).into_err(settings.pos));
}
Token::LeftParen => parse_paren_expr(input, state, lib, settings.level_up())?,
#[cfg(not(feature = "no_index"))]
Token::LeftBracket => parse_array_literal(input, state, lib, settings.level_up())?,
@@ -1680,6 +1694,7 @@ fn parse_primary(
Token::True => Expr::True(settings.pos),
Token::False => Expr::False(settings.pos),
Token::LexError(err) => return Err(err.into_err(settings.pos)),
_ => {
return Err(
PERR::BadInput(format!("Unexpected '{}'", token.syntax())).into_err(settings.pos)
@@ -1862,7 +1877,7 @@ fn parse_unary(
}
// | ...
#[cfg(not(feature = "no_function"))]
Token::Pipe | Token::Or => {
Token::Pipe | Token::Or if settings.allow_anonymous_fn => {
let mut new_state = ParseState::new(
state.engine,
#[cfg(not(feature = "unchecked"))]
@@ -3353,6 +3368,8 @@ impl Engine {
};
let expr = parse_expr(input, &mut state, &mut functions, settings)?;
assert!(functions.is_empty());
match input.peek().unwrap() {
(Token::EOF, _) => (),
// Return error if the expression doesn't end