2024-11-04 20:34:22 -06:00
|
|
|
---
|
|
|
|
source: kcl/src/simulation_tests.rs
|
|
|
|
description: Result of parsing if_else.kcl
|
|
|
|
---
|
|
|
|
{
|
|
|
|
"Ok": {
|
|
|
|
"body": [
|
|
|
|
{
|
2024-12-07 07:16:04 +13:00
|
|
|
"declaration": {
|
|
|
|
"end": 101,
|
|
|
|
"id": {
|
|
|
|
"end": 49,
|
|
|
|
"name": "a",
|
|
|
|
"start": 48,
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
"cond": {
|
|
|
|
"end": 59,
|
|
|
|
"raw": "true",
|
|
|
|
"start": 55,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": true
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"digest": null,
|
|
|
|
"else_ifs": [
|
|
|
|
{
|
|
|
|
"cond": {
|
|
|
|
"end": 80,
|
|
|
|
"raw": "true",
|
|
|
|
"start": 76,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": true
|
|
|
|
},
|
|
|
|
"digest": null,
|
|
|
|
"end": 88,
|
|
|
|
"start": 68,
|
|
|
|
"then_val": {
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"end": 86,
|
|
|
|
"expression": {
|
|
|
|
"end": 86,
|
|
|
|
"raw": "4",
|
|
|
|
"start": 85,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 4.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-12-07 07:16:04 +13:00
|
|
|
},
|
|
|
|
"start": 85,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 87,
|
|
|
|
"start": 81
|
|
|
|
},
|
|
|
|
"type": "ElseIf"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 101,
|
|
|
|
"final_else": {
|
|
|
|
"body": [
|
2024-11-04 20:34:22 -06:00
|
|
|
{
|
2024-12-07 07:16:04 +13:00
|
|
|
"end": 99,
|
|
|
|
"expression": {
|
|
|
|
"end": 99,
|
|
|
|
"raw": "5",
|
|
|
|
"start": 98,
|
2024-11-04 20:34:22 -06:00
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 5.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"start": 98,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
2024-11-04 20:34:22 -06:00
|
|
|
}
|
|
|
|
],
|
2024-12-07 07:16:04 +13:00
|
|
|
"end": 100,
|
|
|
|
"start": 98
|
|
|
|
},
|
|
|
|
"start": 52,
|
|
|
|
"then_val": {
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"end": 65,
|
|
|
|
"expression": {
|
2024-11-04 20:34:22 -06:00
|
|
|
"end": 65,
|
2024-12-07 07:16:04 +13:00
|
|
|
"raw": "3",
|
2024-11-04 20:34:22 -06:00
|
|
|
"start": 64,
|
2024-12-07 07:16:04 +13:00
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 3.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-12-07 07:16:04 +13:00
|
|
|
},
|
|
|
|
"start": 64,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 66,
|
|
|
|
"start": 64
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"type": "IfExpression",
|
|
|
|
"type": "IfExpression"
|
|
|
|
},
|
|
|
|
"start": 48,
|
|
|
|
"type": "VariableDeclarator"
|
|
|
|
},
|
2024-11-04 20:34:22 -06:00
|
|
|
"end": 101,
|
|
|
|
"kind": "const",
|
|
|
|
"start": 48,
|
|
|
|
"type": "VariableDeclaration",
|
|
|
|
"type": "VariableDeclaration"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 159,
|
|
|
|
"expression": {
|
|
|
|
"arguments": [
|
|
|
|
{
|
|
|
|
"end": 115,
|
|
|
|
"name": "a",
|
|
|
|
"start": 114,
|
|
|
|
"type": "Identifier",
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 118,
|
|
|
|
"raw": "3",
|
|
|
|
"start": 117,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 3.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 125,
|
|
|
|
"raw": "0.001",
|
|
|
|
"start": 120,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 0.001,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 158,
|
|
|
|
"raw": "\"the 'if' branch gets returned\"",
|
|
|
|
"start": 127,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": "the 'if' branch gets returned"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"callee": {
|
|
|
|
"end": 113,
|
|
|
|
"name": "assertEqual",
|
|
|
|
"start": 102,
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
"end": 159,
|
|
|
|
"start": 102,
|
|
|
|
"type": "CallExpression",
|
|
|
|
"type": "CallExpression"
|
|
|
|
},
|
|
|
|
"start": 102,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
},
|
|
|
|
{
|
2024-12-07 07:16:04 +13:00
|
|
|
"declaration": {
|
|
|
|
"end": 215,
|
|
|
|
"id": {
|
|
|
|
"end": 162,
|
|
|
|
"name": "b",
|
|
|
|
"start": 161,
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
"cond": {
|
|
|
|
"end": 173,
|
|
|
|
"raw": "false",
|
|
|
|
"start": 168,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": false
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"digest": null,
|
|
|
|
"else_ifs": [
|
|
|
|
{
|
|
|
|
"cond": {
|
|
|
|
"end": 194,
|
|
|
|
"raw": "true",
|
|
|
|
"start": 190,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": true
|
|
|
|
},
|
|
|
|
"digest": null,
|
|
|
|
"end": 202,
|
|
|
|
"start": 182,
|
|
|
|
"then_val": {
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"end": 200,
|
|
|
|
"expression": {
|
|
|
|
"end": 200,
|
|
|
|
"raw": "4",
|
|
|
|
"start": 199,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 4.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-12-07 07:16:04 +13:00
|
|
|
},
|
|
|
|
"start": 199,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 201,
|
|
|
|
"start": 195
|
|
|
|
},
|
|
|
|
"type": "ElseIf"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 215,
|
|
|
|
"final_else": {
|
|
|
|
"body": [
|
2024-11-04 20:34:22 -06:00
|
|
|
{
|
2024-12-07 07:16:04 +13:00
|
|
|
"end": 213,
|
|
|
|
"expression": {
|
|
|
|
"end": 213,
|
|
|
|
"raw": "5",
|
|
|
|
"start": 212,
|
2024-11-04 20:34:22 -06:00
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 5.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"start": 212,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
2024-11-04 20:34:22 -06:00
|
|
|
}
|
|
|
|
],
|
2024-12-07 07:16:04 +13:00
|
|
|
"end": 214,
|
|
|
|
"start": 212
|
|
|
|
},
|
|
|
|
"start": 165,
|
|
|
|
"then_val": {
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"end": 179,
|
|
|
|
"expression": {
|
2024-11-04 20:34:22 -06:00
|
|
|
"end": 179,
|
2024-12-07 07:16:04 +13:00
|
|
|
"raw": "3",
|
2024-11-04 20:34:22 -06:00
|
|
|
"start": 178,
|
2024-12-07 07:16:04 +13:00
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 3.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-12-07 07:16:04 +13:00
|
|
|
},
|
|
|
|
"start": 178,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 180,
|
|
|
|
"start": 178
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"type": "IfExpression",
|
|
|
|
"type": "IfExpression"
|
|
|
|
},
|
|
|
|
"start": 161,
|
|
|
|
"type": "VariableDeclarator"
|
|
|
|
},
|
2024-11-04 20:34:22 -06:00
|
|
|
"end": 215,
|
|
|
|
"kind": "const",
|
|
|
|
"start": 161,
|
|
|
|
"type": "VariableDeclaration",
|
|
|
|
"type": "VariableDeclaration"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 278,
|
|
|
|
"expression": {
|
|
|
|
"arguments": [
|
|
|
|
{
|
|
|
|
"end": 229,
|
|
|
|
"name": "b",
|
|
|
|
"start": 228,
|
|
|
|
"type": "Identifier",
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 232,
|
|
|
|
"raw": "4",
|
|
|
|
"start": 231,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 4.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 239,
|
|
|
|
"raw": "0.001",
|
|
|
|
"start": 234,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 0.001,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 277,
|
|
|
|
"raw": "\"the 'else if' branch gets returned\"",
|
|
|
|
"start": 241,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": "the 'else if' branch gets returned"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"callee": {
|
|
|
|
"end": 227,
|
|
|
|
"name": "assertEqual",
|
|
|
|
"start": 216,
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
"end": 278,
|
|
|
|
"start": 216,
|
|
|
|
"type": "CallExpression",
|
|
|
|
"type": "CallExpression"
|
|
|
|
},
|
|
|
|
"start": 216,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
},
|
|
|
|
{
|
2024-12-07 07:16:04 +13:00
|
|
|
"declaration": {
|
|
|
|
"end": 335,
|
|
|
|
"id": {
|
|
|
|
"end": 281,
|
|
|
|
"name": "c",
|
|
|
|
"start": 280,
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
"cond": {
|
|
|
|
"end": 292,
|
|
|
|
"raw": "false",
|
|
|
|
"start": 287,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": false
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"digest": null,
|
|
|
|
"else_ifs": [
|
|
|
|
{
|
|
|
|
"cond": {
|
|
|
|
"end": 314,
|
|
|
|
"raw": "false",
|
|
|
|
"start": 309,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": false
|
|
|
|
},
|
|
|
|
"digest": null,
|
|
|
|
"end": 322,
|
|
|
|
"start": 301,
|
|
|
|
"then_val": {
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"end": 320,
|
|
|
|
"expression": {
|
|
|
|
"end": 320,
|
|
|
|
"raw": "4",
|
|
|
|
"start": 319,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 4.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-12-07 07:16:04 +13:00
|
|
|
},
|
|
|
|
"start": 319,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 321,
|
|
|
|
"start": 315
|
|
|
|
},
|
|
|
|
"type": "ElseIf"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 335,
|
|
|
|
"final_else": {
|
|
|
|
"body": [
|
2024-11-04 20:34:22 -06:00
|
|
|
{
|
2024-12-07 07:16:04 +13:00
|
|
|
"end": 333,
|
|
|
|
"expression": {
|
|
|
|
"end": 333,
|
|
|
|
"raw": "5",
|
|
|
|
"start": 332,
|
2024-11-04 20:34:22 -06:00
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 5.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"start": 332,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
2024-11-04 20:34:22 -06:00
|
|
|
}
|
|
|
|
],
|
2024-12-07 07:16:04 +13:00
|
|
|
"end": 334,
|
|
|
|
"start": 332
|
|
|
|
},
|
|
|
|
"start": 284,
|
|
|
|
"then_val": {
|
|
|
|
"body": [
|
|
|
|
{
|
|
|
|
"end": 298,
|
|
|
|
"expression": {
|
2024-11-04 20:34:22 -06:00
|
|
|
"end": 298,
|
2024-12-07 07:16:04 +13:00
|
|
|
"raw": "3",
|
2024-11-04 20:34:22 -06:00
|
|
|
"start": 297,
|
2024-12-07 07:16:04 +13:00
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 3.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-12-07 07:16:04 +13:00
|
|
|
},
|
|
|
|
"start": 297,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 299,
|
|
|
|
"start": 297
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
2024-12-07 07:16:04 +13:00
|
|
|
"type": "IfExpression",
|
|
|
|
"type": "IfExpression"
|
|
|
|
},
|
|
|
|
"start": 280,
|
|
|
|
"type": "VariableDeclarator"
|
|
|
|
},
|
2024-11-04 20:34:22 -06:00
|
|
|
"end": 335,
|
|
|
|
"kind": "const",
|
|
|
|
"start": 280,
|
|
|
|
"type": "VariableDeclaration",
|
|
|
|
"type": "VariableDeclaration"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 395,
|
|
|
|
"expression": {
|
|
|
|
"arguments": [
|
|
|
|
{
|
|
|
|
"end": 349,
|
|
|
|
"name": "c",
|
|
|
|
"start": 348,
|
|
|
|
"type": "Identifier",
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 352,
|
|
|
|
"raw": "5",
|
|
|
|
"start": 351,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 5.0,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 359,
|
|
|
|
"raw": "0.001",
|
|
|
|
"start": 354,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
2025-01-22 08:29:30 +13:00
|
|
|
"value": {
|
|
|
|
"value": 0.001,
|
|
|
|
"suffix": "None"
|
|
|
|
}
|
2024-11-04 20:34:22 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 394,
|
|
|
|
"raw": "\"the 'else' branch gets returned\"",
|
|
|
|
"start": 361,
|
|
|
|
"type": "Literal",
|
|
|
|
"type": "Literal",
|
|
|
|
"value": "the 'else' branch gets returned"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"callee": {
|
|
|
|
"end": 347,
|
|
|
|
"name": "assertEqual",
|
|
|
|
"start": 336,
|
|
|
|
"type": "Identifier"
|
|
|
|
},
|
|
|
|
"end": 395,
|
|
|
|
"start": 336,
|
|
|
|
"type": "CallExpression",
|
|
|
|
"type": "CallExpression"
|
|
|
|
},
|
|
|
|
"start": 336,
|
|
|
|
"type": "ExpressionStatement",
|
|
|
|
"type": "ExpressionStatement"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"end": 396,
|
|
|
|
"nonCodeMeta": {
|
|
|
|
"nonCodeNodes": {
|
|
|
|
"1": [
|
|
|
|
{
|
|
|
|
"end": 161,
|
|
|
|
"start": 159,
|
|
|
|
"type": "NonCodeNode",
|
|
|
|
"value": {
|
|
|
|
"type": "newLine"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"3": [
|
|
|
|
{
|
|
|
|
"end": 280,
|
|
|
|
"start": 278,
|
|
|
|
"type": "NonCodeNode",
|
|
|
|
"value": {
|
|
|
|
"type": "newLine"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"startNodes": [
|
|
|
|
{
|
|
|
|
"end": 45,
|
|
|
|
"start": 0,
|
|
|
|
"type": "NonCodeNode",
|
|
|
|
"value": {
|
|
|
|
"type": "blockComment",
|
|
|
|
"value": "This tests evaluating if-else expressions.",
|
|
|
|
"style": "line"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"end": 48,
|
|
|
|
"start": 45,
|
|
|
|
"type": "NonCodeNode",
|
|
|
|
"value": {
|
|
|
|
"type": "newLine"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"start": 0
|
|
|
|
}
|
|
|
|
}
|