Remove CallExpression support (#6639)

Users MUST use keyword call syntax now.

Closes https://github.com/KittyCAD/modeling-app/issues/4600
This commit is contained in:
Adam Chalmers
2025-05-02 16:08:12 -05:00
committed by GitHub
parent 75916d4300
commit 4fe8741ea7
309 changed files with 51419 additions and 66399 deletions

View File

@ -14,7 +14,7 @@ use winnow::{
};
use super::{
ast::types::{AscribedExpression, CallExpression, ImportPath, LabelledExpression},
ast::types::{AscribedExpression, ImportPath, LabelledExpression},
token::{NumericSuffix, RESERVED_WORDS},
DeprecationKind,
};
@ -630,7 +630,6 @@ fn operand(i: &mut TokenSlice) -> PResult<BinaryPart> {
Expr::Literal(x) => BinaryPart::Literal(x),
Expr::Name(x) => BinaryPart::Name(x),
Expr::BinaryExpression(x) => BinaryPart::BinaryExpression(x),
Expr::CallExpression(x) => BinaryPart::CallExpression(x),
Expr::CallExpressionKw(x) => BinaryPart::CallExpressionKw(x),
Expr::MemberExpression(x) => BinaryPart::MemberExpression(x),
Expr::IfExpression(x) => BinaryPart::IfExpression(x),
@ -2030,7 +2029,6 @@ fn expr_allowed_in_pipe_expr(i: &mut TokenSlice) -> PResult<Expr> {
bool_value.map(Expr::Literal),
tag.map(Box::new).map(Expr::TagDeclarator),
literal.map(Expr::Literal),
fn_call.map(Box::new).map(Expr::CallExpression),
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
name.map(Box::new).map(Expr::Name),
array,
@ -2050,7 +2048,6 @@ fn possible_operands(i: &mut TokenSlice) -> PResult<Expr> {
bool_value.map(Expr::Literal),
member_expression.map(Box::new).map(Expr::MemberExpression),
literal.map(Expr::Literal),
fn_call.map(Box::new).map(Expr::CallExpression),
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
name.map(Box::new).map(Expr::Name),
binary_expr_in_parens.map(Box::new).map(Expr::BinaryExpression),
@ -2711,13 +2708,6 @@ fn pipe_sep(i: &mut TokenSlice) -> PResult<()> {
Ok(())
}
/// Arguments are passed into a function.
fn arguments(i: &mut TokenSlice) -> PResult<Vec<Expr>> {
separated(0.., expression, comma_sep)
.context(expected("function arguments"))
.parse_next(i)
}
fn labeled_argument(i: &mut TokenSlice) -> PResult<LabeledArg> {
separated_pair(
terminated(nameable_identifier, opt(whitespace)),
@ -2986,11 +2976,7 @@ fn binding_name(i: &mut TokenSlice) -> PResult<Node<Identifier>> {
/// Either a positional or keyword function call.
fn fn_call_pos_or_kw(i: &mut TokenSlice) -> PResult<Expr> {
alt((
fn_call.map(Box::new).map(Expr::CallExpression),
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
))
.parse_next(i)
alt((fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),)).parse_next(i)
}
fn labelled_fn_call(i: &mut TokenSlice) -> PResult<Expr> {
@ -3003,43 +2989,6 @@ fn labelled_fn_call(i: &mut TokenSlice) -> PResult<Expr> {
}
}
fn fn_call(i: &mut TokenSlice) -> PResult<Node<CallExpression>> {
let fn_name = name(i)?;
opt(whitespace).parse_next(i)?;
let _ = terminated(open_paren, opt(whitespace)).parse_next(i)?;
let args = arguments(i)?;
let end = preceded(opt(whitespace), close_paren).parse_next(i)?.end;
let result = Node::new_node(
fn_name.start,
end,
fn_name.module_id,
CallExpression {
callee: fn_name,
arguments: args,
digest: None,
},
);
let callee_str = result.callee.name.name.to_string();
if let Some(suggestion) = super::deprecation(&callee_str, DeprecationKind::Function) {
ParseContext::warn(
CompilationError::err(
result.as_source_range(),
format!("Calling `{}` is deprecated, prefer using `{}`.", callee_str, suggestion),
)
.with_suggestion(
format!("Replace `{}` with `{}`", callee_str, suggestion),
suggestion,
None,
Tag::Deprecated,
),
);
}
Ok(result)
}
fn fn_call_kw(i: &mut TokenSlice) -> PResult<Node<CallExpressionKw>> {
let fn_name = name(i)?;
opt(whitespace).parse_next(i)?;
@ -3231,18 +3180,6 @@ mod tests {
assert_reserved("import");
}
#[test]
fn parse_args() {
for (i, (test, expected_len)) in [("someVar", 1), ("5, 3", 2), (r#""a""#, 1)].into_iter().enumerate() {
let tokens = crate::parsing::token::lex(test, ModuleId::default()).unwrap();
let actual = match arguments.parse(tokens.as_slice()) {
Ok(x) => x,
Err(e) => panic!("Failed test {i}, could not parse function arguments from \"{test}\": {e:?}"),
};
assert_eq!(actual.len(), expected_len, "failed test {i}");
}
}
#[test]
fn parse_names() {
for (test, expected_len) in [("someVar", 0), ("::foo", 0), ("foo::bar::baz", 2)] {