Support comments on attributes (#5850)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-03-20 16:23:20 +13:00
committed by GitHub
parent 79be72c5f0
commit 461a2c3ab2
319 changed files with 37650 additions and 4752 deletions

View File

@ -6,15 +6,19 @@ description: Result of parsing bad_units_in_annotation.kcl
"Ok": {
"body": [
{
"commentStart": 33,
"declaration": {
"commentStart": 123,
"end": 0,
"id": {
"commentStart": 123,
"end": 0,
"name": "oxygenRadius",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 138,
"end": 0,
"raw": "0.066",
"start": 0,
@ -30,20 +34,30 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"end": 0,
"kind": "const",
"preComments": [
"// Generated by Text-to-CAD: draw a water molecule",
"",
"",
"// Constants for the water molecule"
],
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 143,
"declaration": {
"commentStart": 184,
"end": 0,
"id": {
"commentStart": 184,
"end": 0,
"name": "hydrogenRadius",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 201,
"end": 0,
"raw": "0.053",
"start": 0,
@ -64,15 +78,19 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "VariableDeclaration"
},
{
"commentStart": 206,
"declaration": {
"commentStart": 248,
"end": 0,
"id": {
"commentStart": 248,
"end": 0,
"name": "oxygenHydrogenDistance",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 273,
"end": 0,
"raw": "0.096",
"start": 0,
@ -93,15 +111,19 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "VariableDeclaration"
},
{
"commentStart": 278,
"declaration": {
"commentStart": 337,
"end": 0,
"id": {
"commentStart": 337,
"end": 0,
"name": "bondAngle",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 349,
"end": 0,
"raw": "104.5",
"start": 0,
@ -122,9 +144,12 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "VariableDeclaration"
},
{
"commentStart": 354,
"declaration": {
"commentStart": 437,
"end": 0,
"id": {
"commentStart": 437,
"end": 0,
"name": "createAtom",
"start": 0,
@ -139,6 +164,7 @@ description: Result of parsing bad_units_in_annotation.kcl
{
"arguments": [
{
"commentStart": 489,
"end": 0,
"raw": "'XY'",
"start": 0,
@ -148,11 +174,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 475,
"end": 0,
"name": "startSketchOn",
"start": 0,
"type": "Identifier"
},
"commentStart": 475,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -163,12 +191,14 @@ description: Result of parsing bad_units_in_annotation.kcl
{
"type": "LabeledArg",
"label": {
"commentStart": 509,
"end": 0,
"name": "center",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 518,
"end": 0,
"name": "center",
"start": 0,
@ -179,12 +209,14 @@ description: Result of parsing bad_units_in_annotation.kcl
{
"type": "LabeledArg",
"label": {
"commentStart": 526,
"end": 0,
"name": "radius",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 535,
"end": 0,
"name": "radius",
"start": 0,
@ -194,11 +226,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 502,
"end": 0,
"name": "circle",
"start": 0,
"type": "Identifier"
},
"commentStart": 502,
"end": 0,
"start": 0,
"type": "CallExpressionKw",
@ -210,14 +244,17 @@ description: Result of parsing bad_units_in_annotation.kcl
{
"type": "LabeledArg",
"label": {
"commentStart": 558,
"end": 0,
"name": "length",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 567,
"end": 0,
"left": {
"commentStart": 567,
"end": 0,
"name": "radius",
"start": 0,
@ -226,6 +263,7 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"operator": "*",
"right": {
"commentStart": 576,
"end": 0,
"raw": "2",
"start": 0,
@ -243,11 +281,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 550,
"end": 0,
"name": "extrude",
"start": 0,
"type": "Identifier"
},
"commentStart": 550,
"end": 0,
"start": 0,
"type": "CallExpressionKw",
@ -255,25 +295,30 @@ description: Result of parsing bad_units_in_annotation.kcl
"unlabeled": null
}
],
"commentStart": 475,
"end": 0,
"start": 0,
"type": "PipeExpression",
"type": "PipeExpression"
},
"commentStart": 468,
"end": 0,
"start": 0,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"commentStart": 464,
"end": 0,
"start": 0
},
"commentStart": 447,
"end": 0,
"params": [
{
"type": "Parameter",
"identifier": {
"commentStart": 448,
"end": 0,
"name": "center",
"start": 0,
@ -283,6 +328,7 @@ description: Result of parsing bad_units_in_annotation.kcl
{
"type": "Parameter",
"identifier": {
"commentStart": 456,
"end": 0,
"name": "radius",
"start": 0,
@ -299,14 +345,20 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"end": 0,
"kind": "fn",
"preComments": [
"// Function to create a sphere representing an atom"
],
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 580,
"declaration": {
"commentStart": 622,
"end": 0,
"id": {
"commentStart": 622,
"end": 0,
"name": "oxygenAtom",
"start": 0,
@ -315,8 +367,10 @@ description: Result of parsing bad_units_in_annotation.kcl
"init": {
"arguments": [
{
"commentStart": 646,
"elements": [
{
"commentStart": 647,
"end": 0,
"raw": "0",
"start": 0,
@ -328,6 +382,7 @@ description: Result of parsing bad_units_in_annotation.kcl
}
},
{
"commentStart": 650,
"end": 0,
"raw": "0",
"start": 0,
@ -345,6 +400,7 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "ArrayExpression"
},
{
"commentStart": 654,
"end": 0,
"name": "oxygenRadius",
"start": 0,
@ -353,11 +409,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 635,
"end": 0,
"name": "createAtom",
"start": 0,
"type": "Identifier"
},
"commentStart": 635,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -368,22 +426,32 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"end": 0,
"kind": "const",
"preComments": [
"",
"",
"// Create the oxygen atom at the origin"
],
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 667,
"declaration": {
"commentStart": 718,
"end": 0,
"id": {
"commentStart": 718,
"end": 0,
"name": "hydrogenOffsetX",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 736,
"end": 0,
"left": {
"commentStart": 736,
"end": 0,
"name": "oxygenHydrogenDistance",
"start": 0,
@ -396,8 +464,10 @@ description: Result of parsing bad_units_in_annotation.kcl
{
"arguments": [
{
"commentStart": 775,
"end": 0,
"left": {
"commentStart": 775,
"end": 0,
"name": "bondAngle",
"start": 0,
@ -406,6 +476,7 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"operator": "/",
"right": {
"commentStart": 787,
"end": 0,
"raw": "2",
"start": 0,
@ -422,11 +493,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 765,
"end": 0,
"name": "toRadians",
"start": 0,
"type": "Identifier"
},
"commentStart": 765,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -434,11 +507,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 761,
"end": 0,
"name": "cos",
"start": 0,
"type": "Identifier"
},
"commentStart": 761,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -453,22 +528,32 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"end": 0,
"kind": "const",
"preComments": [
"",
"",
"// Calculate the positions of the hydrogen atoms"
],
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 791,
"declaration": {
"commentStart": 791,
"end": 0,
"id": {
"commentStart": 791,
"end": 0,
"name": "hydrogenOffsetY",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 809,
"end": 0,
"left": {
"commentStart": 809,
"end": 0,
"name": "oxygenHydrogenDistance",
"start": 0,
@ -481,8 +566,10 @@ description: Result of parsing bad_units_in_annotation.kcl
{
"arguments": [
{
"commentStart": 848,
"end": 0,
"left": {
"commentStart": 848,
"end": 0,
"name": "bondAngle",
"start": 0,
@ -491,6 +578,7 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"operator": "/",
"right": {
"commentStart": 860,
"end": 0,
"raw": "2",
"start": 0,
@ -507,11 +595,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 838,
"end": 0,
"name": "toRadians",
"start": 0,
"type": "Identifier"
},
"commentStart": 838,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -519,11 +609,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 834,
"end": 0,
"name": "sin",
"start": 0,
"type": "Identifier"
},
"commentStart": 834,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -543,9 +635,12 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "VariableDeclaration"
},
{
"commentStart": 863,
"declaration": {
"commentStart": 894,
"end": 0,
"id": {
"commentStart": 894,
"end": 0,
"name": "hydrogenAtom1",
"start": 0,
@ -554,8 +649,10 @@ description: Result of parsing bad_units_in_annotation.kcl
"init": {
"arguments": [
{
"commentStart": 921,
"elements": [
{
"commentStart": 922,
"end": 0,
"name": "hydrogenOffsetX",
"start": 0,
@ -563,6 +660,7 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "Identifier"
},
{
"commentStart": 939,
"end": 0,
"name": "hydrogenOffsetY",
"start": 0,
@ -576,6 +674,7 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "ArrayExpression"
},
{
"commentStart": 957,
"end": 0,
"name": "hydrogenRadius",
"start": 0,
@ -584,11 +683,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 910,
"end": 0,
"name": "createAtom",
"start": 0,
"type": "Identifier"
},
"commentStart": 910,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -599,14 +700,22 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"end": 0,
"kind": "const",
"preComments": [
"",
"",
"// Create the hydrogen atoms"
],
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 973,
"declaration": {
"commentStart": 973,
"end": 0,
"id": {
"commentStart": 973,
"end": 0,
"name": "hydrogenAtom2",
"start": 0,
@ -615,15 +724,18 @@ description: Result of parsing bad_units_in_annotation.kcl
"init": {
"arguments": [
{
"commentStart": 1000,
"elements": [
{
"argument": {
"commentStart": 1002,
"end": 0,
"name": "hydrogenOffsetX",
"start": 0,
"type": "Identifier",
"type": "Identifier"
},
"commentStart": 1001,
"end": 0,
"operator": "-",
"start": 0,
@ -631,6 +743,7 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "UnaryExpression"
},
{
"commentStart": 1019,
"end": 0,
"name": "hydrogenOffsetY",
"start": 0,
@ -644,6 +757,7 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "ArrayExpression"
},
{
"commentStart": 1037,
"end": 0,
"name": "hydrogenRadius",
"start": 0,
@ -652,11 +766,13 @@ description: Result of parsing bad_units_in_annotation.kcl
}
],
"callee": {
"commentStart": 989,
"end": 0,
"name": "createAtom",
"start": 0,
"type": "Identifier"
},
"commentStart": 989,
"end": 0,
"start": 0,
"type": "CallExpression",
@ -672,11 +788,14 @@ description: Result of parsing bad_units_in_annotation.kcl
"type": "VariableDeclaration"
}
],
"commentStart": 0,
"end": 0,
"innerAttrs": [
{
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 1,
"end": 0,
"name": "settings",
"start": 0,
@ -684,8 +803,10 @@ description: Result of parsing bad_units_in_annotation.kcl
},
"properties": [
{
"commentStart": 10,
"end": 0,
"key": {
"commentStart": 10,
"end": 0,
"name": "defaultLengthUnit",
"start": 0,
@ -694,6 +815,7 @@ description: Result of parsing bad_units_in_annotation.kcl
"start": 0,
"type": "ObjectProperty",
"value": {
"commentStart": 30,
"end": 0,
"name": "nm",
"start": 0,
@ -710,6 +832,7 @@ description: Result of parsing bad_units_in_annotation.kcl
"nonCodeNodes": {
"0": [
{
"commentStart": 143,
"end": 0,
"start": 0,
"type": "NonCodeNode",
@ -722,6 +845,7 @@ description: Result of parsing bad_units_in_annotation.kcl
],
"1": [
{
"commentStart": 206,
"end": 0,
"start": 0,
"type": "NonCodeNode",
@ -734,6 +858,7 @@ description: Result of parsing bad_units_in_annotation.kcl
],
"2": [
{
"commentStart": 278,
"end": 0,
"start": 0,
"type": "NonCodeNode",
@ -746,6 +871,7 @@ description: Result of parsing bad_units_in_annotation.kcl
],
"3": [
{
"commentStart": 354,
"end": 0,
"start": 0,
"type": "NonCodeNode",
@ -756,89 +882,25 @@ description: Result of parsing bad_units_in_annotation.kcl
}
},
{
"commentStart": 379,
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
},
{
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "Function to create a sphere representing an atom",
"style": "line"
}
}
],
"4": [
{
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Create the oxygen atom at the origin",
"style": "line"
}
}
],
"5": [
{
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Calculate the positions of the hydrogen atoms",
"style": "line"
}
}
],
"7": [
{
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLineBlockComment",
"value": "Create the hydrogen atoms",
"style": "line"
}
}
]
},
"startNodes": [
{
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "Generated by Text-to-CAD: draw a water molecule",
"style": "line"
}
},
{
"commentStart": 33,
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
},
{
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "blockComment",
"value": "Constants for the water molecule",
"style": "line"
}
}
]
},

View File

@ -10,5 +10,5 @@ KCL Semantic error
1 │ @settings(defaultLengthUnit = nm)
· ────────────────┬────────────────
· ╰── tests/bad_units_in_annotation/input.kcl
2 │ // Generated by Text-to-CAD: draw a water molecule
2 │
╰────

View File

@ -1,6 +1,6 @@
@settings(defaultLengthUnit = nm)
// Generated by Text-to-CAD: draw a water molecule
// Generated by Text-to-CAD: draw a water molecule
// Constants for the water molecule
oxygenRadius = 0.066 // Approximate radius of an oxygen atom

View File

@ -3,8 +3,8 @@ source: kcl-lib/src/simulation_tests.rs
description: Result of unparsing bad_units_in_annotation.kcl
---
@settings(defaultLengthUnit = nm)
// Generated by Text-to-CAD: draw a water molecule
// Generated by Text-to-CAD: draw a water molecule
// Constants for the water molecule
oxygenRadius = 0.066 // Approximate radius of an oxygen atom