Refine what can be called in method style.

This commit is contained in:
Stephen Chung
2022-12-27 22:06:51 +08:00
parent 7c00b74916
commit bb1136e8ad
6 changed files with 81 additions and 77 deletions

View File

@@ -1657,7 +1657,7 @@ impl Engine {
match input.peek().expect(NEVER_ENDS).0 {
// Function call is allowed to have reserved keyword
Token::LeftParen | Token::Bang | Token::Unit if is_keyword_function(&s) => {
Token::LeftParen | Token::Bang | Token::Unit if is_keyword_function(&s).0 => {
Expr::Variable(
(None, ns, 0, state.get_interned_string(*s)).into(),
None,
@@ -1800,7 +1800,10 @@ impl Engine {
state.allow_capture = false;
}
}
(Token::Reserved(s), ..) if is_keyword_function(s) => (),
(Token::Reserved(s), ..) if is_keyword_function(s).1 => (),
(Token::Reserved(s), pos) => {
return Err(PERR::Reserved(s.to_string()).into_err(*pos))
}
(.., pos) => return Err(PERR::PropertyExpected.into_err(*pos)),
}
@@ -2109,9 +2112,7 @@ impl Engine {
}
// lhs.module::id - syntax error
#[cfg(not(feature = "no_module"))]
(.., Expr::Variable(x, ..)) if !x.1.is_empty() => {
Err(PERR::PropertyExpected.into_err(x.1.position()))
}
(.., Expr::Variable(x, ..)) if !x.1.is_empty() => unreachable!("lhs.ns::id"),
// lhs.id
(lhs, var_expr @ Expr::Variable(..)) => {
let rhs = var_expr.into_property(state);
@@ -2125,9 +2126,7 @@ impl Engine {
)),
// lhs.nnn::func(...) - syntax error
#[cfg(not(feature = "no_module"))]
(.., Expr::FnCall(f, ..)) if f.is_qualified() => {
Err(PERR::PropertyExpected.into_err(f.namespace.position()))
}
(.., Expr::FnCall(f, ..)) if f.is_qualified() => unreachable!("lhs.ns::func()"),
// lhs.Fn() or lhs.eval()
(.., Expr::FnCall(f, func_pos))
if f.args.is_empty()
@@ -2174,13 +2173,11 @@ impl Engine {
match x.lhs {
// lhs.module::id.dot_rhs or lhs.module::id[idx_rhs] - syntax error
#[cfg(not(feature = "no_module"))]
Expr::Variable(x, ..) if !x.1.is_empty() => {
Err(PERR::PropertyExpected.into_err(x.1.position()))
}
Expr::Variable(x, ..) if !x.1.is_empty() => unreachable!("lhs.ns::id..."),
// lhs.module::func().dot_rhs or lhs.module::func()[idx_rhs] - syntax error
#[cfg(not(feature = "no_module"))]
Expr::FnCall(f, ..) if f.is_qualified() => {
Err(PERR::PropertyExpected.into_err(f.namespace.position()))
unreachable!("lhs.ns::func()...")
}
// lhs.id.dot_rhs or lhs.id[idx_rhs]
Expr::Variable(..) | Expr::Property(..) => {