CM KCL: add named args to fn calls (#5303)
* CM KCL: add named args to fn calls * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Rename to match other code --------- Co-authored-by: Matt Mundell <matt@mundell.me> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 145 KiB |
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 129 KiB |
@ -59,7 +59,9 @@ UnaryOp { AddOp | BangOp }
|
|||||||
|
|
||||||
ObjectProperty { PropertyName (":" | Equals) expression }
|
ObjectProperty { PropertyName (":" | Equals) expression }
|
||||||
|
|
||||||
ArgumentList { "(" commaSep<expression> ")" }
|
LabeledArgument { ArgumentLabel Equals expression }
|
||||||
|
|
||||||
|
ArgumentList { "(" commaSep<LabeledArgument | expression> ")" }
|
||||||
|
|
||||||
type[@isGroup=Type] {
|
type[@isGroup=Type] {
|
||||||
@specialize[@name=PrimitiveType]<
|
@specialize[@name=PrimitiveType]<
|
||||||
@ -74,6 +76,8 @@ VariableDefinition { identifier }
|
|||||||
|
|
||||||
VariableName { identifier }
|
VariableName { identifier }
|
||||||
|
|
||||||
|
ArgumentLabel { identifier }
|
||||||
|
|
||||||
@skip { whitespace | LineComment | BlockComment }
|
@skip { whitespace | LineComment | BlockComment }
|
||||||
|
|
||||||
kw<term> { @specialize[@name={term}]<identifier, term> }
|
kw<term> { @specialize[@name={term}]<identifier, term> }
|
||||||
|
85
packages/codemirror-lang-kcl/test/call.txt
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# empty
|
||||||
|
|
||||||
|
f()
|
||||||
|
|
||||||
|
==>
|
||||||
|
Program(ExpressionStatement(CallExpression(VariableName,
|
||||||
|
ArgumentList)))
|
||||||
|
|
||||||
|
# single anon arg
|
||||||
|
|
||||||
|
f(1)
|
||||||
|
|
||||||
|
==>
|
||||||
|
Program(ExpressionStatement(CallExpression(VariableName,
|
||||||
|
ArgumentList(Number))))
|
||||||
|
|
||||||
|
# deprecated multiple anon args
|
||||||
|
|
||||||
|
f(1, 2)
|
||||||
|
|
||||||
|
==>
|
||||||
|
Program(ExpressionStatement(CallExpression(VariableName,
|
||||||
|
ArgumentList(Number,
|
||||||
|
Number))))
|
||||||
|
|
||||||
|
# deprecated trailing %
|
||||||
|
|
||||||
|
startSketchOn('XY')
|
||||||
|
|> line([thickness, 0], %)
|
||||||
|
|
||||||
|
==>
|
||||||
|
Program(ExpressionStatement(PipeExpression(CallExpression(VariableName,
|
||||||
|
ArgumentList(String)),
|
||||||
|
PipeOperator,
|
||||||
|
CallExpression(VariableName,
|
||||||
|
ArgumentList(ArrayExpression(VariableName,
|
||||||
|
Number),
|
||||||
|
PipeSubstitution)))))
|
||||||
|
|
||||||
|
# % and named arg
|
||||||
|
|
||||||
|
startSketchOn('XY')
|
||||||
|
|> line(%, end = [thickness, 0])
|
||||||
|
|
||||||
|
==>
|
||||||
|
Program(ExpressionStatement(PipeExpression(CallExpression(VariableName,
|
||||||
|
ArgumentList(String)),
|
||||||
|
PipeOperator,
|
||||||
|
CallExpression(VariableName,
|
||||||
|
ArgumentList(PipeSubstitution,
|
||||||
|
LabeledArgument(ArgumentLabel,
|
||||||
|
Equals,
|
||||||
|
ArrayExpression(VariableName,
|
||||||
|
Number)))))))
|
||||||
|
|
||||||
|
# implied % and named arg
|
||||||
|
|
||||||
|
startSketchOn('XY')
|
||||||
|
|> line(end = [thickness, 0])
|
||||||
|
|
||||||
|
==>
|
||||||
|
Program(ExpressionStatement(PipeExpression(CallExpression(VariableName,
|
||||||
|
ArgumentList(String)),
|
||||||
|
PipeOperator,
|
||||||
|
CallExpression(VariableName,
|
||||||
|
ArgumentList(LabeledArgument(ArgumentLabel,
|
||||||
|
Equals,
|
||||||
|
ArrayExpression(VariableName,
|
||||||
|
Number)))))))
|
||||||
|
|
||||||
|
# multiple named arg
|
||||||
|
|
||||||
|
ngon(plane = "XY", numSides = 5, radius = pentR)
|
||||||
|
|
||||||
|
==>
|
||||||
|
Program(ExpressionStatement(CallExpression(VariableName,
|
||||||
|
ArgumentList(LabeledArgument(ArgumentLabel,
|
||||||
|
Equals,
|
||||||
|
String),
|
||||||
|
LabeledArgument(ArgumentLabel,
|
||||||
|
Equals,
|
||||||
|
Number),
|
||||||
|
LabeledArgument(ArgumentLabel,
|
||||||
|
Equals,
|
||||||
|
VariableName)))))
|