diff --git a/crates/fuse-parser/tests/cases/pass/if-expression-04/ast.snap b/crates/fuse-parser/tests/cases/pass/if-expression-04/ast.snap new file mode 100644 index 0000000..82c7a23 --- /dev/null +++ b/crates/fuse-parser/tests/cases/pass/if-expression-04/ast.snap @@ -0,0 +1,132 @@ +--- +source: crates/fuse-parser/tests/cases/mod.rs +expression: parsed.chunk +input_file: crates/fuse-parser/tests/cases/pass/if-expression-04/case.fuse +--- +Some(Chunk( + span: Span( + start: 0, + end: 71, + ), + body: Block( + statements: [ + Expression(If(If( + span: Span( + start: 0, + end: 70, + ), + cond: BinaryOperator(BinaryOperator( + kind: LogicalOr(Span( + start: 5, + end: 7, + )), + lhs: Identifier(Identifier( + span: Span( + start: 3, + end: 4, + ), + name: Atom("x"), + )), + rhs: BinaryOperator(BinaryOperator( + kind: LogicalAnd(Span( + start: 10, + end: 13, + )), + lhs: Identifier(Identifier( + span: Span( + start: 8, + end: 9, + ), + name: Atom("y"), + )), + rhs: Identifier(Identifier( + span: Span( + start: 14, + end: 15, + ), + name: Atom("z"), + )), + )), + )), + body: Block( + statements: [ + Expression(NumberLiteral(NumberLiteral( + span: Span( + start: 23, + end: 26, + ), + raw: Atom("123"), + value: 123.0, + kind: Decimal, + ))), + ], + ), + else: Some(If(If( + span: Span( + start: 27, + end: 70, + ), + cond: BinaryOperator(BinaryOperator( + kind: LogicalOr(Span( + start: 42, + end: 44, + )), + lhs: BinaryOperator(BinaryOperator( + kind: LogicalAnd(Span( + start: 36, + end: 39, + )), + lhs: Identifier(Identifier( + span: Span( + start: 34, + end: 35, + ), + name: Atom("x"), + )), + rhs: Identifier(Identifier( + span: Span( + start: 40, + end: 41, + ), + name: Atom("y"), + )), + )), + rhs: Identifier(Identifier( + span: Span( + start: 45, + end: 46, + ), + name: Atom("z"), + )), + )), + body: Block( + statements: [ + Expression(NumberLiteral(NumberLiteral( + span: Span( + start: 54, + end: 57, + ), + raw: Atom("321"), + value: 321.0, + kind: Decimal, + ))), + ], + ), + else: Some(Block(Block( + statements: [ + Expression(NumberLiteral(NumberLiteral( + span: Span( + start: 65, + end: 66, + ), + raw: Atom("0"), + value: 0.0, + kind: Decimal, + ))), + ], + ))), + ))), + ))), + ], + ), +)) diff --git a/crates/fuse-parser/tests/cases/pass/if-expression-04/case.fuse b/crates/fuse-parser/tests/cases/pass/if-expression-04/case.fuse new file mode 100644 index 0000000..c251ae2 --- /dev/null +++ b/crates/fuse-parser/tests/cases/pass/if-expression-04/case.fuse @@ -0,0 +1,7 @@ +if x or y and z then + 123 +elseif x and y or z then + 321 +else + 0 +end diff --git a/crates/fuse-parser/tests/cases/pass/if-expression-04/tokens.snap b/crates/fuse-parser/tests/cases/pass/if-expression-04/tokens.snap new file mode 100644 index 0000000..fabbc19 --- /dev/null +++ b/crates/fuse-parser/tests/cases/pass/if-expression-04/tokens.snap @@ -0,0 +1,368 @@ +--- +source: crates/fuse-parser/tests/cases/mod.rs +expression: tokens +input_file: crates/fuse-parser/tests/cases/pass/if-expression-04/case.fuse +--- +[ + TokenReference( + token: Token( + span: Span( + start: 0, + end: 2, + ), + kind: If, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 2, + end: 3, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 3, + end: 4, + ), + kind: Identifier, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 4, + end: 5, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 5, + end: 7, + ), + kind: Or, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 7, + end: 8, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 8, + end: 9, + ), + kind: Identifier, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 9, + end: 10, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 10, + end: 13, + ), + kind: And, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 13, + end: 14, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 14, + end: 15, + ), + kind: Identifier, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 15, + end: 16, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 16, + end: 20, + ), + kind: Then, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 20, + end: 23, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 23, + end: 26, + ), + kind: NumberLiteral, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 26, + end: 27, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 27, + end: 33, + ), + kind: ElseIf, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 33, + end: 34, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 34, + end: 35, + ), + kind: Identifier, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 35, + end: 36, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 36, + end: 39, + ), + kind: And, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 39, + end: 40, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 40, + end: 41, + ), + kind: Identifier, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 41, + end: 42, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 42, + end: 44, + ), + kind: Or, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 44, + end: 45, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 45, + end: 46, + ), + kind: Identifier, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 46, + end: 47, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 47, + end: 51, + ), + kind: Then, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 51, + end: 54, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 54, + end: 57, + ), + kind: NumberLiteral, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 57, + end: 58, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 58, + end: 62, + ), + kind: Else, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 62, + end: 65, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 65, + end: 66, + ), + kind: NumberLiteral, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 66, + end: 67, + ), + kind: Whitespace, + ), + ], + ), + TokenReference( + token: Token( + span: Span( + start: 67, + end: 70, + ), + kind: End, + ), + leading_trivia: [], + trailing_trivia: [ + Token( + span: Span( + start: 70, + end: 71, + ), + kind: Whitespace, + ), + ], + ), +]