Implements boolean logical and/or in kcl (#4678)
* redoing bool logic impl on latest main * adding snapshot tests (removing .new) * removing accidental change smh:( * accepting client side scene snapshot * accepting png snapshot and triggering ci * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * accepting png again? * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * accepting grid visibility snapshot * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * accepting png snapshot * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * accepting png snapshot * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * accepting png snapshot * rerunning simtest creation to get ops.snap files --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
Binary file not shown.
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
Binary file not shown.
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 124 KiB |
@ -12,6 +12,7 @@ export const kclHighlight = styleTags({
|
||||
'AddOp MultOp ExpOp': t.arithmeticOperator,
|
||||
BangOp: t.logicOperator,
|
||||
CompOp: t.compareOperator,
|
||||
LogicOp: t.logicOperator,
|
||||
'Equals Arrow': t.definitionOperator,
|
||||
PipeOperator: t.controlOperator,
|
||||
String: t.string,
|
||||
|
@ -5,6 +5,7 @@
|
||||
mult @left
|
||||
add @left
|
||||
comp @left
|
||||
logic @left
|
||||
pipe @left
|
||||
range
|
||||
}
|
||||
@ -40,7 +41,8 @@ expression[@isGroup=Expression] {
|
||||
expression !add AddOp expression |
|
||||
expression !mult MultOp expression |
|
||||
expression !exp ExpOp expression |
|
||||
expression !comp CompOp expression
|
||||
expression !comp CompOp expression |
|
||||
expression !logic LogicOp expression
|
||||
} |
|
||||
UnaryExpression { UnaryOp expression } |
|
||||
ParenthesizedExpression { "(" expression ")" } |
|
||||
@ -89,6 +91,7 @@ commaSep1NoTrailingComma<term> { term ("," term)* }
|
||||
AddOp { "+" | "-" }
|
||||
MultOp { "/" | "*" | "\\" }
|
||||
ExpOp { "^" }
|
||||
LogicOp { "|" | "&" }
|
||||
BangOp { "!" }
|
||||
CompOp { "==" | "!=" | "<=" | ">=" | "<" | ">" }
|
||||
Equals { "=" }
|
||||
|
@ -170,6 +170,42 @@ impl Node<BinaryExpression> {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we are doing logical operations on booleans.
|
||||
if self.operator == BinaryOperator::Or || self.operator == BinaryOperator::And {
|
||||
let KclValue::Bool {
|
||||
value: left_value,
|
||||
meta: _,
|
||||
} = left_value
|
||||
else {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
message: format!(
|
||||
"Cannot apply logical operator to non-boolean value: {}",
|
||||
left_value.human_friendly_type()
|
||||
),
|
||||
source_ranges: vec![self.left.clone().into()],
|
||||
}));
|
||||
};
|
||||
let KclValue::Bool {
|
||||
value: right_value,
|
||||
meta: _,
|
||||
} = right_value
|
||||
else {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
message: format!(
|
||||
"Cannot apply logical operator to non-boolean value: {}",
|
||||
right_value.human_friendly_type()
|
||||
),
|
||||
source_ranges: vec![self.right.clone().into()],
|
||||
}));
|
||||
};
|
||||
let raw_value = match self.operator {
|
||||
BinaryOperator::Or => left_value || right_value,
|
||||
BinaryOperator::And => left_value && right_value,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
return Ok(KclValue::Bool { value: raw_value, meta });
|
||||
}
|
||||
|
||||
let left = parse_number_as_f64(&left_value, self.left.clone().into())?;
|
||||
let right = parse_number_as_f64(&right_value, self.right.clone().into())?;
|
||||
|
||||
@ -222,6 +258,7 @@ impl Node<BinaryExpression> {
|
||||
value: left == right,
|
||||
meta,
|
||||
},
|
||||
BinaryOperator::And | BinaryOperator::Or => unreachable!(),
|
||||
};
|
||||
|
||||
Ok(value)
|
||||
|
@ -2596,6 +2596,14 @@ pub enum BinaryOperator {
|
||||
#[serde(rename = "<=")]
|
||||
#[display("<=")]
|
||||
Lte,
|
||||
/// Are both left and right true?
|
||||
#[serde(rename = "&")]
|
||||
#[display("&")]
|
||||
And,
|
||||
/// Is either left or right true?
|
||||
#[serde(rename = "|")]
|
||||
#[display("|")]
|
||||
Or,
|
||||
}
|
||||
|
||||
/// Mathematical associativity.
|
||||
@ -2630,6 +2638,8 @@ impl BinaryOperator {
|
||||
BinaryOperator::Gte => *b"gte",
|
||||
BinaryOperator::Lt => *b"ltr",
|
||||
BinaryOperator::Lte => *b"lte",
|
||||
BinaryOperator::And => *b"and",
|
||||
BinaryOperator::Or => *b"lor",
|
||||
}
|
||||
}
|
||||
|
||||
@ -2642,6 +2652,8 @@ impl BinaryOperator {
|
||||
BinaryOperator::Pow => 13,
|
||||
Self::Gt | Self::Gte | Self::Lt | Self::Lte => 9,
|
||||
Self::Eq | Self::Neq => 8,
|
||||
Self::And => 7,
|
||||
Self::Or => 6,
|
||||
}
|
||||
}
|
||||
|
||||
@ -2652,6 +2664,7 @@ impl BinaryOperator {
|
||||
Self::Add | Self::Sub | Self::Mul | Self::Div | Self::Mod => Associativity::Left,
|
||||
Self::Pow => Associativity::Right,
|
||||
Self::Gt | Self::Gte | Self::Lt | Self::Lte | Self::Eq | Self::Neq => Associativity::Left, // I don't know if this is correct
|
||||
Self::And | Self::Or => Associativity::Left,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -504,6 +504,8 @@ fn binary_operator(i: &mut TokenSlice) -> PResult<BinaryOperator> {
|
||||
">=" => BinaryOperator::Gte,
|
||||
"<" => BinaryOperator::Lt,
|
||||
"<=" => BinaryOperator::Lte,
|
||||
"|" => BinaryOperator::Or,
|
||||
"&" => BinaryOperator::And,
|
||||
_ => {
|
||||
return Err(CompilationError::fatal(
|
||||
token.as_source_range(),
|
||||
@ -4330,6 +4332,20 @@ var baz = 2
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unary_not_on_keyword_bool() {
|
||||
let some_program_string = r#"!true"#;
|
||||
let module_id = ModuleId::default();
|
||||
let tokens = crate::parsing::token::lex(some_program_string, module_id).unwrap(); // Updated import path
|
||||
let actual = match unary_expression.parse(tokens.as_slice()) {
|
||||
// Use tokens.as_slice() for parsing
|
||||
Ok(x) => x,
|
||||
Err(e) => panic!("{e:?}"),
|
||||
};
|
||||
assert_eq!(actual.operator, UnaryOperator::Not);
|
||||
crate::parsing::top_level_parse(some_program_string).unwrap(); // Updated import path
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -4588,6 +4604,11 @@ my14 = 4 ^ 2 - 3 ^ 2 * 2
|
||||
r#"x = 3
|
||||
obj = { x, y: 4}"#
|
||||
);
|
||||
snapshot_test!(bj, "true");
|
||||
snapshot_test!(bk, "truee");
|
||||
snapshot_test!(bl, "x = !true");
|
||||
snapshot_test!(bm, "x = true & false");
|
||||
snapshot_test!(bn, "x = true | false");
|
||||
snapshot_test!(kw_function_unnamed_first, r#"val = foo(x, y = z)"#);
|
||||
snapshot_test!(kw_function_all_named, r#"val = foo(x = a, y = b)"#);
|
||||
snapshot_test!(kw_function_decl_all_labeled, r#"fn foo(x, y) { return 1 }"#);
|
||||
|
@ -0,0 +1,26 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
assertion_line: 4521
|
||||
expression: actual
|
||||
snapshot_kind: text
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 4,
|
||||
"expression": {
|
||||
"end": 4,
|
||||
"raw": "true",
|
||||
"start": 0,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 4,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
assertion_line: 4522
|
||||
expression: actual
|
||||
snapshot_kind: text
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 5,
|
||||
"expression": {
|
||||
"end": 5,
|
||||
"name": "truee",
|
||||
"start": 0,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 5,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
assertion_line: 4523
|
||||
expression: actual
|
||||
snapshot_kind: text
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 9,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"argument": {
|
||||
"end": 9,
|
||||
"raw": "true",
|
||||
"start": 5,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"end": 9,
|
||||
"operator": "!",
|
||||
"start": 4,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 9,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 9,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
assertion_line: 4524
|
||||
expression: actual
|
||||
snapshot_kind: text
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 16,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 16,
|
||||
"left": {
|
||||
"end": 8,
|
||||
"raw": "true",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 16,
|
||||
"raw": "false",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 4,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 16,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 16,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
assertion_line: 4525
|
||||
expression: actual
|
||||
snapshot_kind: text
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 16,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 16,
|
||||
"left": {
|
||||
"end": 8,
|
||||
"raw": "true",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 16,
|
||||
"raw": "false",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 4,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 16,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 16,
|
||||
"start": 0
|
||||
}
|
@ -187,7 +187,7 @@ fn word(i: &mut Input<'_>) -> PResult<Token> {
|
||||
|
||||
fn operator(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = alt((
|
||||
">=", "<=", "==", "=>", "!=", "|>", "*", "+", "-", "/", "%", "=", "<", ">", r"\", "|", "^",
|
||||
">=", "<=", "==", "=>", "!=", "|>", "*", "+", "-", "/", "%", "=", "<", ">", r"\", "^", "|", "&",
|
||||
))
|
||||
.with_span()
|
||||
.parse_next(i)?;
|
||||
@ -464,7 +464,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_operator() {
|
||||
for valid in [
|
||||
"+", "+ ", "-", "<=", "<= ", ">=", ">= ", "> ", "< ", "| ", "|> ", "^ ", "% ", "+* ",
|
||||
"+", "+ ", "-", "<=", "<= ", ">=", ">= ", "> ", "< ", "|> ", "^ ", "% ", "+* ", "| ", "& ",
|
||||
] {
|
||||
assert_parse_ok(operator, valid);
|
||||
}
|
||||
@ -750,4 +750,30 @@ const things = "things"
|
||||
}
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn test_boolean_literal() {
|
||||
let module_id = ModuleId::default();
|
||||
let actual = lex("true", module_id).unwrap();
|
||||
let expected = Token {
|
||||
token_type: TokenType::Keyword,
|
||||
value: "true".to_owned(),
|
||||
start: 0,
|
||||
end: 4,
|
||||
module_id,
|
||||
};
|
||||
assert_eq!(actual.tokens[0], expected);
|
||||
}
|
||||
#[test]
|
||||
fn test_word_starting_with_keyword() {
|
||||
let module_id = ModuleId::default();
|
||||
let actual = lex("truee", module_id).unwrap();
|
||||
let expected = Token {
|
||||
token_type: TokenType::Word,
|
||||
value: "truee".to_owned(),
|
||||
start: 0,
|
||||
end: 5,
|
||||
module_id,
|
||||
};
|
||||
assert_eq!(actual.tokens[0], expected);
|
||||
}
|
||||
}
|
||||
|
@ -1593,3 +1593,66 @@ mod kw_fn_with_defaults {
|
||||
super::execute(TEST_NAME, false).await
|
||||
}
|
||||
}
|
||||
mod boolean_logical_and {
|
||||
const TEST_NAME: &str = "boolean_logical_and";
|
||||
|
||||
/// Test parsing KCL.
|
||||
#[test]
|
||||
fn parse() {
|
||||
super::parse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that parsing and unparsing KCL produces the original KCL input.
|
||||
#[test]
|
||||
fn unparse() {
|
||||
super::unparse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that KCL is executed correctly.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn kcl_test_execute() {
|
||||
super::execute(TEST_NAME, false).await
|
||||
}
|
||||
}
|
||||
mod boolean_logical_or {
|
||||
const TEST_NAME: &str = "boolean_logical_or";
|
||||
|
||||
/// Test parsing KCL.
|
||||
#[test]
|
||||
fn parse() {
|
||||
super::parse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that parsing and unparsing KCL produces the original KCL input.
|
||||
#[test]
|
||||
fn unparse() {
|
||||
super::unparse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that KCL is executed correctly.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn kcl_test_execute() {
|
||||
super::execute(TEST_NAME, false).await
|
||||
}
|
||||
}
|
||||
mod boolean_logical_multiple {
|
||||
const TEST_NAME: &str = "boolean_logical_multiple";
|
||||
|
||||
/// Test parsing KCL.
|
||||
#[test]
|
||||
fn parse() {
|
||||
super::parse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that parsing and unparsing KCL produces the original KCL input.
|
||||
#[test]
|
||||
fn unparse() {
|
||||
super::unparse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that KCL is executed correctly.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn kcl_test_execute() {
|
||||
super::execute(TEST_NAME, false).await
|
||||
}
|
||||
}
|
||||
|
703
src/wasm-lib/kcl/tests/boolean_logical_and/ast.snap
Normal file
703
src/wasm-lib/kcl/tests/boolean_logical_and/ast.snap
Normal file
@ -0,0 +1,703 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Result of parsing boolean_logical_and.kcl
|
||||
---
|
||||
{
|
||||
"Ok": {
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 17,
|
||||
"id": {
|
||||
"end": 2,
|
||||
"name": "aa",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 17,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "true",
|
||||
"start": 5,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 17,
|
||||
"raw": "false",
|
||||
"start": 12,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 5,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 17,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 48,
|
||||
"id": {
|
||||
"end": 19,
|
||||
"name": "a",
|
||||
"start": 18,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 27,
|
||||
"name": "aa",
|
||||
"start": 25,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 48,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 46,
|
||||
"expression": {
|
||||
"end": 46,
|
||||
"raw": "2",
|
||||
"start": 45,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 45,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 47,
|
||||
"start": 45
|
||||
},
|
||||
"start": 22,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 33,
|
||||
"expression": {
|
||||
"end": 33,
|
||||
"raw": "1",
|
||||
"start": 32,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 32,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 34,
|
||||
"start": 32
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 18,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 48,
|
||||
"kind": "const",
|
||||
"start": 18,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 128,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 62,
|
||||
"left": {
|
||||
"end": 57,
|
||||
"name": "a",
|
||||
"start": 56,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 62,
|
||||
"raw": "2",
|
||||
"start": 61,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 56,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 127,
|
||||
"raw": "\"right branch of and is false makes the whole expression false\"",
|
||||
"start": 64,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "right branch of and is false makes the whole expression false"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 55,
|
||||
"name": "assert",
|
||||
"start": 49,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 128,
|
||||
"start": 49,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 49,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 147,
|
||||
"id": {
|
||||
"end": 132,
|
||||
"name": "bb",
|
||||
"start": 130,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 147,
|
||||
"left": {
|
||||
"end": 140,
|
||||
"raw": "false",
|
||||
"start": 135,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 147,
|
||||
"raw": "true",
|
||||
"start": 143,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"start": 135,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 130,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 147,
|
||||
"kind": "const",
|
||||
"start": 130,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 178,
|
||||
"id": {
|
||||
"end": 149,
|
||||
"name": "b",
|
||||
"start": 148,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 157,
|
||||
"name": "bb",
|
||||
"start": 155,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 178,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 176,
|
||||
"expression": {
|
||||
"end": 176,
|
||||
"raw": "2",
|
||||
"start": 175,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 175,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 177,
|
||||
"start": 175
|
||||
},
|
||||
"start": 152,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 163,
|
||||
"expression": {
|
||||
"end": 163,
|
||||
"raw": "1",
|
||||
"start": 162,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 162,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 164,
|
||||
"start": 162
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 148,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 178,
|
||||
"kind": "const",
|
||||
"start": 148,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 257,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 192,
|
||||
"left": {
|
||||
"end": 187,
|
||||
"name": "b",
|
||||
"start": 186,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 192,
|
||||
"raw": "2",
|
||||
"start": 191,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 186,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 256,
|
||||
"raw": "\"left branch of and is false makes the whole expression false\"",
|
||||
"start": 194,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "left branch of and is false makes the whole expression false"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 185,
|
||||
"name": "assert",
|
||||
"start": 179,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 257,
|
||||
"start": 179,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 179,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 275,
|
||||
"id": {
|
||||
"end": 261,
|
||||
"name": "cc",
|
||||
"start": 259,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 275,
|
||||
"left": {
|
||||
"end": 268,
|
||||
"raw": "true",
|
||||
"start": 264,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 275,
|
||||
"raw": "true",
|
||||
"start": 271,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"start": 264,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 259,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 275,
|
||||
"kind": "const",
|
||||
"start": 259,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 306,
|
||||
"id": {
|
||||
"end": 277,
|
||||
"name": "c",
|
||||
"start": 276,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 285,
|
||||
"name": "cc",
|
||||
"start": 283,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 306,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 304,
|
||||
"expression": {
|
||||
"end": 304,
|
||||
"raw": "2",
|
||||
"start": 303,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 303,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 305,
|
||||
"start": 303
|
||||
},
|
||||
"start": 280,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 291,
|
||||
"expression": {
|
||||
"end": 291,
|
||||
"raw": "1",
|
||||
"start": 290,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 290,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 292,
|
||||
"start": 290
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 276,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 306,
|
||||
"kind": "const",
|
||||
"start": 276,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 386,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 320,
|
||||
"left": {
|
||||
"end": 315,
|
||||
"name": "c",
|
||||
"start": 314,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 320,
|
||||
"raw": "1",
|
||||
"start": 319,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 314,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 385,
|
||||
"raw": "\"both branches of and are true makes the whole expression true\"",
|
||||
"start": 322,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "both branches of and are true makes the whole expression true"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 313,
|
||||
"name": "assert",
|
||||
"start": 307,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 386,
|
||||
"start": 307,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 307,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 406,
|
||||
"id": {
|
||||
"end": 390,
|
||||
"name": "dd",
|
||||
"start": 388,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 406,
|
||||
"left": {
|
||||
"end": 398,
|
||||
"raw": "false",
|
||||
"start": 393,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 406,
|
||||
"raw": "false",
|
||||
"start": 401,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 393,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 388,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 406,
|
||||
"kind": "const",
|
||||
"start": 388,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 437,
|
||||
"id": {
|
||||
"end": 408,
|
||||
"name": "d",
|
||||
"start": 407,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 416,
|
||||
"name": "dd",
|
||||
"start": 414,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 437,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 435,
|
||||
"expression": {
|
||||
"end": 435,
|
||||
"raw": "2",
|
||||
"start": 434,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 434,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 436,
|
||||
"start": 434
|
||||
},
|
||||
"start": 411,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 422,
|
||||
"expression": {
|
||||
"end": 422,
|
||||
"raw": "1",
|
||||
"start": 421,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 421,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 423,
|
||||
"start": 421
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 407,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 437,
|
||||
"kind": "const",
|
||||
"start": 407,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 519,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 451,
|
||||
"left": {
|
||||
"end": 446,
|
||||
"name": "d",
|
||||
"start": 445,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 451,
|
||||
"raw": "2",
|
||||
"start": 450,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 445,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 518,
|
||||
"raw": "\"both branches of and are false makes the whole expression false\"",
|
||||
"start": 453,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "both branches of and are false makes the whole expression false"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 444,
|
||||
"name": "assert",
|
||||
"start": 438,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 519,
|
||||
"start": 438,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 438,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 520,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"2": [
|
||||
{
|
||||
"end": 130,
|
||||
"start": 128,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "newLine"
|
||||
}
|
||||
}
|
||||
],
|
||||
"5": [
|
||||
{
|
||||
"end": 259,
|
||||
"start": 257,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "newLine"
|
||||
}
|
||||
}
|
||||
],
|
||||
"8": [
|
||||
{
|
||||
"end": 388,
|
||||
"start": 386,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "newLine"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 0
|
||||
}
|
||||
}
|
31
src/wasm-lib/kcl/tests/boolean_logical_and/input.kcl
Normal file
31
src/wasm-lib/kcl/tests/boolean_logical_and/input.kcl
Normal file
@ -0,0 +1,31 @@
|
||||
aa = true & false
|
||||
a = if aa {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(a == 2, "right branch of and is false makes the whole expression false")
|
||||
|
||||
bb = false & true
|
||||
b = if bb {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(b == 2, "left branch of and is false makes the whole expression false")
|
||||
|
||||
cc = true & true
|
||||
c = if cc {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(c == 1, "both branches of and are true makes the whole expression true")
|
||||
|
||||
dd = false & false
|
||||
d = if dd {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(d == 2, "both branches of and are false makes the whole expression false")
|
5
src/wasm-lib/kcl/tests/boolean_logical_and/ops.snap
Normal file
5
src/wasm-lib/kcl/tests/boolean_logical_and/ops.snap
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Operations executed boolean_logical_and.kcl
|
||||
---
|
||||
[]
|
167
src/wasm-lib/kcl/tests/boolean_logical_and/program_memory.snap
Normal file
167
src/wasm-lib/kcl/tests/boolean_logical_and/program_memory.snap
Normal file
@ -0,0 +1,167 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Program memory after executing boolean_logical_and.kcl
|
||||
---
|
||||
{
|
||||
"environments": [
|
||||
{
|
||||
"bindings": {
|
||||
"HALF_TURN": {
|
||||
"type": "Number",
|
||||
"value": 180.0,
|
||||
"__meta": []
|
||||
},
|
||||
"QUARTER_TURN": {
|
||||
"type": "Number",
|
||||
"value": 90.0,
|
||||
"__meta": []
|
||||
},
|
||||
"THREE_QUARTER_TURN": {
|
||||
"type": "Number",
|
||||
"value": 270.0,
|
||||
"__meta": []
|
||||
},
|
||||
"ZERO": {
|
||||
"type": "Number",
|
||||
"value": 0.0,
|
||||
"__meta": []
|
||||
},
|
||||
"a": {
|
||||
"type": "Number",
|
||||
"value": 2.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
45,
|
||||
46,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"aa": {
|
||||
"type": "Bool",
|
||||
"value": false,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
5,
|
||||
9,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
12,
|
||||
17,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"b": {
|
||||
"type": "Number",
|
||||
"value": 2.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
175,
|
||||
176,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"bb": {
|
||||
"type": "Bool",
|
||||
"value": false,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
135,
|
||||
140,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
143,
|
||||
147,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"c": {
|
||||
"type": "Number",
|
||||
"value": 1.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
290,
|
||||
291,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"cc": {
|
||||
"type": "Bool",
|
||||
"value": true,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
264,
|
||||
268,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
271,
|
||||
275,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"d": {
|
||||
"type": "Number",
|
||||
"value": 2.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
434,
|
||||
435,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dd": {
|
||||
"type": "Bool",
|
||||
"value": false,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
393,
|
||||
398,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
401,
|
||||
406,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"parent": null
|
||||
}
|
||||
],
|
||||
"currentEnv": 0,
|
||||
"return": null
|
||||
}
|
422
src/wasm-lib/kcl/tests/boolean_logical_multiple/ast.snap
Normal file
422
src/wasm-lib/kcl/tests/boolean_logical_multiple/ast.snap
Normal file
@ -0,0 +1,422 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Result of parsing boolean_logical_multiple.kcl
|
||||
---
|
||||
{
|
||||
"Ok": {
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 25,
|
||||
"id": {
|
||||
"end": 2,
|
||||
"name": "ii",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 25,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "true",
|
||||
"start": 5,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 25,
|
||||
"left": {
|
||||
"end": 17,
|
||||
"raw": "false",
|
||||
"start": 12,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 25,
|
||||
"raw": "false",
|
||||
"start": 20,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 12,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 5,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 25,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 56,
|
||||
"id": {
|
||||
"end": 27,
|
||||
"name": "i",
|
||||
"start": 26,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 35,
|
||||
"name": "ii",
|
||||
"start": 33,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 56,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 54,
|
||||
"expression": {
|
||||
"end": 54,
|
||||
"raw": "2",
|
||||
"start": 53,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 53,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 55,
|
||||
"start": 53
|
||||
},
|
||||
"start": 30,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 41,
|
||||
"expression": {
|
||||
"end": 41,
|
||||
"raw": "1",
|
||||
"start": 40,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 40,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 42,
|
||||
"start": 40
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 26,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 56,
|
||||
"kind": "const",
|
||||
"start": 26,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 108,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 70,
|
||||
"left": {
|
||||
"end": 65,
|
||||
"name": "i",
|
||||
"start": 64,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 70,
|
||||
"raw": "1",
|
||||
"start": 69,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 64,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 107,
|
||||
"raw": "\"and has higher precedence than or\"",
|
||||
"start": 72,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "and has higher precedence than or"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 63,
|
||||
"name": "assert",
|
||||
"start": 57,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 108,
|
||||
"start": 57,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 57,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 151,
|
||||
"id": {
|
||||
"end": 112,
|
||||
"name": "jj",
|
||||
"start": 110,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 151,
|
||||
"left": {
|
||||
"end": 136,
|
||||
"left": {
|
||||
"end": 120,
|
||||
"raw": "false",
|
||||
"start": 115,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 136,
|
||||
"left": {
|
||||
"end": 127,
|
||||
"raw": "true",
|
||||
"start": 123,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"argument": {
|
||||
"end": 136,
|
||||
"raw": "false",
|
||||
"start": 131,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"end": 136,
|
||||
"operator": "!",
|
||||
"start": 130,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
},
|
||||
"start": 123,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 115,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 151,
|
||||
"left": {
|
||||
"end": 144,
|
||||
"raw": "false",
|
||||
"start": 139,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 151,
|
||||
"raw": "true",
|
||||
"start": 147,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"start": 139,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 115,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 110,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 151,
|
||||
"kind": "const",
|
||||
"start": 110,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 182,
|
||||
"id": {
|
||||
"end": 153,
|
||||
"name": "j",
|
||||
"start": 152,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 161,
|
||||
"name": "jj",
|
||||
"start": 159,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 182,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 180,
|
||||
"expression": {
|
||||
"end": 180,
|
||||
"raw": "2",
|
||||
"start": 179,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 179,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 181,
|
||||
"start": 179
|
||||
},
|
||||
"start": 156,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 167,
|
||||
"expression": {
|
||||
"end": 167,
|
||||
"raw": "1",
|
||||
"start": 166,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 166,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 168,
|
||||
"start": 166
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 152,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 182,
|
||||
"kind": "const",
|
||||
"start": 152,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 227,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 196,
|
||||
"left": {
|
||||
"end": 191,
|
||||
"name": "j",
|
||||
"start": 190,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 196,
|
||||
"raw": "1",
|
||||
"start": 195,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 190,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 226,
|
||||
"raw": "\"multiple logical operators\"",
|
||||
"start": 198,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "multiple logical operators"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 189,
|
||||
"name": "assert",
|
||||
"start": 183,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 227,
|
||||
"start": 183,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 183,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 228,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"2": [
|
||||
{
|
||||
"end": 110,
|
||||
"start": 108,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "newLine"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 0
|
||||
}
|
||||
}
|
15
src/wasm-lib/kcl/tests/boolean_logical_multiple/input.kcl
Normal file
15
src/wasm-lib/kcl/tests/boolean_logical_multiple/input.kcl
Normal file
@ -0,0 +1,15 @@
|
||||
ii = true | false & false
|
||||
i = if ii {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(i == 1, "and has higher precedence than or")
|
||||
|
||||
jj = false | true & !false | false & true
|
||||
j = if jj {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(j == 1, "multiple logical operators")
|
5
src/wasm-lib/kcl/tests/boolean_logical_multiple/ops.snap
Normal file
5
src/wasm-lib/kcl/tests/boolean_logical_multiple/ops.snap
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Operations executed boolean_logical_multiple.kcl
|
||||
---
|
||||
[]
|
@ -0,0 +1,129 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Program memory after executing boolean_logical_multiple.kcl
|
||||
---
|
||||
{
|
||||
"environments": [
|
||||
{
|
||||
"bindings": {
|
||||
"HALF_TURN": {
|
||||
"type": "Number",
|
||||
"value": 180.0,
|
||||
"__meta": []
|
||||
},
|
||||
"QUARTER_TURN": {
|
||||
"type": "Number",
|
||||
"value": 90.0,
|
||||
"__meta": []
|
||||
},
|
||||
"THREE_QUARTER_TURN": {
|
||||
"type": "Number",
|
||||
"value": 270.0,
|
||||
"__meta": []
|
||||
},
|
||||
"ZERO": {
|
||||
"type": "Number",
|
||||
"value": 0.0,
|
||||
"__meta": []
|
||||
},
|
||||
"i": {
|
||||
"type": "Number",
|
||||
"value": 1.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
40,
|
||||
41,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"ii": {
|
||||
"type": "Bool",
|
||||
"value": true,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
5,
|
||||
9,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
12,
|
||||
17,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
20,
|
||||
25,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"j": {
|
||||
"type": "Number",
|
||||
"value": 1.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
166,
|
||||
167,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"jj": {
|
||||
"type": "Bool",
|
||||
"value": true,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
115,
|
||||
120,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
123,
|
||||
127,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
130,
|
||||
136,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
139,
|
||||
144,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
147,
|
||||
151,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"parent": null
|
||||
}
|
||||
],
|
||||
"currentEnv": 0,
|
||||
"return": null
|
||||
}
|
703
src/wasm-lib/kcl/tests/boolean_logical_or/ast.snap
Normal file
703
src/wasm-lib/kcl/tests/boolean_logical_or/ast.snap
Normal file
@ -0,0 +1,703 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Result of parsing boolean_logical_or.kcl
|
||||
---
|
||||
{
|
||||
"Ok": {
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 17,
|
||||
"id": {
|
||||
"end": 2,
|
||||
"name": "aa",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 17,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "true",
|
||||
"start": 5,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 17,
|
||||
"raw": "false",
|
||||
"start": 12,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 5,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 17,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 48,
|
||||
"id": {
|
||||
"end": 19,
|
||||
"name": "a",
|
||||
"start": 18,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 27,
|
||||
"name": "aa",
|
||||
"start": 25,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 48,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 46,
|
||||
"expression": {
|
||||
"end": 46,
|
||||
"raw": "2",
|
||||
"start": 45,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 45,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 47,
|
||||
"start": 45
|
||||
},
|
||||
"start": 22,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 33,
|
||||
"expression": {
|
||||
"end": 33,
|
||||
"raw": "1",
|
||||
"start": 32,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 32,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 34,
|
||||
"start": 32
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 18,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 48,
|
||||
"kind": "const",
|
||||
"start": 18,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 124,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 62,
|
||||
"left": {
|
||||
"end": 57,
|
||||
"name": "a",
|
||||
"start": 56,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 62,
|
||||
"raw": "1",
|
||||
"start": 61,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 56,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 123,
|
||||
"raw": "\"left branch of or is true makes the whole expression true\"",
|
||||
"start": 64,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "left branch of or is true makes the whole expression true"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 55,
|
||||
"name": "assert",
|
||||
"start": 49,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 124,
|
||||
"start": 49,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 49,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 143,
|
||||
"id": {
|
||||
"end": 128,
|
||||
"name": "bb",
|
||||
"start": 126,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 143,
|
||||
"left": {
|
||||
"end": 136,
|
||||
"raw": "false",
|
||||
"start": 131,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 143,
|
||||
"raw": "true",
|
||||
"start": 139,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"start": 131,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 126,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 143,
|
||||
"kind": "const",
|
||||
"start": 126,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 174,
|
||||
"id": {
|
||||
"end": 145,
|
||||
"name": "b",
|
||||
"start": 144,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 153,
|
||||
"name": "bb",
|
||||
"start": 151,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 174,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 172,
|
||||
"expression": {
|
||||
"end": 172,
|
||||
"raw": "2",
|
||||
"start": 171,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 171,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 173,
|
||||
"start": 171
|
||||
},
|
||||
"start": 148,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 159,
|
||||
"expression": {
|
||||
"end": 159,
|
||||
"raw": "1",
|
||||
"start": 158,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 158,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 160,
|
||||
"start": 158
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 144,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 174,
|
||||
"kind": "const",
|
||||
"start": 144,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 251,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 188,
|
||||
"left": {
|
||||
"end": 183,
|
||||
"name": "b",
|
||||
"start": 182,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 188,
|
||||
"raw": "1",
|
||||
"start": 187,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 182,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 250,
|
||||
"raw": "\"right branch of or is true makes the whole expression true\"",
|
||||
"start": 190,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "right branch of or is true makes the whole expression true"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 181,
|
||||
"name": "assert",
|
||||
"start": 175,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 251,
|
||||
"start": 175,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 175,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 269,
|
||||
"id": {
|
||||
"end": 255,
|
||||
"name": "cc",
|
||||
"start": 253,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 269,
|
||||
"left": {
|
||||
"end": 262,
|
||||
"raw": "true",
|
||||
"start": 258,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 269,
|
||||
"raw": "true",
|
||||
"start": 265,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"start": 258,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 253,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 269,
|
||||
"kind": "const",
|
||||
"start": 253,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 300,
|
||||
"id": {
|
||||
"end": 271,
|
||||
"name": "c",
|
||||
"start": 270,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 279,
|
||||
"name": "cc",
|
||||
"start": 277,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 300,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 298,
|
||||
"expression": {
|
||||
"end": 298,
|
||||
"raw": "2",
|
||||
"start": 297,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 297,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 299,
|
||||
"start": 297
|
||||
},
|
||||
"start": 274,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 285,
|
||||
"expression": {
|
||||
"end": 285,
|
||||
"raw": "1",
|
||||
"start": 284,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 284,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 286,
|
||||
"start": 284
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 270,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 300,
|
||||
"kind": "const",
|
||||
"start": 270,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 379,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 314,
|
||||
"left": {
|
||||
"end": 309,
|
||||
"name": "c",
|
||||
"start": 308,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 314,
|
||||
"raw": "1",
|
||||
"start": 313,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 308,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 378,
|
||||
"raw": "\"both branches of or are true makes the whole expression true\"",
|
||||
"start": 316,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "both branches of or are true makes the whole expression true"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 307,
|
||||
"name": "assert",
|
||||
"start": 301,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 379,
|
||||
"start": 301,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 301,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 399,
|
||||
"id": {
|
||||
"end": 383,
|
||||
"name": "dd",
|
||||
"start": 381,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 399,
|
||||
"left": {
|
||||
"end": 391,
|
||||
"raw": "false",
|
||||
"start": 386,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 399,
|
||||
"raw": "false",
|
||||
"start": 394,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 386,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 381,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 399,
|
||||
"kind": "const",
|
||||
"start": 381,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 430,
|
||||
"id": {
|
||||
"end": 401,
|
||||
"name": "d",
|
||||
"start": 400,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 409,
|
||||
"name": "dd",
|
||||
"start": 407,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 430,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 428,
|
||||
"expression": {
|
||||
"end": 428,
|
||||
"raw": "2",
|
||||
"start": 427,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 427,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 429,
|
||||
"start": 427
|
||||
},
|
||||
"start": 404,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 415,
|
||||
"expression": {
|
||||
"end": 415,
|
||||
"raw": "1",
|
||||
"start": 414,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 1.0
|
||||
},
|
||||
"start": 414,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 416,
|
||||
"start": 414
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 400,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 430,
|
||||
"kind": "const",
|
||||
"start": 400,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 511,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 444,
|
||||
"left": {
|
||||
"end": 439,
|
||||
"name": "d",
|
||||
"start": 438,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 444,
|
||||
"raw": "2",
|
||||
"start": 443,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": 2.0
|
||||
},
|
||||
"start": 438,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 510,
|
||||
"raw": "\"both branches of or are false makes the whole expression false\"",
|
||||
"start": 446,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "both branches of or are false makes the whole expression false"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 437,
|
||||
"name": "assert",
|
||||
"start": 431,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 511,
|
||||
"start": 431,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 431,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 512,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"2": [
|
||||
{
|
||||
"end": 126,
|
||||
"start": 124,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "newLine"
|
||||
}
|
||||
}
|
||||
],
|
||||
"5": [
|
||||
{
|
||||
"end": 253,
|
||||
"start": 251,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "newLine"
|
||||
}
|
||||
}
|
||||
],
|
||||
"8": [
|
||||
{
|
||||
"end": 381,
|
||||
"start": 379,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "newLine"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 0
|
||||
}
|
||||
}
|
31
src/wasm-lib/kcl/tests/boolean_logical_or/input.kcl
Normal file
31
src/wasm-lib/kcl/tests/boolean_logical_or/input.kcl
Normal file
@ -0,0 +1,31 @@
|
||||
aa = true | false
|
||||
a = if aa {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(a == 1, "left branch of or is true makes the whole expression true")
|
||||
|
||||
bb = false | true
|
||||
b = if bb {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(b == 1, "right branch of or is true makes the whole expression true")
|
||||
|
||||
cc = true | true
|
||||
c = if cc {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(c == 1, "both branches of or are true makes the whole expression true")
|
||||
|
||||
dd = false | false
|
||||
d = if dd {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
assert(d == 2, "both branches of or are false makes the whole expression false")
|
5
src/wasm-lib/kcl/tests/boolean_logical_or/ops.snap
Normal file
5
src/wasm-lib/kcl/tests/boolean_logical_or/ops.snap
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Operations executed boolean_logical_or.kcl
|
||||
---
|
||||
[]
|
167
src/wasm-lib/kcl/tests/boolean_logical_or/program_memory.snap
Normal file
167
src/wasm-lib/kcl/tests/boolean_logical_or/program_memory.snap
Normal file
@ -0,0 +1,167 @@
|
||||
---
|
||||
source: kcl/src/simulation_tests.rs
|
||||
description: Program memory after executing boolean_logical_or.kcl
|
||||
---
|
||||
{
|
||||
"environments": [
|
||||
{
|
||||
"bindings": {
|
||||
"HALF_TURN": {
|
||||
"type": "Number",
|
||||
"value": 180.0,
|
||||
"__meta": []
|
||||
},
|
||||
"QUARTER_TURN": {
|
||||
"type": "Number",
|
||||
"value": 90.0,
|
||||
"__meta": []
|
||||
},
|
||||
"THREE_QUARTER_TURN": {
|
||||
"type": "Number",
|
||||
"value": 270.0,
|
||||
"__meta": []
|
||||
},
|
||||
"ZERO": {
|
||||
"type": "Number",
|
||||
"value": 0.0,
|
||||
"__meta": []
|
||||
},
|
||||
"a": {
|
||||
"type": "Number",
|
||||
"value": 1.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
32,
|
||||
33,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"aa": {
|
||||
"type": "Bool",
|
||||
"value": true,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
5,
|
||||
9,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
12,
|
||||
17,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"b": {
|
||||
"type": "Number",
|
||||
"value": 1.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
158,
|
||||
159,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"bb": {
|
||||
"type": "Bool",
|
||||
"value": true,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
131,
|
||||
136,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
139,
|
||||
143,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"c": {
|
||||
"type": "Number",
|
||||
"value": 1.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
284,
|
||||
285,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"cc": {
|
||||
"type": "Bool",
|
||||
"value": true,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
258,
|
||||
262,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
265,
|
||||
269,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"d": {
|
||||
"type": "Number",
|
||||
"value": 2.0,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
427,
|
||||
428,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dd": {
|
||||
"type": "Bool",
|
||||
"value": false,
|
||||
"__meta": [
|
||||
{
|
||||
"sourceRange": [
|
||||
386,
|
||||
391,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"sourceRange": [
|
||||
394,
|
||||
399,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"parent": null
|
||||
}
|
||||
],
|
||||
"currentEnv": 0,
|
||||
"return": null
|
||||
}
|
Reference in New Issue
Block a user