Parse multi-line comments in |> expressions (#3731)
Fixes #3708, ty @mlfarrell for reporting!
This commit is contained in:
@ -135,13 +135,16 @@ fn non_code_node_no_leading_whitespace(i: TokenSlice) -> PResult<NonCodeNode> {
|
|||||||
|
|
||||||
fn pipe_expression(i: TokenSlice) -> PResult<PipeExpression> {
|
fn pipe_expression(i: TokenSlice) -> PResult<PipeExpression> {
|
||||||
let mut non_code_meta = NonCodeMeta::default();
|
let mut non_code_meta = NonCodeMeta::default();
|
||||||
let (head, noncode) = terminated(
|
let (head, noncode): (_, Vec<_>) = terminated(
|
||||||
(expression_but_not_pipe, preceded(whitespace, opt(non_code_node))),
|
(
|
||||||
|
expression_but_not_pipe,
|
||||||
|
repeat(0.., preceded(whitespace, non_code_node)),
|
||||||
|
),
|
||||||
peek(pipe_surrounded_by_whitespace),
|
peek(pipe_surrounded_by_whitespace),
|
||||||
)
|
)
|
||||||
.context(expected("an expression, followed by the |> (pipe) operator"))
|
.context(expected("an expression, followed by the |> (pipe) operator"))
|
||||||
.parse_next(i)?;
|
.parse_next(i)?;
|
||||||
if let Some(nc) = noncode {
|
for nc in noncode {
|
||||||
non_code_meta.insert(0, nc);
|
non_code_meta.insert(0, nc);
|
||||||
}
|
}
|
||||||
let mut values = vec![head];
|
let mut values = vec![head];
|
||||||
@ -3453,6 +3456,17 @@ mod snapshot_tests {
|
|||||||
c: 3
|
c: 3
|
||||||
}"
|
}"
|
||||||
);
|
);
|
||||||
|
snapshot_test!(
|
||||||
|
ba,
|
||||||
|
r#"
|
||||||
|
const sketch001 = startSketchOn('XY')
|
||||||
|
// |> arc({
|
||||||
|
// angleEnd: 270,
|
||||||
|
// angleStart: 450,
|
||||||
|
// }, %)
|
||||||
|
|> startProfileAt(%)
|
||||||
|
"#
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
|||||||
@ -0,0 +1,150 @@
|
|||||||
|
---
|
||||||
|
source: kcl/src/parser/parser_impl.rs
|
||||||
|
expression: actual
|
||||||
|
---
|
||||||
|
{
|
||||||
|
"start": 0,
|
||||||
|
"end": 133,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"start": 1,
|
||||||
|
"end": 132,
|
||||||
|
"declarations": [
|
||||||
|
{
|
||||||
|
"type": "VariableDeclarator",
|
||||||
|
"start": 7,
|
||||||
|
"end": 132,
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 7,
|
||||||
|
"end": 16,
|
||||||
|
"name": "sketch001",
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
"init": {
|
||||||
|
"type": "PipeExpression",
|
||||||
|
"type": "PipeExpression",
|
||||||
|
"start": 19,
|
||||||
|
"end": 132,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "CallExpression",
|
||||||
|
"type": "CallExpression",
|
||||||
|
"start": 19,
|
||||||
|
"end": 38,
|
||||||
|
"callee": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 19,
|
||||||
|
"end": 32,
|
||||||
|
"name": "startSketchOn",
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"type": "Literal",
|
||||||
|
"type": "Literal",
|
||||||
|
"start": 33,
|
||||||
|
"end": 37,
|
||||||
|
"value": "XY",
|
||||||
|
"raw": "'XY'",
|
||||||
|
"digest": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"optional": false,
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CallExpression",
|
||||||
|
"type": "CallExpression",
|
||||||
|
"start": 115,
|
||||||
|
"end": 132,
|
||||||
|
"callee": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 115,
|
||||||
|
"end": 129,
|
||||||
|
"name": "startProfileAt",
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"type": "PipeSubstitution",
|
||||||
|
"type": "PipeSubstitution",
|
||||||
|
"start": 130,
|
||||||
|
"end": 131,
|
||||||
|
"digest": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"optional": false,
|
||||||
|
"digest": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nonCodeMeta": {
|
||||||
|
"nonCodeNodes": {
|
||||||
|
"0": [
|
||||||
|
{
|
||||||
|
"type": "NonCodeNode",
|
||||||
|
"start": 41,
|
||||||
|
"end": 52,
|
||||||
|
"value": {
|
||||||
|
"type": "blockComment",
|
||||||
|
"value": "|> arc({",
|
||||||
|
"style": "line"
|
||||||
|
},
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NonCodeNode",
|
||||||
|
"start": 55,
|
||||||
|
"end": 74,
|
||||||
|
"value": {
|
||||||
|
"type": "blockComment",
|
||||||
|
"value": "angleEnd: 270,",
|
||||||
|
"style": "line"
|
||||||
|
},
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NonCodeNode",
|
||||||
|
"start": 77,
|
||||||
|
"end": 98,
|
||||||
|
"value": {
|
||||||
|
"type": "blockComment",
|
||||||
|
"value": "angleStart: 450,",
|
||||||
|
"style": "line"
|
||||||
|
},
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NonCodeNode",
|
||||||
|
"start": 101,
|
||||||
|
"end": 109,
|
||||||
|
"value": {
|
||||||
|
"type": "blockComment",
|
||||||
|
"value": "}, %)",
|
||||||
|
"style": "line"
|
||||||
|
},
|
||||||
|
"digest": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"start": [],
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
"digest": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"kind": "const",
|
||||||
|
"digest": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nonCodeMeta": {
|
||||||
|
"nonCodeNodes": {},
|
||||||
|
"start": [],
|
||||||
|
"digest": null
|
||||||
|
},
|
||||||
|
"digest": null
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user