Declare std kwarg functions in KCL and migrate circle (#5955)
* Support calling KCL std KW fns, and move circle to KCL std Signed-off-by: Nick Cameron <nrc@ncameron.org> * Doc comments on parameters Signed-off-by: Nick Cameron <nrc@ncameron.org> * Update grammar Signed-off-by: Nick Cameron <nrc@ncameron.org> * Change use of counterClockWise to ccw Signed-off-by: Nick Cameron <nrc@ncameron.org> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -2883,15 +2883,40 @@ fn uom_for_type(i: &mut TokenSlice) -> PResult<NumericSuffix> {
|
||||
any.try_map(|t: Token| t.value.parse()).parse_next(i)
|
||||
}
|
||||
|
||||
fn comment(i: &mut TokenSlice) -> PResult<Node<String>> {
|
||||
any.verify_map(|token: Token| {
|
||||
let value = match token.token_type {
|
||||
TokenType::LineComment => token.value,
|
||||
TokenType::BlockComment => token.value,
|
||||
_ => return None,
|
||||
};
|
||||
Some(Node::new(value, token.start, token.end, token.module_id))
|
||||
})
|
||||
.context(expected("Comment"))
|
||||
.parse_next(i)
|
||||
}
|
||||
|
||||
fn comments(i: &mut TokenSlice) -> PResult<Node<Vec<String>>> {
|
||||
let comments: Vec<Node<String>> = repeat(1.., (comment, opt(whitespace)).map(|(c, _)| c)).parse_next(i)?;
|
||||
let start = comments[0].start;
|
||||
let module_id = comments[0].module_id;
|
||||
let end = comments.last().unwrap().end;
|
||||
let inner = comments.into_iter().map(|n| n.inner).collect();
|
||||
Ok(Node::new(inner, start, end, module_id))
|
||||
}
|
||||
|
||||
struct ParamDescription {
|
||||
labeled: bool,
|
||||
arg_name: Token,
|
||||
type_: std::option::Option<Node<Type>>,
|
||||
default_value: Option<DefaultParamVal>,
|
||||
comments: Option<Node<Vec<String>>>,
|
||||
}
|
||||
|
||||
fn parameter(i: &mut TokenSlice) -> PResult<ParamDescription> {
|
||||
let (found_at_sign, arg_name, question_mark, _, type_, _ws, default_literal) = (
|
||||
let (_, comments, found_at_sign, arg_name, question_mark, _, type_, _ws, default_literal) = (
|
||||
opt(whitespace),
|
||||
opt(comments),
|
||||
opt(at_sign),
|
||||
any.verify(|token: &Token| !matches!(token.token_type, TokenType::Brace) || token.value != ")"),
|
||||
opt(question_mark),
|
||||
@ -2901,6 +2926,7 @@ fn parameter(i: &mut TokenSlice) -> PResult<ParamDescription> {
|
||||
opt((equals, opt(whitespace), literal).map(|(_, _, literal)| literal)),
|
||||
)
|
||||
.parse_next(i)?;
|
||||
|
||||
Ok(ParamDescription {
|
||||
labeled: found_at_sign.is_none(),
|
||||
arg_name,
|
||||
@ -2915,6 +2941,7 @@ fn parameter(i: &mut TokenSlice) -> PResult<ParamDescription> {
|
||||
return Err(ErrMode::Backtrack(ContextError::from(e)));
|
||||
}
|
||||
},
|
||||
comments,
|
||||
})
|
||||
}
|
||||
|
||||
@ -2924,6 +2951,7 @@ fn parameters(i: &mut TokenSlice) -> PResult<Vec<Parameter>> {
|
||||
let candidates: Vec<_> = separated(0.., parameter, comma_sep)
|
||||
.context(expected("function parameters"))
|
||||
.parse_next(i)?;
|
||||
opt(comma_sep).parse_next(i)?;
|
||||
|
||||
// Make sure all those tokens are valid parameters.
|
||||
let params: Vec<Parameter> = candidates
|
||||
@ -2934,8 +2962,13 @@ fn parameters(i: &mut TokenSlice) -> PResult<Vec<Parameter>> {
|
||||
arg_name,
|
||||
type_,
|
||||
default_value,
|
||||
comments,
|
||||
}| {
|
||||
let identifier = Node::<Identifier>::try_from(arg_name)?;
|
||||
let mut identifier = Node::<Identifier>::try_from(arg_name)?;
|
||||
if let Some(comments) = comments {
|
||||
identifier.comment_start = comments.start;
|
||||
identifier.pre_comments = comments.inner;
|
||||
}
|
||||
|
||||
Ok(Parameter {
|
||||
identifier,
|
||||
|
Reference in New Issue
Block a user