Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Dec 17, 2024
1 parent 692088e commit 1f6427d
Show file tree
Hide file tree
Showing 8 changed files with 740 additions and 694 deletions.
14 changes: 12 additions & 2 deletions src/wasm-lib/kcl/src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2462,9 +2462,17 @@ fn typecheck(spec_arg: &crate::docs::StdLibFnArg, arg: &&Expr) -> PResult<()> {
Ok(())
}

/// 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)
}

fn labelled_fn_call(i: &mut TokenSlice) -> PResult<Expr> {
let call = fn_call.parse_next(i)?;
let expr = Expr::CallExpression(Box::new(call));
let expr = fn_call_pos_or_kw.parse_next(i)?;

let label = opt(label).parse_next(i)?;
match label {
Expand Down Expand Up @@ -4267,6 +4275,7 @@ mod snapshot_tests {
#[test]
fn $func_name() {
let module_id = crate::ModuleId::default();
println!("{}", $test_kcl_program);
let tokens = crate::parsing::token::lex($test_kcl_program, module_id).unwrap();
print_tokens(tokens.as_slice());
ParseContext::init();
Expand Down Expand Up @@ -4482,6 +4491,7 @@ my14 = 4 ^ 2 - 3 ^ 2 * 2
kw_function_decl_with_default_and_type,
r#"fn foo(x?: number = 2) { return 1 }"#
);
snapshot_test!(kw_function_to_draw_square, r#"val = 1 |> f(arg = x)"#);
}

#[allow(unused)]
Expand Down
4 changes: 0 additions & 4 deletions src/wasm-lib/kcl/src/std/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,6 @@ impl Args {
FromArgs::from_args(self, 0)
}

pub(crate) fn get_sketch_and_optional_tag(&self) -> Result<(Sketch, Option<TagNode>), KclError> {
FromArgs::from_args(self, 0)
}

pub(crate) fn get_data_and_optional_tag<'a, T>(&'a self) -> Result<(T, Option<FaceTag>), KclError>
where
T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized,
Expand Down
15 changes: 11 additions & 4 deletions src/wasm-lib/kcl/src/std/extrude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ use crate::{

/// Extrudes by a given amount.
pub async fn extrude(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (length, sketch_set) = args.get_number_sketch_set()?;
let sketch_set = args.get_unlabeled_kw_arg("sketch_set")?;
let length = args.get_kw_arg("length")?;

let result = inner_extrude(length, sketch_set, exec_state, args).await?;
let result = inner_extrude(sketch_set, length, exec_state, args).await?;

Ok(result.into())
}
Expand Down Expand Up @@ -75,11 +76,17 @@ pub async fn extrude(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// example = extrude(10, exampleSketch)
/// ```
#[stdlib {
name = "extrude"
name = "extrude",
keywords = true,
unlabeled_first = true,
arg_docs = {
sketch_set = "Which sketches should be extruded",
length = "How far to extrude the given sketches",
}
}]
async fn inner_extrude(
length: f64,
sketch_set: SketchSet,
length: f64,
exec_state: &mut ExecState,
args: Args,
) -> Result<SolidSet, KclError> {
Expand Down
1 change: 0 additions & 1 deletion src/wasm-lib/kcl/src/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ lazy_static! {
Box::new(crate::std::segment::AngleToMatchLengthY),
Box::new(crate::std::shapes::Circle),
Box::new(crate::std::shapes::Polygon),
Box::new(crate::std::sketch::LineTo),
Box::new(crate::std::sketch::Line),
Box::new(crate::std::sketch::XLineTo),
Box::new(crate::std::sketch::XLine),
Expand Down
Loading

0 comments on commit 1f6427d

Please sign in to comment.