diff --git a/kclvm/parser/src/parser/tests.rs b/kclvm/parser/src/parser/tests.rs index e83a43cf2..f4f9e3c2c 100644 --- a/kclvm/parser/src/parser/tests.rs +++ b/kclvm/parser/src/parser/tests.rs @@ -10,895 +10,50 @@ use regex::Regex; use std::path::PathBuf; use std::sync::Arc; -fn check_parsing_expr(src: &str, expect: Expect) { - let sm = SourceMap::new(FilePathMapping::empty()); - let sf = sm.new_source_file(PathBuf::from("").into(), src.to_string()); - let sess = &ParseSession::with_source_map(Arc::new(sm)); - - match sf.src.as_ref() { - Some(src_from_sf) => { - create_session_globals_then(|| { - let stream = parse_token_streams(sess, src_from_sf.as_str(), new_byte_pos(0)); - let mut parser = Parser::new(sess, stream); - let expr = parser.parse_expr(); - let actual = format!("{expr:?}\n"); - expect.assert_eq(&actual) - }); - } - None => todo!(), - }; -} - -fn check_parsing_file_ast_json(filename: &str, src: &str, expect: Expect) { - let m = crate::parse_file_with_global_session( - Arc::new(ParseSession::default()), - filename, - Some(src.into()), - ) - .unwrap(); - let actual = serde_json::ser::to_string(&m).unwrap(); - let actual = format!("{actual}\n"); - expect.assert_eq(&actual) -} - -fn check_parsing_type(src: &str, expect: Expect) { - let sm = SourceMap::new(FilePathMapping::empty()); - sm.new_source_file(PathBuf::from("").into(), src.to_string()); - let sess = &ParseSession::with_source_map(Arc::new(sm)); - - create_session_globals_then(|| { - let stream = parse_token_streams(sess, src, new_byte_pos(0)); - let mut parser = Parser::new(sess, stream); - let typ = parser.parse_type_annotation(); - let actual = format!("{typ:?}\n"); - expect.assert_eq(&actual) - }); -} - -fn check_type_str(src: &str, expect: Expect) { - let sm = SourceMap::new(FilePathMapping::empty()); - sm.new_source_file(PathBuf::from("").into(), src.to_string()); - let sess = &ParseSession::with_source_map(Arc::new(sm)); - - create_session_globals_then(|| { - let stream = parse_token_streams(sess, src, new_byte_pos(0)); - let mut parser = Parser::new(sess, stream); - let typ = parser.parse_type_annotation(); - let actual = typ.node.to_string(); - expect.assert_eq(&actual) - }); -} - -fn check_parsing_module(filename: &str, src: &str, expect: &str) { - let m = crate::parse_file(filename, Some(src.to_string())).expect(filename); - let actual = format!("{}\n", serde_json::ser::to_string(&m).unwrap()); - assert_eq!(actual.trim(), expect.trim()); -} - -#[test] -fn smoke_test_parsing_expr() { - check_parsing_expr( - "1\n", - expect![[r#" - Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 } - "#]], - ); - check_parsing_expr( - "\"1\"\n", - expect![[r#" - Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"1\"", value: "1" }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } - "#]], - ); -} - -#[test] -fn named_literal_expr() { - check_parsing_expr( - r####"Undefined"####, - expect![[r#" - Node { node: NameConstantLit(NameConstantLit { value: Undefined }), filename: "", line: 1, column: 0, end_line: 1, end_column: 9 } - "#]], - ); - check_parsing_expr( - r####"None"####, - expect![[r#" - Node { node: NameConstantLit(NameConstantLit { value: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } - "#]], - ); - ( - r####"True"####, - expect![[r#" - Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 1, column: 1, end_line: 1, end_column: 1 } - "#]], - ); - check_parsing_expr( - r####"False"####, - expect![[r#" - Node { node: NameConstantLit(NameConstantLit { value: False }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn nonstring_literal_expr() { - check_parsing_expr( - r####"1234"####, - expect![[r#" - Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1234) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } - "#]], - ) -} - -#[test] -fn string_literal_expr_0() { - check_parsing_expr( - r####"'1234'"####, - expect![[r#" - Node { node: StringLit(StringLit { is_long_string: false, raw_value: "'1234'", value: "1234" }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ) -} - -#[test] -fn string_literal_expr_1() { - check_parsing_expr( - r####""1234""####, - expect![[r#" - Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"1234\"", value: "1234" }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ) -} - -#[test] -fn string_literal_expr_2() { - check_parsing_expr( - r####""1234\n""####, - expect![[r#" - Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"1234\\n\"", value: "1234\n" }), filename: "", line: 1, column: 0, end_line: 1, end_column: 8 } - "#]], - ) -} - -#[test] -fn number_bin_suffix_expr() { - check_parsing_expr( - r####"1234Ki"####, - expect![[r#" - Node { node: NumberLit(NumberLit { binary_suffix: Some(Ki), value: Int(1234) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ) -} - -#[test] -fn unary_expr() { - check_parsing_expr( - r####"+1"####, - expect![[r#" - Node { node: Unary(UnaryExpr { op: UAdd, operand: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 2 } - "#]], - ); -} - -#[test] -fn binary_expr_0() { - check_parsing_expr( - r####"1+2+3"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn binary_expr_1() { - check_parsing_expr( - r####"1+2*3-4"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, op: Bin(Add), right: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }, op: Bin(Mul), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 2, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }, op: Bin(Sub), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(4) }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn binary_expr_2() { - check_parsing_expr( - r####"1+2*3/4"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, op: Bin(Add), right: Node { node: Binary(BinaryExpr { left: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }, op: Bin(Mul), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 2, end_line: 1, end_column: 5 }, op: Bin(Div), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(4) }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 2, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn binary_expr_3() { - check_parsing_expr( - r####"a or b"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, op: Bin(Or), right: Node { node: Identifier(Identifier { names: [Node { node: "b", filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn binary_expr_4() { - check_parsing_expr( - r####"x == a or b"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, ops: [Eq], comparators: [Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 11 }, op: Bin(Or), right: Node { node: Identifier(Identifier { names: [Node { node: "b", filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 10, end_line: 1, end_column: 11 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 11 } - "#]], - ); - check_parsing_expr( - r####"22 > 11 and 111 < 222"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Compare(Compare { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(22) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 2 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(11) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 7 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 21 }, op: Bin(And), right: Node { node: Compare(Compare { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(111) }), filename: "", line: 1, column: 12, end_line: 1, end_column: 15 }, ops: [Lt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(222) }), filename: "", line: 1, column: 18, end_line: 1, end_column: 21 }] }), filename: "", line: 1, column: 12, end_line: 1, end_column: 21 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 21 } - "#]], - ); - check_parsing_expr( - r####"int(e.value) > 1 and i == 0"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Compare(Compare { left: Node { node: Call(CallExpr { func: Node { node: Identifier(Identifier { names: [Node { node: "int", filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, args: [Node { node: Identifier(Identifier { names: [Node { node: "e", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, Node { node: "value", filename: "", line: 1, column: 6, end_line: 1, end_column: 11 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 11 }], keywords: [] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 12 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 15, end_line: 1, end_column: 16 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 27 }, op: Bin(And), right: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "i", filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }, ops: [Eq], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 26, end_line: 1, end_column: 27 }] }), filename: "", line: 1, column: 21, end_line: 1, end_column: 27 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 27 } - "#]], - ); - check_parsing_expr( - r####"key in ['key']"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "key", filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, ops: [In], comparators: [Node { node: List(ListExpr { elts: [Node { node: StringLit(StringLit { is_long_string: false, raw_value: "'key'", value: "key" }), filename: "", line: 1, column: 8, end_line: 1, end_column: 13 }], ctx: Load }), filename: "", line: 1, column: 7, end_line: 1, end_column: 14 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 } - "#]], - ); - check_parsing_expr( - r####"key not in ['key']"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "key", filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, ops: [NotIn], comparators: [Node { node: List(ListExpr { elts: [Node { node: StringLit(StringLit { is_long_string: false, raw_value: "'key'", value: "key" }), filename: "", line: 1, column: 12, end_line: 1, end_column: 17 }], ctx: Load }), filename: "", line: 1, column: 11, end_line: 1, end_column: 18 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 18 } - "#]], - ); - - check_parsing_expr( - r####"1 is 1 and 11 is not 22"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Compare(Compare { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, ops: [Is], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 23 }, op: Bin(And), right: Node { node: Compare(Compare { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(11) }), filename: "", line: 1, column: 11, end_line: 1, end_column: 13 }, ops: [IsNot], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(22) }), filename: "", line: 1, column: 21, end_line: 1, end_column: 23 }] }), filename: "", line: 1, column: 11, end_line: 1, end_column: 23 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 23 } - "#]], - ); -} - -#[test] -fn binary_expr_5() { - check_parsing_expr( - r####"1 + a and b"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, op: Bin(Add), right: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }, op: Bin(And), right: Node { node: Identifier(Identifier { names: [Node { node: "b", filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 10, end_line: 1, end_column: 11 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 11 } - "#]], - ); -} - -#[test] -fn binary_expr_with_paren() { - check_parsing_expr( - r####"1*(2+3)-4"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, op: Bin(Mul), right: Node { node: Paren(ParenExpr { expr: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 3, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 2, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 }, op: Bin(Sub), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(4) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 9 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 9 } - "#]], - ); -} - -#[test] -fn logic_expr_0() { - check_parsing_expr( - r####"0 < a < 100"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, ops: [Lt, Lt], comparators: [Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(100) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 11 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 11 } - "#]], - ); - check_parsing_expr( - r####"0 < a < 100 + a"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, ops: [Lt, Lt], comparators: [Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(100) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 11 }, op: Bin(Add), right: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 14, end_line: 1, end_column: 15 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 14, end_line: 1, end_column: 15 } }), filename: "", line: 1, column: 8, end_line: 1, end_column: 15 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 15 } - "#]], - ); - check_parsing_expr( - r####"100 > a > 0"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(100) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, ops: [Gt, Gt], comparators: [Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 11 } - "#]], - ); - check_parsing_expr( - r####"100 + a > a > 0"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(100) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, op: Bin(Add), right: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 }, ops: [Gt, Gt], comparators: [Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 14, end_line: 1, end_column: 15 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 15 } - "#]], - ); -} - -#[test] -fn logic_expr_1() { - check_parsing_expr( - r####"a is b"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, ops: [Is], comparators: [Node { node: Identifier(Identifier { names: [Node { node: "b", filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); - check_parsing_expr( - r####"a is not True"####, - expect![[r#" - Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, ops: [IsNot], comparators: [Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 1, column: 9, end_line: 1, end_column: 13 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 13 } - "#]], - ); - check_parsing_expr( - r####"not False or a > 0 and b is True"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: Unary(UnaryExpr { op: Not, operand: Node { node: NameConstantLit(NameConstantLit { value: False }), filename: "", line: 1, column: 4, end_line: 1, end_column: 9 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 9 }, op: Bin(Or), right: Node { node: Binary(BinaryExpr { left: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 13, end_line: 1, end_column: 14 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 13, end_line: 1, end_column: 14 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 17, end_line: 1, end_column: 18 }] }), filename: "", line: 1, column: 13, end_line: 1, end_column: 32 }, op: Bin(And), right: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "b", filename: "", line: 1, column: 23, end_line: 1, end_column: 24 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 23, end_line: 1, end_column: 24 }, ops: [Is], comparators: [Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 1, column: 28, end_line: 1, end_column: 32 }] }), filename: "", line: 1, column: 23, end_line: 1, end_column: 32 } }), filename: "", line: 1, column: 13, end_line: 1, end_column: 32 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 32 } - "#]], - ); -} - -#[test] -fn if_expr() { - check_parsing_expr( - r####"1 if true else 2"####, - expect![[r#" - Node { node: If(IfExpr { body: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, cond: Node { node: Identifier(Identifier { names: [Node { node: "true", filename: "", line: 1, column: 5, end_line: 1, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 5, end_line: 1, end_column: 9 }, orelse: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 15, end_line: 1, end_column: 16 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 16 } - "#]], - ); -} - -#[test] -fn primary_expr_0() { - check_parsing_expr( - r####"a.b.c"####, - expect![[r#" - Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, Node { node: "b", filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }, Node { node: "c", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn primary_expr_1() { - check_parsing_expr( - r####"'{}'.format(1)"####, - expect![[r#" - Node { node: Call(CallExpr { func: Node { node: Selector(SelectorExpr { value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "'{}'", value: "{}" }), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 }, attr: Node { node: Identifier { names: [Node { node: "format", filename: "", line: 1, column: 5, end_line: 1, end_column: 11 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 5, end_line: 1, end_column: 11 }, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 11 }, args: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 12, end_line: 1, end_column: 13 }], keywords: [] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 } - "#]], - ); -} - -#[test] -fn primary_expr_2() { - check_parsing_expr( - r####"str(1).isdigit()"####, - expect![[r#" - Node { node: Call(CallExpr { func: Node { node: Selector(SelectorExpr { value: Node { node: Call(CallExpr { func: Node { node: Identifier(Identifier { names: [Node { node: "str", filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, args: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], keywords: [] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }, attr: Node { node: Identifier { names: [Node { node: "isdigit", filename: "", line: 1, column: 7, end_line: 1, end_column: 14 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 14 }, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 }, args: [], keywords: [] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 16 } - "#]], - ); -} - -#[test] -fn list_expr() { - check_parsing_expr( - r####"[1, 2, 3]"####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 9 } - "#]], - ); - - check_parsing_expr( - r####"[1, if True: 2, 3]"####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, Node { node: ListIfItem(ListIfItemExpr { if_cond: Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 1, column: 7, end_line: 1, end_column: 11 }, exprs: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 13, end_line: 1, end_column: 14 }], orelse: None }), filename: "", line: 1, column: 4, end_line: 1, end_column: 14 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 16, end_line: 1, end_column: 17 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 18 } - "#]], - ); -} - -#[test] -fn list_comp_expr_0() { - check_parsing_expr( - r####"[x ** 2 for x in [1, 2, 3]]"####, - expect![[r#" - Node { node: ListComp(ListComp { elt: Node { node: Binary(BinaryExpr { left: Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, op: Bin(Pow), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 1, end_line: 1, end_column: 7 }, generators: [Node { node: CompClause { targets: [Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 12, end_line: 1, end_column: 13 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 12, end_line: 1, end_column: 13 }], iter: Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 18, end_line: 1, end_column: 19 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 24, end_line: 1, end_column: 25 }], ctx: Load }), filename: "", line: 1, column: 17, end_line: 1, end_column: 26 }, ifs: [] }, filename: "", line: 1, column: 8, end_line: 1, end_column: 26 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 27 } - "#]], - ); -} - -#[test] -fn list_comp_expr_1() { - check_parsing_expr( - r####"[i for i in [1, 2, 3] if i > 2]"####, - expect![[r#" - Node { node: ListComp(ListComp { elt: Node { node: Identifier(Identifier { names: [Node { node: "i", filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, generators: [Node { node: CompClause { targets: [Node { node: Identifier { names: [Node { node: "i", filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], iter: Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 13, end_line: 1, end_column: 14 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 16, end_line: 1, end_column: 17 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 19, end_line: 1, end_column: 20 }], ctx: Load }), filename: "", line: 1, column: 12, end_line: 1, end_column: 21 }, ifs: [Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "i", filename: "", line: 1, column: 25, end_line: 1, end_column: 26 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 25, end_line: 1, end_column: 26 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 29, end_line: 1, end_column: 30 }] }), filename: "", line: 1, column: 25, end_line: 1, end_column: 30 }] }, filename: "", line: 1, column: 3, end_line: 1, end_column: 30 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 31 } - "#]], - ); -} - -#[test] -fn dict_expr() { - check_parsing_expr( - r####"{k0=v0, k1=v1}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k0", filename: "", line: 1, column: 1, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 3 }), value: Node { node: Identifier(Identifier { names: [Node { node: "v0", filename: "", line: 1, column: 4, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 6 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 1, end_line: 1, end_column: 6 }, Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k1", filename: "", line: 1, column: 8, end_line: 1, end_column: 10 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 8, end_line: 1, end_column: 10 }), value: Node { node: Identifier(Identifier { names: [Node { node: "v1", filename: "", line: 1, column: 11, end_line: 1, end_column: 13 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 11, end_line: 1, end_column: 13 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 8, end_line: 1, end_column: 13 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 } - "#]], - ); -} - -#[test] -fn dict_comp_expr() { - check_parsing_expr( - r####"{k: v + 1 for k, v in {k1 = 1, k2 = 2}}"####, - expect![[r#" - Node { node: DictComp(DictComp { entry: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k", filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }), value: Node { node: Binary(BinaryExpr { left: Node { node: Identifier(Identifier { names: [Node { node: "v", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 9 } }), filename: "", line: 1, column: 4, end_line: 1, end_column: 9 }, operation: Union, insert_index: -1 }, generators: [Node { node: CompClause { targets: [Node { node: Identifier { names: [Node { node: "k", filename: "", line: 1, column: 14, end_line: 1, end_column: 15 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 14, end_line: 1, end_column: 15 }, Node { node: Identifier { names: [Node { node: "v", filename: "", line: 1, column: 17, end_line: 1, end_column: 18 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 17, end_line: 1, end_column: 18 }], iter: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k1", filename: "", line: 1, column: 23, end_line: 1, end_column: 25 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 23, end_line: 1, end_column: 25 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 28, end_line: 1, end_column: 29 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 23, end_line: 1, end_column: 29 }, Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k2", filename: "", line: 1, column: 31, end_line: 1, end_column: 33 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 31, end_line: 1, end_column: 33 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 36, end_line: 1, end_column: 37 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 31, end_line: 1, end_column: 37 }] }), filename: "", line: 1, column: 22, end_line: 1, end_column: 38 }, ifs: [] }, filename: "", line: 1, column: 10, end_line: 1, end_column: 38 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 39 } - "#]], - ); -} - -#[test] -fn subscript_expr_0() { - check_parsing_expr( - r####"a[0]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), lower: None, upper: None, step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } - "#]], - ); -} - -#[test] -fn subscript_expr_1() { - check_parsing_expr( - r####"b["k"]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "b", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"k\"", value: "k" }), filename: "", line: 1, column: 2, end_line: 1, end_column: 5 }), lower: None, upper: None, step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn subscript_expr_2() { - check_parsing_expr( - r####"c?[1]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "c", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }), lower: None, upper: None, step: None, ctx: Load, has_question: true }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn subscript_expr_3() { - check_parsing_expr( - r####"a[1:]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), upper: None, step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn subscript_expr_4() { - check_parsing_expr( - r####"a[:-1]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: None, upper: Some(Node { node: Unary(UnaryExpr { op: USub, operand: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 3, end_line: 1, end_column: 5 }), step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn subscript_expr_5() { - check_parsing_expr( - r####"a[1:len]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), upper: Some(Node { node: Identifier(Identifier { names: [Node { node: "len", filename: "", line: 1, column: 4, end_line: 1, end_column: 7 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 7 }), step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 8 } - "#]], - ); -} - -#[test] -fn subscript_expr_6() { - check_parsing_expr( - r####"a[0:-1]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), upper: Some(Node { node: Unary(UnaryExpr { op: USub, operand: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 4, end_line: 1, end_column: 6 }), step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn subscript_expr_7() { - check_parsing_expr( - r####"a[::]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: None, upper: None, step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn subscript_expr_8() { - check_parsing_expr( - r####"a[1::]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), upper: None, step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn subscript_expr_9() { - check_parsing_expr( - r####"a[:0:]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: None, upper: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }), step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn subscript_expr_10() { - check_parsing_expr( - r####"a[::-1]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: None, upper: None, step: Some(Node { node: Unary(UnaryExpr { op: USub, operand: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 4, end_line: 1, end_column: 6 }), ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn subscript_expr_11() { - check_parsing_expr( - r####"a[1::2]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), upper: None, step: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }), ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn subscript_expr_12() { - check_parsing_expr( - r####"a[:2:1]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: None, upper: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }), step: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }), ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn subscript_expr_13() { - check_parsing_expr( - r####"a[1:2:]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), upper: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }), step: None, ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn subscript_expr_14() { - check_parsing_expr( - r####"a[1:3:1]"####, - expect![[r#" - Node { node: Subscript(Subscript { value: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, index: None, lower: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), upper: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }), step: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }), ctx: Load, has_question: false }), filename: "", line: 1, column: 0, end_line: 1, end_column: 8 } - "#]], - ); -} - -#[test] -fn call_expr_0() { - check_parsing_expr( - r####"func0()"####, - expect![[r#" - Node { node: Call(CallExpr { func: Node { node: Identifier(Identifier { names: [Node { node: "func0", filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }, args: [], keywords: [] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn call_expr_1() { - check_parsing_expr( - r####"func1(1)"####, - expect![[r#" - Node { node: Call(CallExpr { func: Node { node: Identifier(Identifier { names: [Node { node: "func1", filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }, args: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }], keywords: [] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 8 } - "#]], - ); -} - -#[test] -fn call_expr_2() { - check_parsing_expr( - r####"func2(x=2)"####, - expect![[r#" - Node { node: Call(CallExpr { func: Node { node: Identifier(Identifier { names: [Node { node: "func2", filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }, args: [], keywords: [Node { node: Keyword { arg: Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }, value: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 9 }) }, filename: "", line: 1, column: 6, end_line: 1, end_column: 9 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 10 } - "#]], - ); -} - -#[test] -fn call_expr_3() { - check_parsing_expr( - r####"func3(1,x=2)"####, - expect![[r#" - Node { node: Call(CallExpr { func: Node { node: Identifier(Identifier { names: [Node { node: "func3", filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 }, args: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }], keywords: [Node { node: Keyword { arg: Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 8, end_line: 1, end_column: 9 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 8, end_line: 1, end_column: 9 }, value: Some(Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }) }, filename: "", line: 1, column: 8, end_line: 1, end_column: 11 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 12 } - "#]], - ); -} - -#[test] -fn quant_expr_0() { - check_parsing_expr( - r####"all x in collection {x > 0}"####, - expect![[r#" - Node { node: Quant(QuantExpr { target: Node { node: Identifier(Identifier { names: [Node { node: "collection", filename: "", line: 1, column: 9, end_line: 1, end_column: 19 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 9, end_line: 1, end_column: 19 }, variables: [Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], op: All, test: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 25, end_line: 1, end_column: 26 }] }), filename: "", line: 1, column: 21, end_line: 1, end_column: 26 }, if_cond: None, ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 27 } - "#]], - ); -} - -#[test] -fn quant_expr_1() { - check_parsing_expr( - r####"any y in collection {y < 0}"####, - expect![[r#" - Node { node: Quant(QuantExpr { target: Node { node: Identifier(Identifier { names: [Node { node: "collection", filename: "", line: 1, column: 9, end_line: 1, end_column: 19 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 9, end_line: 1, end_column: 19 }, variables: [Node { node: Identifier { names: [Node { node: "y", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], op: Any, test: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "y", filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }, ops: [Lt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 25, end_line: 1, end_column: 26 }] }), filename: "", line: 1, column: 21, end_line: 1, end_column: 26 }, if_cond: None, ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 27 } - "#]], - ); -} - -#[test] -fn quant_expr_2() { - check_parsing_expr( - r####"map x in collection {x + 1}"####, - expect![[r#" - Node { node: Quant(QuantExpr { target: Node { node: Identifier(Identifier { names: [Node { node: "collection", filename: "", line: 1, column: 9, end_line: 1, end_column: 19 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 9, end_line: 1, end_column: 19 }, variables: [Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], op: Map, test: Node { node: Binary(BinaryExpr { left: Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 21, end_line: 1, end_column: 22 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 25, end_line: 1, end_column: 26 } }), filename: "", line: 1, column: 21, end_line: 1, end_column: 26 }, if_cond: None, ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 27 } - "#]], - ); -} - -#[test] -fn quant_expr_3() { - check_parsing_expr( - r####"filter x in collection {x > 1}"####, - expect![[r#" - Node { node: Quant(QuantExpr { target: Node { node: Identifier(Identifier { names: [Node { node: "collection", filename: "", line: 1, column: 12, end_line: 1, end_column: 22 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 12, end_line: 1, end_column: 22 }, variables: [Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], op: Filter, test: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 1, column: 24, end_line: 1, end_column: 25 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 24, end_line: 1, end_column: 25 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 28, end_line: 1, end_column: 29 }] }), filename: "", line: 1, column: 24, end_line: 1, end_column: 29 }, if_cond: None, ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 30 } - "#]], - ); -} - -#[test] -fn quant_expr_4() { - check_parsing_expr( - r####"filter x in collection {x > 1}"####, - expect![[r#" - Node { node: Quant(QuantExpr { target: Node { node: Identifier(Identifier { names: [Node { node: "collection", filename: "", line: 1, column: 12, end_line: 1, end_column: 22 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 12, end_line: 1, end_column: 22 }, variables: [Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], op: Filter, test: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 1, column: 24, end_line: 1, end_column: 25 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 24, end_line: 1, end_column: 25 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 28, end_line: 1, end_column: 29 }] }), filename: "", line: 1, column: 24, end_line: 1, end_column: 29 }, if_cond: None, ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 30 } - "#]], - ); -} - -#[test] -fn quant_expr_5() { - check_parsing_expr( - r####"map i, e in [{k1 = "v1", k2 = "v2"}] { e }"####, - expect![[r#" - Node { node: Quant(QuantExpr { target: Node { node: List(ListExpr { elts: [Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k1", filename: "", line: 1, column: 14, end_line: 1, end_column: 16 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 14, end_line: 1, end_column: 16 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"v1\"", value: "v1" }), filename: "", line: 1, column: 19, end_line: 1, end_column: 23 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 14, end_line: 1, end_column: 23 }, Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k2", filename: "", line: 1, column: 25, end_line: 1, end_column: 27 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 25, end_line: 1, end_column: 27 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"v2\"", value: "v2" }), filename: "", line: 1, column: 30, end_line: 1, end_column: 34 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 25, end_line: 1, end_column: 34 }] }), filename: "", line: 1, column: 13, end_line: 1, end_column: 35 }], ctx: Load }), filename: "", line: 1, column: 12, end_line: 1, end_column: 36 }, variables: [Node { node: Identifier { names: [Node { node: "i", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, Node { node: Identifier { names: [Node { node: "e", filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], op: Map, test: Node { node: Identifier(Identifier { names: [Node { node: "e", filename: "", line: 1, column: 39, end_line: 1, end_column: 40 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 39, end_line: 1, end_column: 40 }, if_cond: None, ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 42 } - "#]], - ); -} - -#[test] -fn quant_expr_6() { - check_parsing_expr( - r####"map i, e in [{k1 = "v1", k2 = "v2"}] { e if i > 0 }"####, - expect![[r#" - Node { node: Quant(QuantExpr { target: Node { node: List(ListExpr { elts: [Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k1", filename: "", line: 1, column: 14, end_line: 1, end_column: 16 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 14, end_line: 1, end_column: 16 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"v1\"", value: "v1" }), filename: "", line: 1, column: 19, end_line: 1, end_column: 23 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 14, end_line: 1, end_column: 23 }, Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k2", filename: "", line: 1, column: 25, end_line: 1, end_column: 27 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 25, end_line: 1, end_column: 27 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"v2\"", value: "v2" }), filename: "", line: 1, column: 30, end_line: 1, end_column: 34 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 25, end_line: 1, end_column: 34 }] }), filename: "", line: 1, column: 13, end_line: 1, end_column: 35 }], ctx: Load }), filename: "", line: 1, column: 12, end_line: 1, end_column: 36 }, variables: [Node { node: Identifier { names: [Node { node: "i", filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, Node { node: Identifier { names: [Node { node: "e", filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], op: Map, test: Node { node: Identifier(Identifier { names: [Node { node: "e", filename: "", line: 1, column: 39, end_line: 1, end_column: 40 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 39, end_line: 1, end_column: 40 }, if_cond: Some(Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "i", filename: "", line: 1, column: 44, end_line: 1, end_column: 45 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 44, end_line: 1, end_column: 45 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(0) }), filename: "", line: 1, column: 48, end_line: 1, end_column: 49 }] }), filename: "", line: 1, column: 44, end_line: 1, end_column: 49 }), ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 51 } - "#]], - ); -} - -#[test] -fn lambda_expr_0() { - check_parsing_expr( - r####"lambda {}"####, - expect![[r#" - Node { node: Lambda(LambdaExpr { args: None, return_type_str: None, body: [], return_ty: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 9 } - "#]], - ); -} - -#[test] -fn lambda_expr_1() { - check_parsing_expr( - r####"lambda x {}"####, - expect![[r#" - Node { node: Lambda(LambdaExpr { args: Some(Node { node: Arguments { args: [Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], defaults: [None], type_annotation_list: [None], ty_list: [None] }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }), return_type_str: None, body: [], return_ty: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 11 } - "#]], - ); -} - -#[test] -fn lambda_expr_2() { - check_parsing_expr( - r####"lambda x: int -> int {x}"####, - expect![[r#" - Node { node: Lambda(LambdaExpr { args: Some(Node { node: Arguments { args: [Node { node: Identifier { names: [Node { node: "x", filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 7, end_line: 1, end_column: 8 }], defaults: [None], type_annotation_list: [Some(Node { node: "int", filename: "", line: 1, column: 10, end_line: 1, end_column: 13 })], ty_list: [Some(Node { node: Basic(Int), filename: "", line: 1, column: 10, end_line: 1, end_column: 13 })] }, filename: "", line: 1, column: 7, end_line: 1, end_column: 13 }), return_type_str: Some("int"), body: [Node { node: Expr(ExprStmt { exprs: [Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 1, column: 22, end_line: 1, end_column: 23 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 22, end_line: 1, end_column: 23 }] }), filename: "", line: 1, column: 22, end_line: 1, end_column: 23 }], return_ty: Some(Node { node: Basic(Int), filename: "", line: 1, column: 17, end_line: 1, end_column: 20 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 24 } - "#]], - ); -} - -#[test] -fn lambda_expr_3() { - check_parsing_expr( - r####"lambda { - if True: - _a = 1 - else: - _a = 2 - _a -}"####, - expect![[r#" - Node { node: Lambda(LambdaExpr { args: None, return_type_str: None, body: [Node { node: If(IfStmt { body: [Node { node: Assign(AssignStmt { targets: [Node { node: Identifier { names: [Node { node: "_a", filename: "", line: 3, column: 8, end_line: 3, end_column: 10 }], pkgpath: "", ctx: Store }, filename: "", line: 3, column: 8, end_line: 3, end_column: 10 }], value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 3, column: 13, end_line: 3, end_column: 14 }, type_annotation: None, ty: None }), filename: "", line: 3, column: 8, end_line: 3, end_column: 14 }], cond: Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 2, column: 7, end_line: 2, end_column: 11 }, orelse: [Node { node: Assign(AssignStmt { targets: [Node { node: Identifier { names: [Node { node: "_a", filename: "", line: 5, column: 8, end_line: 5, end_column: 10 }], pkgpath: "", ctx: Store }, filename: "", line: 5, column: 8, end_line: 5, end_column: 10 }], value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 5, column: 13, end_line: 5, end_column: 14 }, type_annotation: None, ty: None }), filename: "", line: 5, column: 8, end_line: 5, end_column: 14 }] }), filename: "", line: 2, column: 4, end_line: 6, end_column: 4 }, Node { node: Expr(ExprStmt { exprs: [Node { node: Identifier(Identifier { names: [Node { node: "_a", filename: "", line: 6, column: 4, end_line: 6, end_column: 6 }], pkgpath: "", ctx: Load }), filename: "", line: 6, column: 4, end_line: 6, end_column: 6 }] }), filename: "", line: 6, column: 4, end_line: 6, end_column: 6 }], return_ty: None }), filename: "", line: 1, column: 0, end_line: 7, end_column: 1 } - "#]], - ); -} - -#[test] -fn config_expr_0() { - check_parsing_expr( - r####"{ - "name" = { - "name": "alice" - }, - "gender" = "female" -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"name\"", value: "name" }), filename: "", line: 2, column: 4, end_line: 2, end_column: 10 }), value: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"name\"", value: "name" }), filename: "", line: 3, column: 8, end_line: 3, end_column: 14 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"alice\"", value: "alice" }), filename: "", line: 3, column: 16, end_line: 3, end_column: 23 }, operation: Union, insert_index: -1 }, filename: "", line: 3, column: 8, end_line: 3, end_column: 23 }] }), filename: "", line: 2, column: 13, end_line: 4, end_column: 5 }, operation: Override, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 4, end_column: 5 }, Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"gender\"", value: "gender" }), filename: "", line: 5, column: 4, end_line: 5, end_column: 12 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"female\"", value: "female" }), filename: "", line: 5, column: 15, end_line: 5, end_column: 23 }, operation: Override, insert_index: -1 }, filename: "", line: 5, column: 4, end_line: 5, end_column: 23 }] }), filename: "", line: 1, column: 0, end_line: 6, end_column: 1 } - "#]], - ); -} - -#[test] -fn config_expr_1() { - check_parsing_expr( - r####"{ - "name" = { - "name": "alice" - } - "gender" = "female", -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"name\"", value: "name" }), filename: "", line: 2, column: 4, end_line: 2, end_column: 10 }), value: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"name\"", value: "name" }), filename: "", line: 3, column: 8, end_line: 3, end_column: 14 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"alice\"", value: "alice" }), filename: "", line: 3, column: 16, end_line: 3, end_column: 23 }, operation: Union, insert_index: -1 }, filename: "", line: 3, column: 8, end_line: 3, end_column: 23 }] }), filename: "", line: 2, column: 13, end_line: 4, end_column: 5 }, operation: Override, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 4, end_column: 5 }, Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"gender\"", value: "gender" }), filename: "", line: 5, column: 4, end_line: 5, end_column: 12 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"female\"", value: "female" }), filename: "", line: 5, column: 15, end_line: 5, end_column: 23 }, operation: Override, insert_index: -1 }, filename: "", line: 5, column: 4, end_line: 5, end_column: 23 }] }), filename: "", line: 1, column: 0, end_line: 6, end_column: 1 } - "#]], - ); -} - -#[test] -fn config_expr_2() { - check_parsing_expr( - r####"{ - "name" = { - "name": "alice", - } - "gender" = "female" -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"name\"", value: "name" }), filename: "", line: 2, column: 4, end_line: 2, end_column: 10 }), value: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"name\"", value: "name" }), filename: "", line: 3, column: 8, end_line: 3, end_column: 14 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"alice\"", value: "alice" }), filename: "", line: 3, column: 16, end_line: 3, end_column: 23 }, operation: Union, insert_index: -1 }, filename: "", line: 3, column: 8, end_line: 3, end_column: 23 }] }), filename: "", line: 2, column: 13, end_line: 4, end_column: 5 }, operation: Override, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 4, end_column: 5 }, Node { node: ConfigEntry { key: Some(Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"gender\"", value: "gender" }), filename: "", line: 5, column: 4, end_line: 5, end_column: 12 }), value: Node { node: StringLit(StringLit { is_long_string: false, raw_value: "\"female\"", value: "female" }), filename: "", line: 5, column: 15, end_line: 5, end_column: 23 }, operation: Override, insert_index: -1 }, filename: "", line: 5, column: 4, end_line: 5, end_column: 23 }] }), filename: "", line: 1, column: 0, end_line: 6, end_column: 1 } - "#]], - ); -} - -#[test] -fn config_if_expr_0() { - check_parsing_expr( - r####"{ - if True: - a = 1 -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: None, value: Node { node: ConfigIfEntry(ConfigIfEntryExpr { if_cond: Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 2, column: 7, end_line: 2, end_column: 11 }, items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 3, column: 8, end_line: 3, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 3, column: 8, end_line: 3, end_column: 9 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 3, column: 12, end_line: 3, end_column: 13 }, operation: Override, insert_index: -1 }, filename: "", line: 3, column: 8, end_line: 3, end_column: 13 }], orelse: None }), filename: "", line: 2, column: 4, end_line: 4, end_column: 0 }, operation: Union, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 4, end_column: 0 }] }), filename: "", line: 1, column: 0, end_line: 4, end_column: 1 } - "#]], - ); -} - -#[test] -fn config_if_expr_1() { - check_parsing_expr( - r####"{ - if True: - a = 1 - else: - a = 2 -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: None, value: Node { node: ConfigIfEntry(ConfigIfEntryExpr { if_cond: Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 2, column: 7, end_line: 2, end_column: 11 }, items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 3, column: 8, end_line: 3, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 3, column: 8, end_line: 3, end_column: 9 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 3, column: 12, end_line: 3, end_column: 13 }, operation: Override, insert_index: -1 }, filename: "", line: 3, column: 8, end_line: 3, end_column: 13 }], orelse: Some(Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 5, column: 8, end_line: 5, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 5, column: 8, end_line: 5, end_column: 9 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 5, column: 12, end_line: 5, end_column: 13 }, operation: Override, insert_index: -1 }, filename: "", line: 5, column: 8, end_line: 5, end_column: 13 }] }), filename: "", line: 4, column: 4, end_line: 6, end_column: 0 }) }), filename: "", line: 2, column: 4, end_line: 6, end_column: 0 }, operation: Union, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 6, end_column: 0 }] }), filename: "", line: 1, column: 0, end_line: 6, end_column: 1 } - "#]], - ); -} - -#[test] -fn config_if_expr_2() { - check_parsing_expr( - r####"{ - if True: - a = 1 - elif x > 1: - a = 2 - else: - a = 3 -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: None, value: Node { node: ConfigIfEntry(ConfigIfEntryExpr { if_cond: Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 2, column: 7, end_line: 2, end_column: 11 }, items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 3, column: 8, end_line: 3, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 3, column: 8, end_line: 3, end_column: 9 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 3, column: 12, end_line: 3, end_column: 13 }, operation: Override, insert_index: -1 }, filename: "", line: 3, column: 8, end_line: 3, end_column: 13 }], orelse: Some(Node { node: ConfigIfEntry(ConfigIfEntryExpr { if_cond: Node { node: Compare(Compare { left: Node { node: Identifier(Identifier { names: [Node { node: "x", filename: "", line: 4, column: 9, end_line: 4, end_column: 10 }], pkgpath: "", ctx: Load }), filename: "", line: 4, column: 9, end_line: 4, end_column: 10 }, ops: [Gt], comparators: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 4, column: 13, end_line: 4, end_column: 14 }] }), filename: "", line: 4, column: 9, end_line: 4, end_column: 14 }, items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 5, column: 8, end_line: 5, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 5, column: 8, end_line: 5, end_column: 9 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 5, column: 12, end_line: 5, end_column: 13 }, operation: Override, insert_index: -1 }, filename: "", line: 5, column: 8, end_line: 5, end_column: 13 }], orelse: Some(Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 7, column: 8, end_line: 7, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 7, column: 8, end_line: 7, end_column: 9 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 7, column: 12, end_line: 7, end_column: 13 }, operation: Override, insert_index: -1 }, filename: "", line: 7, column: 8, end_line: 7, end_column: 13 }] }), filename: "", line: 6, column: 4, end_line: 8, end_column: 0 }) }), filename: "", line: 4, column: 4, end_line: 6, end_column: 4 }) }), filename: "", line: 2, column: 4, end_line: 8, end_column: 0 }, operation: Union, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 8, end_column: 0 }] }), filename: "", line: 1, column: 0, end_line: 8, end_column: 1 } - "#]], - ); -} - -#[test] -fn config_if_expr_3() { - check_parsing_expr( - r####"{ - if True: - if False: - a = 1 -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: None, value: Node { node: ConfigIfEntry(ConfigIfEntryExpr { if_cond: Node { node: NameConstantLit(NameConstantLit { value: True }), filename: "", line: 2, column: 7, end_line: 2, end_column: 11 }, items: [Node { node: ConfigEntry { key: None, value: Node { node: ConfigIfEntry(ConfigIfEntryExpr { if_cond: Node { node: NameConstantLit(NameConstantLit { value: False }), filename: "", line: 3, column: 11, end_line: 3, end_column: 16 }, items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 4, column: 12, end_line: 4, end_column: 13 }], pkgpath: "", ctx: Load }), filename: "", line: 4, column: 12, end_line: 4, end_column: 13 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 4, column: 16, end_line: 4, end_column: 17 }, operation: Override, insert_index: -1 }, filename: "", line: 4, column: 12, end_line: 4, end_column: 17 }], orelse: None }), filename: "", line: 3, column: 8, end_line: 5, end_column: 0 }, operation: Override, insert_index: -1 }, filename: "", line: 3, column: 8, end_line: 5, end_column: 0 }], orelse: None }), filename: "", line: 2, column: 4, end_line: 5, end_column: 0 }, operation: Union, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 5, end_column: 0 }] }), filename: "", line: 1, column: 0, end_line: 5, end_column: 1 } - "#]], - ); -} - -#[test] -fn schema_expr_0() { - check_parsing_expr( - r####"Schema {}"####, - expect![[r#" - Node { node: Schema(SchemaExpr { name: Node { node: Identifier { names: [Node { node: "Schema", filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }, args: [], kwargs: [], config: Node { node: Config(ConfigExpr { items: [] }), filename: "", line: 1, column: 7, end_line: 1, end_column: 9 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 9 } - "#]], - ); +fn check_parsing_file_ast_json(filename: &str, src: &str, expect: Expect) { + let m = crate::parse_file_with_global_session( + Arc::new(ParseSession::default()), + filename, + Some(src.into()), + ) + .unwrap(); + let actual = serde_json::ser::to_string(&m).unwrap(); + let actual = format!("{actual}\n"); + expect.assert_eq(&actual) } -#[test] -fn schema_expr_1() { - check_parsing_expr( - r####"Schema {k=v}"####, - expect![[r#" - Node { node: Schema(SchemaExpr { name: Node { node: Identifier { names: [Node { node: "Schema", filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }, args: [], kwargs: [], config: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k", filename: "", line: 1, column: 8, end_line: 1, end_column: 9 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 8, end_line: 1, end_column: 9 }), value: Node { node: Identifier(Identifier { names: [Node { node: "v", filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 10, end_line: 1, end_column: 11 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 8, end_line: 1, end_column: 11 }] }), filename: "", line: 1, column: 7, end_line: 1, end_column: 12 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 12 } - "#]], - ); -} +fn check_parsing_type(src: &str, expect: Expect) { + let sm = SourceMap::new(FilePathMapping::empty()); + sm.new_source_file(PathBuf::from("").into(), src.to_string()); + let sess = &ParseSession::with_source_map(Arc::new(sm)); -#[test] -fn schema_expr_2() { - check_parsing_expr( - r####"Schema () {k=v}"####, - expect![[r#" - Node { node: Schema(SchemaExpr { name: Node { node: Identifier { names: [Node { node: "Schema", filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }, args: [], kwargs: [], config: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k", filename: "", line: 1, column: 11, end_line: 1, end_column: 12 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 11, end_line: 1, end_column: 12 }), value: Node { node: Identifier(Identifier { names: [Node { node: "v", filename: "", line: 1, column: 13, end_line: 1, end_column: 14 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 13, end_line: 1, end_column: 14 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 11, end_line: 1, end_column: 14 }] }), filename: "", line: 1, column: 10, end_line: 1, end_column: 15 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 15 } - "#]], - ); + create_session_globals_then(|| { + let stream = parse_token_streams(sess, src, new_byte_pos(0)); + let mut parser = Parser::new(sess, stream); + let typ = parser.parse_type_annotation(); + let actual = format!("{typ:?}\n"); + expect.assert_eq(&actual) + }); } -#[test] -fn schema_expr_3() { - check_parsing_expr( - r####"Schema (1, 2) {k=v}"####, - expect![[r#" - Node { node: Schema(SchemaExpr { name: Node { node: Identifier { names: [Node { node: "Schema", filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }, args: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 9 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 11, end_line: 1, end_column: 12 }], kwargs: [], config: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k", filename: "", line: 1, column: 15, end_line: 1, end_column: 16 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 15, end_line: 1, end_column: 16 }), value: Node { node: Identifier(Identifier { names: [Node { node: "v", filename: "", line: 1, column: 17, end_line: 1, end_column: 18 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 17, end_line: 1, end_column: 18 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 15, end_line: 1, end_column: 18 }] }), filename: "", line: 1, column: 14, end_line: 1, end_column: 19 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 19 } - "#]], - ); -} +fn check_type_str(src: &str, expect: Expect) { + let sm = SourceMap::new(FilePathMapping::empty()); + sm.new_source_file(PathBuf::from("").into(), src.to_string()); + let sess = &ParseSession::with_source_map(Arc::new(sm)); -#[test] -fn schema_expr_4() { - check_parsing_expr( - r####"Schema (1, 2) { - k=v -}"####, - expect![[r#" - Node { node: Schema(SchemaExpr { name: Node { node: Identifier { names: [Node { node: "Schema", filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }, filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }, args: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 9 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 11, end_line: 1, end_column: 12 }], kwargs: [], config: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "k", filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }), value: Node { node: Identifier(Identifier { names: [Node { node: "v", filename: "", line: 2, column: 6, end_line: 2, end_column: 7 }], pkgpath: "", ctx: Load }), filename: "", line: 2, column: 6, end_line: 2, end_column: 7 }, operation: Override, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 2, end_column: 7 }] }), filename: "", line: 1, column: 14, end_line: 3, end_column: 1 } }), filename: "", line: 1, column: 0, end_line: 3, end_column: 1 } - "#]], - ); + create_session_globals_then(|| { + let stream = parse_token_streams(sess, src, new_byte_pos(0)); + let mut parser = Parser::new(sess, stream); + let typ = parser.parse_type_annotation(); + let actual = typ.node.to_string(); + expect.assert_eq(&actual) + }); } -#[test] -fn line_continue() { - check_parsing_expr( - r####"1 + \ -2 -"####, - expect![[r#" - Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 2, column: 0, end_line: 2, end_column: 1 } }), filename: "", line: 1, column: 0, end_line: 2, end_column: 1 } - "#]], - ); +fn check_parsing_module(filename: &str, src: &str, expect: &str) { + let m = crate::parse_file(filename, Some(src.to_string())).expect(filename); + let actual = format!("{}\n", serde_json::ser::to_string(&m).unwrap()); + assert_eq!(actual.trim(), expect.trim()); } #[test] @@ -1131,22 +286,6 @@ schema TestBool: ); } -#[test] -fn test_parse_joined_string() { - check_parsing_expr( - r####"'${123+200}'"####, - expect![[r#" - Node { node: JoinedString(JoinedString { is_long_string: false, values: [Node { node: FormattedValue(FormattedValue { is_long_string: false, value: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(123) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 6 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(200) }), filename: "", line: 1, column: 7, end_line: 1, end_column: 10 } }), filename: "", line: 1, column: 3, end_line: 1, end_column: 10 }, format_spec: None }), filename: "", line: 1, column: 3, end_line: 1, end_column: 10 }], raw_value: "'${123+200}'" }), filename: "", line: 1, column: 0, end_line: 1, end_column: 12 } - "#]], - ); - check_parsing_expr( - r####"'abc${a+1}cde'"####, - expect![[r#" - Node { node: JoinedString(JoinedString { is_long_string: false, values: [Node { node: StringLit(StringLit { is_long_string: false, raw_value: "abc", value: "abc" }), filename: "", line: 1, column: 1, end_line: 1, end_column: 1 }, Node { node: FormattedValue(FormattedValue { is_long_string: false, value: Node { node: Binary(BinaryExpr { left: Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 6, end_line: 1, end_column: 7 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 1, column: 8, end_line: 1, end_column: 9 } }), filename: "", line: 1, column: 6, end_line: 1, end_column: 9 }, format_spec: None }), filename: "", line: 1, column: 6, end_line: 1, end_column: 9 }, Node { node: StringLit(StringLit { is_long_string: false, raw_value: "cde", value: "cde" }), filename: "", line: 1, column: 1, end_line: 1, end_column: 1 }], raw_value: "'abc${a+1}cde'" }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 } - "#]], - ); -} - #[test] fn test_parse_assign_stmt() { check_parsing_file_ast_json( @@ -1236,230 +375,6 @@ fn test_parse_file() { } } -#[test] -fn expr_with_paren1() { - check_parsing_expr( - r####"(2+3)"####, - expect![[r#" - Node { node: Paren(ParenExpr { expr: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 } }), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn expr_with_paren2() { - check_parsing_expr( - r####"((2+3)"####, - expect![[r#" - Node { node: Paren(ParenExpr { expr: Node { node: Paren(ParenExpr { expr: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 2, end_line: 1, end_column: 5 } }), filename: "", line: 1, column: 1, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn expr_with_paren3() { - check_parsing_expr( - r####"(2+3))"####, - expect![[r#" - Node { node: Paren(ParenExpr { expr: Node { node: Binary(BinaryExpr { left: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, op: Bin(Add), right: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 } }), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn expr_with_bracket1() { - check_parsing_expr( - r####"[2,3]"####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn expr_with_bracket2() { - check_parsing_expr( - r####"[[2,3]"####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 6 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn expr_with_bracket3() { - check_parsing_expr( - r####"[2,3]]"####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn expr_with_bracket4() { - check_parsing_expr( - r####"[2,3"####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(3) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } - "#]], - ); -} - -#[test] -fn expr_with_bracket5() { - check_parsing_expr( - r####"["####, - expect![[r#" - Node { node: List(ListExpr { elts: [], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 } - "#]], - ); -} - -#[test] -fn expr_with_bracket6() { - check_parsing_expr( - r####"[ - 1 - 2, -] - "####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 3, column: 4, end_line: 3, end_column: 5 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 4, end_column: 1 } - "#]], - ); -} - -#[test] -fn expr_with_bracket7() { - check_parsing_expr( - r####"[ - 1,2, -] - "####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 2, column: 6, end_line: 2, end_column: 7 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 3, end_column: 1 } - "#]], - ); -} - -#[test] -fn expr_with_bracket8() { - check_parsing_expr( - r####"[ - 1,2, - - "####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }, Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 2, column: 6, end_line: 2, end_column: 7 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 4, end_column: 8 } - "#]], - ); -} - -#[test] -fn expr_with_brace1() { - check_parsing_expr( - r####"{a=2}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn expr_with_brace2() { - check_parsing_expr( - r####"{a=2}}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 3, end_line: 1, end_column: 4 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); -} - -#[test] -fn expr_with_delim1() { - check_parsing_expr( - r####"({a=2}"####, - expect![[r#" - Node { node: Paren(ParenExpr { expr: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 2, end_line: 1, end_column: 5 }] }), filename: "", line: 1, column: 1, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn expr_with_delim2() { - check_parsing_expr( - r####"({a=(2}"####, - expect![[r#" - Node { node: Paren(ParenExpr { expr: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), value: Node { node: Paren(ParenExpr { expr: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 } }), filename: "", line: 1, column: 4, end_line: 1, end_column: 7 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 2, end_line: 1, end_column: 7 }] }), filename: "", line: 1, column: 1, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn expr_with_delim3() { - check_parsing_expr( - r####"{a=[2]"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 1, end_line: 1, end_column: 2 }), value: Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }], ctx: Load }), filename: "", line: 1, column: 3, end_line: 1, end_column: 6 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 1, end_line: 1, end_column: 6 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn expr_with_delim4() { - check_parsing_expr( - r####"[{a=2}"####, - expect![[r#" - Node { node: List(ListExpr { elts: [Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 4, end_line: 1, end_column: 5 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 2, end_line: 1, end_column: 5 }] }), filename: "", line: 1, column: 1, end_line: 1, end_column: 6 }], ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); -} - -#[test] -fn expr_with_delim5() { - check_parsing_expr( - r####"({a=[2}"####, - expect![[r#" - Node { node: Paren(ParenExpr { expr: Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 2, end_line: 1, end_column: 3 }), value: Node { node: List(ListExpr { elts: [Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(2) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 6 }], ctx: Load }), filename: "", line: 1, column: 4, end_line: 1, end_column: 7 }, operation: Override, insert_index: -1 }, filename: "", line: 1, column: 2, end_line: 1, end_column: 7 }] }), filename: "", line: 1, column: 1, end_line: 1, end_column: 7 } }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn expr_with_delim6() { - check_parsing_expr( - r####"{"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 1 } - "#]], - ); -} - -#[test] -fn expr_with_delim7() { - check_parsing_expr( - r####"{ - a = 1 -}"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 2, column: 8, end_line: 2, end_column: 9 }, operation: Override, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 2, end_column: 9 }] }), filename: "", line: 1, column: 0, end_line: 3, end_column: 1 } - "#]], - ); -} - -#[test] -fn expr_with_delim8() { - check_parsing_expr( - r####"{ - a = 1 -"####, - expect![[r#" - Node { node: Config(ConfigExpr { items: [Node { node: ConfigEntry { key: Some(Node { node: Identifier(Identifier { names: [Node { node: "a", filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }], pkgpath: "", ctx: Load }), filename: "", line: 2, column: 4, end_line: 2, end_column: 5 }), value: Node { node: NumberLit(NumberLit { binary_suffix: None, value: Int(1) }), filename: "", line: 2, column: 8, end_line: 2, end_column: 9 }, operation: Override, insert_index: -1 }, filename: "", line: 2, column: 4, end_line: 2, end_column: 9 }] }), filename: "", line: 1, column: 0, end_line: 2, end_column: 10 } - "#]], - ); -} - #[test] fn test_parse_file_not_found() { match parse_file("The file path is invalid", None) { diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index 82ccf65f7..09b31b1cd 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -11,6 +11,7 @@ use crate::*; use core::any::Any; mod error_recovery; +mod expr; #[macro_export] macro_rules! parse_expr_snapshot { diff --git a/kclvm/parser/src/tests/expr.rs b/kclvm/parser/src/tests/expr.rs new file mode 100644 index 000000000..d7b491e5c --- /dev/null +++ b/kclvm/parser/src/tests/expr.rs @@ -0,0 +1,221 @@ +use crate::tests::parse_expr_snapshot; + +parse_expr_snapshot!(smoke_test_parsing_expr_0, "1\n"); +parse_expr_snapshot!(smoke_test_parsing_expr_1, "\"1\"\n"); +parse_expr_snapshot!(named_literal_expr_0, "Undefined"); +parse_expr_snapshot!(named_literal_expr_1, "None"); +parse_expr_snapshot!(named_literal_expr_2, "True"); +parse_expr_snapshot!(named_literal_expr_3, "False"); +parse_expr_snapshot!(nonstring_literal_expr, r####"1234"####); +parse_expr_snapshot!(string_literal_expr_0, r####"'1234'"####); +parse_expr_snapshot!(string_literal_expr_1, r####""1234""####); +parse_expr_snapshot!(string_literal_expr_2, r####""1234\n""####); +parse_expr_snapshot!(number_bin_suffix_expr, r####"1234Ki"####); +parse_expr_snapshot!(unary_expr, r####"+1"####); +parse_expr_snapshot!(binary_expr_0, r####"1+2+3"####); +parse_expr_snapshot!(binary_expr_1, r####"1+2*3-4"####); +parse_expr_snapshot!(binary_expr_2, r####"1+2*3/4"####); +parse_expr_snapshot!(binary_expr_3, r####"a or b"####); +parse_expr_snapshot!(binary_expr_4, r####"x == a or b"####); +parse_expr_snapshot!(binary_expr_5, r####"22 > 11 and 111 < 222"####); +parse_expr_snapshot!(binary_expr_6, r####"int(e.value) > 1 and i == 0"####); +parse_expr_snapshot!(binary_expr_7, r####"key in ['key']"####); +parse_expr_snapshot!(binary_expr_8, r####"key not in ['key']"####); +parse_expr_snapshot!(binary_expr_9, r####"1 is 1 and 11 is not 22"####); +parse_expr_snapshot!(binary_expr_10, r####"1 + a and b"####); +parse_expr_snapshot!(binary_expr_with_paren, r####"1*(2+3)-4"####); +parse_expr_snapshot!(logic_expr_0, r####"0 < a < 100"####); +parse_expr_snapshot!(logic_expr_1, r####"0 < a < 100 + a"####); +parse_expr_snapshot!(logic_expr_2, r####"100 > a > 0"####); +parse_expr_snapshot!(logic_expr_3, r####"100 + a > a > 0"####); +parse_expr_snapshot!(logic_expr_4, r####"a is b"####); +parse_expr_snapshot!(logic_expr_5, r####"a is not True"####); +parse_expr_snapshot!(logic_expr_6, r####"not False or a > 0 and b is True"####); +parse_expr_snapshot!(if_expr, r####"1 if true else 2"####); +parse_expr_snapshot!(primary_expr_0, r####"a.b.c"####); +parse_expr_snapshot!(primary_expr_1, r####"'{}'.format(1)"####); +parse_expr_snapshot!(primary_expr_2, r####"str(1).isdigit()"####); +parse_expr_snapshot!(list_expr_0, r####"[1, 2, 3]"####); +parse_expr_snapshot!(list_expr_1, r####"[1, if True: 2, 3]"####); +parse_expr_snapshot!(list_comp_expr_0, r####"[x ** 2 for x in [1, 2, 3]]"####); +parse_expr_snapshot!(list_comp_expr_1, r####"[i for i in [1, 2, 3] if i > 2]"####); +parse_expr_snapshot!(dict_expr, r####"{k0=v0, k1=v1}"####); +parse_expr_snapshot!( + dict_comp_expr, + r####"{k: v + 1 for k, v in {k1 = 1, k2 = 2}}"#### +); +parse_expr_snapshot!(subscript_expr_0, r####"a[0]"####); +parse_expr_snapshot!(subscript_expr_1, r####"b["k"]"####); +parse_expr_snapshot!(subscript_expr_2, r####"c?[1]"####); +parse_expr_snapshot!(subscript_expr_3, r####"a[1:]"####); +parse_expr_snapshot!(subscript_expr_4, r####"a[:-1]"####); +parse_expr_snapshot!(subscript_expr_5, r####"a[1:len]"####); +parse_expr_snapshot!(subscript_expr_6, r####"a[0:-1]"####); +parse_expr_snapshot!(subscript_expr_7, r####"a[::]"####); +parse_expr_snapshot!(subscript_expr_8, r####"a[1::]"####); +parse_expr_snapshot!(subscript_expr_9, r####"a[:0:]"####); +parse_expr_snapshot!(subscript_expr_10, r####"a[::-1]"####); +parse_expr_snapshot!(subscript_expr_11, r####"a[1::2]"####); +parse_expr_snapshot!(subscript_expr_12, r####"a[:2:1]"####); +parse_expr_snapshot!(subscript_expr_13, r####"a[1:2:]"####); +parse_expr_snapshot!(subscript_expr_14, r####"a[1:3:1]"####); +parse_expr_snapshot!(call_expr_0, r####"func0()"####); +parse_expr_snapshot!(call_expr_1, r####"func1(1)"####); +parse_expr_snapshot!(call_expr_2, r####"func2(x=2)"####); +parse_expr_snapshot!(call_expr_3, r####"func3(1,x=2)"####); +parse_expr_snapshot!(quant_expr_0, r####"all x in collection {x > 0}"####); +parse_expr_snapshot!(quant_expr_1, r####"any y in collection {y < 0}"####); +parse_expr_snapshot!(quant_expr_2, r####"map x in collection {x + 1}"####); +parse_expr_snapshot!(quant_expr_3, r####"filter x in collection {x > 1}"####); +parse_expr_snapshot!(quant_expr_4, r####"filter x in collection {x > 1}"####); +parse_expr_snapshot!( + quant_expr_5, + r####"map i, e in [{k1 = "v1", k2 = "v2"}] { e }"#### +); +parse_expr_snapshot!( + quant_expr_6, + r####"map i, e in [{k1 = "v1", k2 = "v2"}] { e if i > 0 }"#### +); +parse_expr_snapshot!(lambda_expr_0, r####"lambda {}"####); +parse_expr_snapshot!(lambda_expr_1, r####"lambda x {}"####); +parse_expr_snapshot!(lambda_expr_2, r####"lambda x: int -> int {x}"####); +parse_expr_snapshot!( + lambda_expr_3, + r####"lambda { + if True: + _a = 1 + else: + _a = 2 + _a +}"#### +); +parse_expr_snapshot!( + config_expr_0, + r####"{ + "name" = { + "name": "alice" + }, + "gender" = "female" +}"#### +); +parse_expr_snapshot!( + config_expr_1, + r####"{ + "name" = { + "name": "alice" + } + "gender" = "female", +}"#### +); +parse_expr_snapshot!( + config_expr_2, + r####"{ + "name" = { + "name": "alice", + } + "gender" = "female" +}"#### +); +parse_expr_snapshot!( + config_if_expr_0, + r####"{ + if True: + a = 1 +}"#### +); +parse_expr_snapshot!( + config_if_expr_1, + r####"{ + if True: + a = 1 + else: + a = 2 +}"#### +); +parse_expr_snapshot!( + config_if_expr_2, + r####"{ + if True: + a = 1 + elif x > 1: + a = 2 + else: + a = 3 +}"#### +); +parse_expr_snapshot!( + config_if_expr_3, + r####"{ + if True: + if False: + a = 1 +}"#### +); +parse_expr_snapshot!(schema_expr_0, r####"Schema {}"####); +parse_expr_snapshot!(schema_expr_1, r####"Schema {k=v}"####); +parse_expr_snapshot!(schema_expr_2, r####"Schema () {k=v}"####); +parse_expr_snapshot!(schema_expr_3, r####"Schema (1, 2) {k=v}"####); +parse_expr_snapshot!( + schema_expr_4, + r####"Schema (1, 2) { + k=v +}"#### +); +parse_expr_snapshot!( + line_continue, + r####"1 + \ +2 +"#### +); +parse_expr_snapshot!(parse_joined_string_0, r####"'${123+200}'"####); +parse_expr_snapshot!(parse_joined_string_1, r####"'abc${a+1}cde'"####); +parse_expr_snapshot!(expr_with_paren_0, r####"(2+3)"####); +parse_expr_snapshot!(expr_with_paren_1, r####"((2+3)"####); +parse_expr_snapshot!(expr_with_paren_2, r####"(2+3))"####); +parse_expr_snapshot!(expr_with_bracket_0, r####"[2,3]"####); +parse_expr_snapshot!(expr_with_bracket_1, r####"[[2,3]"####); +parse_expr_snapshot!(expr_with_bracket_2, r####"[2,3]]"####); +parse_expr_snapshot!(expr_with_bracket_3, r####"[2,3"####); +parse_expr_snapshot!(expr_with_bracket_4, r####"["####); +parse_expr_snapshot!( + expr_with_bracket_5, + r####"[ + 1 + 2, +] + "#### +); +parse_expr_snapshot!( + expr_with_bracket_6, + r####"[ + 1,2, +] + "#### +); +parse_expr_snapshot!( + expr_with_bracket_7, + r####"[ + 1,2, + + "#### +); +parse_expr_snapshot!(expr_with_brace_0, r####"{a=2}"####); +parse_expr_snapshot!(expr_with_brace_1, r####"{a=2}}"####); +parse_expr_snapshot!(expr_with_delim_0, r####"({a=2}"####); +parse_expr_snapshot!(expr_with_delim_1, r####"({a=(2}"####); +parse_expr_snapshot!(expr_with_delim_2, r####"{a=[2]"####); +parse_expr_snapshot!(expr_with_delim_3, r####"[{a=2}"####); +parse_expr_snapshot!(expr_with_delim_4, r####"({a=[2}"####); +parse_expr_snapshot!(expr_with_delim_5, r####"{"####); +parse_expr_snapshot!( + expr_with_delim_6, + r####"{ + a = 1 +}"#### +); +parse_expr_snapshot!( + expr_with_delim_7, + r####"{ + a = 1 +"#### +); diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_0.snap new file mode 100644 index 000000000..ff497d920 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_0.snap @@ -0,0 +1,78 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1+2+3\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_1.snap new file mode 100644 index 000000000..d5ea0857a --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_1.snap @@ -0,0 +1,107 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1+2*3-4\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + op: Bin( + Add, + ), + right: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + op: Bin( + Mul, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + op: Bin( + Sub, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 4, + ), + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_10.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_10.snap new file mode 100644 index 000000000..880406eae --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_10.snap @@ -0,0 +1,94 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1 + a and b\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + op: Bin( + Add, + ), + right: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + op: Bin( + And, + ), + right: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "b", + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 11, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_2.snap new file mode 100644 index 000000000..bf66dd48a --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_2.snap @@ -0,0 +1,107 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1+2*3/4\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + op: Bin( + Add, + ), + right: Node { + node: Binary( + BinaryExpr { + left: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + op: Bin( + Mul, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 5, + }, + op: Bin( + Div, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 4, + ), + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_3.snap new file mode 100644 index 000000000..2b7e42805 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_3.snap @@ -0,0 +1,65 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a or b\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + op: Bin( + Or, + ), + right: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "b", + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_4.snap new file mode 100644 index 000000000..f95bc13af --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_4.snap @@ -0,0 +1,104 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"x == a or b\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ops: [ + Eq, + ], + comparators: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 11, + }, + op: Bin( + Or, + ), + right: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "b", + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 11, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_5.snap new file mode 100644 index 000000000..19b27602b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_5.snap @@ -0,0 +1,111 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"22 > 11 and 111 < 222\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Compare( + Compare { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 22, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 2, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 11, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 7, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 21, + }, + op: Bin( + And, + ), + right: Node { + node: Compare( + Compare { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 111, + ), + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 15, + }, + ops: [ + Lt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 222, + ), + }, + ), + filename: "", + line: 1, + column: 18, + end_line: 1, + end_column: 21, + }, + ], + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 21, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 21, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_6.snap new file mode 100644 index 000000000..55952d50b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_6.snap @@ -0,0 +1,172 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"int(e.value) > 1 and i == 0\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Compare( + Compare { + left: Node { + node: Call( + CallExpr { + func: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "int", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + args: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "e", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + Node { + node: "value", + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 11, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 11, + }, + ], + keywords: [], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 12, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 15, + end_line: 1, + end_column: 16, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 27, + }, + op: Bin( + And, + ), + right: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "i", + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + ops: [ + Eq, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 26, + end_line: 1, + end_column: 27, + }, + ], + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 27, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 27, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_7.snap new file mode 100644 index 000000000..7f48f3a65 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_7.snap @@ -0,0 +1,72 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"key in ['key']\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "key", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + ops: [ + In, + ], + comparators: [ + Node { + node: List( + ListExpr { + elts: [ + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "'key'", + value: "key", + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 13, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 14, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 14, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_8.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_8.snap new file mode 100644 index 000000000..1bb4f300a --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_8.snap @@ -0,0 +1,72 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"key not in ['key']\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "key", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + ops: [ + NotIn, + ], + comparators: [ + Node { + node: List( + ListExpr { + elts: [ + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "'key'", + value: "key", + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 17, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 18, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 18, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_9.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_9.snap new file mode 100644 index 000000000..54807efd4 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_9.snap @@ -0,0 +1,111 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1 is 1 and 11 is not 22\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Compare( + Compare { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ops: [ + Is, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 23, + }, + op: Bin( + And, + ), + right: Node { + node: Compare( + Compare { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 11, + ), + }, + ), + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 13, + }, + ops: [ + IsNot, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 22, + ), + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 23, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 23, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_with_paren.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_with_paren.snap new file mode 100644 index 000000000..179afbde6 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__binary_expr_with_paren.snap @@ -0,0 +1,118 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1*(2+3)-4\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + op: Bin( + Mul, + ), + right: Node { + node: Paren( + ParenExpr { + expr: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, + }, + op: Bin( + Sub, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 4, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 9, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_0.snap new file mode 100644 index 000000000..44b34d0df --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_0.snap @@ -0,0 +1,41 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"func0()\"####)" +--- +Node { + node: Call( + CallExpr { + func: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "func0", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + args: [], + keywords: [], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_1.snap new file mode 100644 index 000000000..7f53f5a9e --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_1.snap @@ -0,0 +1,57 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"func1(1)\"####)" +--- +Node { + node: Call( + CallExpr { + func: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "func1", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + args: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + ], + keywords: [], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 8, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_2.snap new file mode 100644 index 000000000..365a54fd2 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_2.snap @@ -0,0 +1,89 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"func2(x=2)\"####)" +--- +Node { + node: Call( + CallExpr { + func: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "func2", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + args: [], + keywords: [ + Node { + node: Keyword { + arg: Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + value: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + ), + }, + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 9, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 10, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_3.snap new file mode 100644 index 000000000..abe42a4cb --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__call_expr_3.snap @@ -0,0 +1,105 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"func3(1,x=2)\"####)" +--- +Node { + node: Call( + CallExpr { + func: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "func3", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, + }, + args: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + ], + keywords: [ + Node { + node: Keyword { + arg: Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + value: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + ), + }, + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 11, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 12, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_0.snap new file mode 100644 index 000000000..9368a7f64 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_0.snap @@ -0,0 +1,140 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n \"name\" = {\n \"name\": \"alice\"\n },\n \"gender\" = \"female\"\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"name\"", + value: "name", + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 10, + }, + ), + value: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"name\"", + value: "name", + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 14, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"alice\"", + value: "alice", + }, + ), + filename: "", + line: 3, + column: 16, + end_line: 3, + end_column: 23, + }, + operation: Union, + insert_index: -1, + }, + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 2, + column: 13, + end_line: 4, + end_column: 5, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 4, + end_column: 5, + }, + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"gender\"", + value: "gender", + }, + ), + filename: "", + line: 5, + column: 4, + end_line: 5, + end_column: 12, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"female\"", + value: "female", + }, + ), + filename: "", + line: 5, + column: 15, + end_line: 5, + end_column: 23, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 5, + column: 4, + end_line: 5, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 6, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_1.snap new file mode 100644 index 000000000..6c3076fa3 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_1.snap @@ -0,0 +1,140 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n \"name\" = {\n \"name\": \"alice\"\n }\n \"gender\" = \"female\",\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"name\"", + value: "name", + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 10, + }, + ), + value: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"name\"", + value: "name", + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 14, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"alice\"", + value: "alice", + }, + ), + filename: "", + line: 3, + column: 16, + end_line: 3, + end_column: 23, + }, + operation: Union, + insert_index: -1, + }, + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 2, + column: 13, + end_line: 4, + end_column: 5, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 4, + end_column: 5, + }, + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"gender\"", + value: "gender", + }, + ), + filename: "", + line: 5, + column: 4, + end_line: 5, + end_column: 12, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"female\"", + value: "female", + }, + ), + filename: "", + line: 5, + column: 15, + end_line: 5, + end_column: 23, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 5, + column: 4, + end_line: 5, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 6, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_2.snap new file mode 100644 index 000000000..dbab80146 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_expr_2.snap @@ -0,0 +1,140 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n \"name\" = {\n \"name\": \"alice\",\n }\n \"gender\" = \"female\"\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"name\"", + value: "name", + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 10, + }, + ), + value: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"name\"", + value: "name", + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 14, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"alice\"", + value: "alice", + }, + ), + filename: "", + line: 3, + column: 16, + end_line: 3, + end_column: 23, + }, + operation: Union, + insert_index: -1, + }, + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 2, + column: 13, + end_line: 4, + end_column: 5, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 4, + end_column: 5, + }, + Node { + node: ConfigEntry { + key: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"gender\"", + value: "gender", + }, + ), + filename: "", + line: 5, + column: 4, + end_line: 5, + end_column: 12, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"female\"", + value: "female", + }, + ), + filename: "", + line: 5, + column: 15, + end_line: 5, + end_column: 23, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 5, + column: 4, + end_line: 5, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 6, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_0.snap new file mode 100644 index 000000000..8262d6a38 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_0.snap @@ -0,0 +1,107 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n if True:\n a = 1\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: None, + value: Node { + node: ConfigIfEntry( + ConfigIfEntryExpr { + if_cond: Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 2, + column: 7, + end_line: 2, + end_column: 11, + }, + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 9, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 3, + column: 12, + end_line: 3, + end_column: 13, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 13, + }, + ], + orelse: None, + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 4, + end_column: 0, + }, + operation: Union, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 4, + end_column: 0, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 4, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_1.snap new file mode 100644 index 000000000..3077aef2c --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_1.snap @@ -0,0 +1,172 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n if True:\n a = 1\n else:\n a = 2\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: None, + value: Node { + node: ConfigIfEntry( + ConfigIfEntryExpr { + if_cond: Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 2, + column: 7, + end_line: 2, + end_column: 11, + }, + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 9, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 3, + column: 12, + end_line: 3, + end_column: 13, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 13, + }, + ], + orelse: Some( + Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 9, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 5, + column: 12, + end_line: 5, + end_column: 13, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 13, + }, + ], + }, + ), + filename: "", + line: 4, + column: 4, + end_line: 6, + end_column: 0, + }, + ), + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 6, + end_column: 0, + }, + operation: Union, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 6, + end_column: 0, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 6, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_2.snap new file mode 100644 index 000000000..65871797e --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_2.snap @@ -0,0 +1,292 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n if True:\n a = 1\n elif x > 1:\n a = 2\n else:\n a = 3\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: None, + value: Node { + node: ConfigIfEntry( + ConfigIfEntryExpr { + if_cond: Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 2, + column: 7, + end_line: 2, + end_column: 11, + }, + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 9, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 3, + column: 12, + end_line: 3, + end_column: 13, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 13, + }, + ], + orelse: Some( + Node { + node: ConfigIfEntry( + ConfigIfEntryExpr { + if_cond: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 4, + column: 9, + end_line: 4, + end_column: 10, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 4, + column: 9, + end_line: 4, + end_column: 10, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 4, + column: 13, + end_line: 4, + end_column: 14, + }, + ], + }, + ), + filename: "", + line: 4, + column: 9, + end_line: 4, + end_column: 14, + }, + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 9, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 5, + column: 12, + end_line: 5, + end_column: 13, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 13, + }, + ], + orelse: Some( + Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 7, + column: 8, + end_line: 7, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 7, + column: 8, + end_line: 7, + end_column: 9, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 7, + column: 12, + end_line: 7, + end_column: 13, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 7, + column: 8, + end_line: 7, + end_column: 13, + }, + ], + }, + ), + filename: "", + line: 6, + column: 4, + end_line: 8, + end_column: 0, + }, + ), + }, + ), + filename: "", + line: 4, + column: 4, + end_line: 6, + end_column: 4, + }, + ), + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 8, + end_column: 0, + }, + operation: Union, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 8, + end_column: 0, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 8, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_3.snap new file mode 100644 index 000000000..1102a3fe4 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__config_if_expr_3.snap @@ -0,0 +1,145 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n if True:\n if False:\n a = 1\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: None, + value: Node { + node: ConfigIfEntry( + ConfigIfEntryExpr { + if_cond: Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 2, + column: 7, + end_line: 2, + end_column: 11, + }, + items: [ + Node { + node: ConfigEntry { + key: None, + value: Node { + node: ConfigIfEntry( + ConfigIfEntryExpr { + if_cond: Node { + node: NameConstantLit( + NameConstantLit { + value: False, + }, + ), + filename: "", + line: 3, + column: 11, + end_line: 3, + end_column: 16, + }, + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 4, + column: 12, + end_line: 4, + end_column: 13, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 4, + column: 12, + end_line: 4, + end_column: 13, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 4, + column: 16, + end_line: 4, + end_column: 17, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 4, + column: 12, + end_line: 4, + end_column: 17, + }, + ], + orelse: None, + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 5, + end_column: 0, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 3, + column: 8, + end_line: 5, + end_column: 0, + }, + ], + orelse: None, + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 5, + end_column: 0, + }, + operation: Union, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 5, + end_column: 0, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 5, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__dict_comp_expr.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__dict_comp_expr.snap new file mode 100644 index 000000000..47a0c8716 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__dict_comp_expr.snap @@ -0,0 +1,268 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{k: v + 1 for k, v in {k1 = 1, k2 = 2}}\"####)" +--- +Node { + node: DictComp( + DictComp { + entry: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k", + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ), + value: Node { + node: Binary( + BinaryExpr { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "v", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 9, + }, + operation: Union, + insert_index: -1, + }, + generators: [ + Node { + node: CompClause { + targets: [ + Node { + node: Identifier { + names: [ + Node { + node: "k", + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 15, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 15, + }, + Node { + node: Identifier { + names: [ + Node { + node: "v", + filename: "", + line: 1, + column: 17, + end_line: 1, + end_column: 18, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 17, + end_line: 1, + end_column: 18, + }, + ], + iter: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k1", + filename: "", + line: 1, + column: 23, + end_line: 1, + end_column: 25, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 23, + end_line: 1, + end_column: 25, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 28, + end_line: 1, + end_column: 29, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 23, + end_line: 1, + end_column: 29, + }, + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k2", + filename: "", + line: 1, + column: 31, + end_line: 1, + end_column: 33, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 31, + end_line: 1, + end_column: 33, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 36, + end_line: 1, + end_column: 37, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 31, + end_line: 1, + end_column: 37, + }, + ], + }, + ), + filename: "", + line: 1, + column: 22, + end_line: 1, + end_column: 38, + }, + ifs: [], + }, + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 38, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 39, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__dict_expr.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__dict_expr.snap new file mode 100644 index 000000000..091ef3644 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__dict_expr.snap @@ -0,0 +1,136 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{k0=v0, k1=v1}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k0", + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 3, + }, + ), + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "v0", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 6, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 6, + }, + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k1", + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 10, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 10, + }, + ), + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "v1", + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 13, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 13, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 13, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 14, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_brace_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_brace_0.snap new file mode 100644 index 000000000..ad2a5a0cf --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_brace_0.snap @@ -0,0 +1,69 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{a=2}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 4, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_brace_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_brace_1.snap new file mode 100644 index 000000000..9fb8ad972 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_brace_1.snap @@ -0,0 +1,69 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{a=2}}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 4, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_0.snap new file mode 100644 index 000000000..5f61ac170 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_0.snap @@ -0,0 +1,49 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[2,3]\"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_1.snap new file mode 100644 index 000000000..8540a6417 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_1.snap @@ -0,0 +1,63 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[[2,3]\"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 6, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_2.snap new file mode 100644 index 000000000..974638b56 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_2.snap @@ -0,0 +1,49 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[2,3]]\"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_3.snap new file mode 100644 index 000000000..f00b8be1a --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_3.snap @@ -0,0 +1,49 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[2,3\"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 4, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_4.snap new file mode 100644 index 000000000..1caf60fff --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_4.snap @@ -0,0 +1,18 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[\"####)" +--- +Node { + node: List( + ListExpr { + elts: [], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_5.snap new file mode 100644 index 000000000..aa4f7fe96 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_5.snap @@ -0,0 +1,49 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[\n 1\n 2,\n]\n \"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 3, + column: 4, + end_line: 3, + end_column: 5, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 4, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_6.snap new file mode 100644 index 000000000..ca20c1f26 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_6.snap @@ -0,0 +1,49 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[\n 1,2,\n]\n \"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 2, + column: 6, + end_line: 2, + end_column: 7, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 3, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_7.snap new file mode 100644 index 000000000..9ae683dfa --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_bracket_7.snap @@ -0,0 +1,49 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[\n 1,2,\n\n \"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 2, + column: 6, + end_line: 2, + end_column: 7, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 4, + end_column: 8, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_0.snap new file mode 100644 index 000000000..bcb6bdaff --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_0.snap @@ -0,0 +1,80 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"({a=2}\"####)" +--- +Node { + node: Paren( + ParenExpr { + expr: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 5, + }, + ], + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_1.snap new file mode 100644 index 000000000..909f52bcf --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_1.snap @@ -0,0 +1,91 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"({a=(2}\"####)" +--- +Node { + node: Paren( + ParenExpr { + expr: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + value: Node { + node: Paren( + ParenExpr { + expr: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 7, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 7, + }, + ], + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_2.snap new file mode 100644 index 000000000..086df811c --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_2.snap @@ -0,0 +1,83 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{a=[2]\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ), + value: Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 6, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 6, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_3.snap new file mode 100644 index 000000000..47ac7d93d --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_3.snap @@ -0,0 +1,83 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[{a=2}\"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 5, + }, + ], + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 6, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_4.snap new file mode 100644 index 000000000..de2f05aab --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_4.snap @@ -0,0 +1,94 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"({a=[2}\"####)" +--- +Node { + node: Paren( + ParenExpr { + expr: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + value: Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 7, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 7, + }, + ], + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_5.snap new file mode 100644 index 000000000..e69e0ea93 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_5.snap @@ -0,0 +1,17 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_6.snap new file mode 100644 index 000000000..f65835076 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_6.snap @@ -0,0 +1,69 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n a = 1\n}\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 2, + column: 8, + end_line: 2, + end_column: 9, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 9, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 3, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_7.snap new file mode 100644 index 000000000..39f44a320 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_delim_7.snap @@ -0,0 +1,69 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"{\n a = 1\n\"####)" +--- +Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + ), + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 2, + column: 8, + end_line: 2, + end_column: 9, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 9, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 2, + end_column: 10, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_0.snap new file mode 100644 index 000000000..98eef0b07 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_0.snap @@ -0,0 +1,60 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"(2+3)\"####)" +--- +Node { + node: Paren( + ParenExpr { + expr: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 4, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_1.snap new file mode 100644 index 000000000..fa0105b3e --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_1.snap @@ -0,0 +1,71 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"((2+3)\"####)" +--- +Node { + node: Paren( + ParenExpr { + expr: Node { + node: Paren( + ParenExpr { + expr: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_2.snap new file mode 100644 index 000000000..405b5f0e0 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__expr_with_paren_2.snap @@ -0,0 +1,60 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"(2+3))\"####)" +--- +Node { + node: Paren( + ParenExpr { + expr: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 4, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__if_expr.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__if_expr.snap new file mode 100644 index 000000000..6d43c32c0 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__if_expr.snap @@ -0,0 +1,69 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1 if true else 2\"####)" +--- +Node { + node: If( + IfExpr { + body: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + cond: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "true", + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 9, + }, + orelse: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 15, + end_line: 1, + end_column: 16, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 16, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_0.snap new file mode 100644 index 000000000..39e4e5a6e --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_0.snap @@ -0,0 +1,20 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"lambda {}\"####)" +--- +Node { + node: Lambda( + LambdaExpr { + args: None, + return_type_str: None, + body: [], + return_ty: None, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 9, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_1.snap new file mode 100644 index 000000000..a560a0138 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_1.snap @@ -0,0 +1,62 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"lambda x {}\"####)" +--- +Node { + node: Lambda( + LambdaExpr { + args: Some( + Node { + node: Arguments { + args: [ + Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + defaults: [ + None, + ], + type_annotation_list: [ + None, + ], + ty_list: [ + None, + ], + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ), + return_type_str: None, + body: [], + return_ty: None, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 11, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_2.snap new file mode 100644 index 000000000..5a8575f24 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_2.snap @@ -0,0 +1,132 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"lambda x: int -> int {x}\"####)" +--- +Node { + node: Lambda( + LambdaExpr { + args: Some( + Node { + node: Arguments { + args: [ + Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + defaults: [ + None, + ], + type_annotation_list: [ + Some( + Node { + node: "int", + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 13, + }, + ), + ], + ty_list: [ + Some( + Node { + node: Basic( + Int, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 13, + }, + ), + ], + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 13, + }, + ), + return_type_str: Some( + "int", + ), + body: [ + Node { + node: Expr( + ExprStmt { + exprs: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 22, + end_line: 1, + end_column: 23, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 22, + end_line: 1, + end_column: 23, + }, + ], + }, + ), + filename: "", + line: 1, + column: 22, + end_line: 1, + end_column: 23, + }, + ], + return_ty: Some( + Node { + node: Basic( + Int, + ), + filename: "", + line: 1, + column: 17, + end_line: 1, + end_column: 20, + }, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 24, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_3.snap new file mode 100644 index 000000000..cec3abf08 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__lambda_expr_3.snap @@ -0,0 +1,186 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"lambda {\n if True:\n _a = 1\n else:\n _a = 2\n _a\n}\"####)" +--- +Node { + node: Lambda( + LambdaExpr { + args: None, + return_type_str: None, + body: [ + Node { + node: If( + IfStmt { + body: [ + Node { + node: Assign( + AssignStmt { + targets: [ + Node { + node: Identifier { + names: [ + Node { + node: "_a", + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 10, + }, + ], + pkgpath: "", + ctx: Store, + }, + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 10, + }, + ], + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 3, + column: 13, + end_line: 3, + end_column: 14, + }, + type_annotation: None, + ty: None, + }, + ), + filename: "", + line: 3, + column: 8, + end_line: 3, + end_column: 14, + }, + ], + cond: Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 2, + column: 7, + end_line: 2, + end_column: 11, + }, + orelse: [ + Node { + node: Assign( + AssignStmt { + targets: [ + Node { + node: Identifier { + names: [ + Node { + node: "_a", + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 10, + }, + ], + pkgpath: "", + ctx: Store, + }, + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 10, + }, + ], + value: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 5, + column: 13, + end_line: 5, + end_column: 14, + }, + type_annotation: None, + ty: None, + }, + ), + filename: "", + line: 5, + column: 8, + end_line: 5, + end_column: 14, + }, + ], + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 6, + end_column: 4, + }, + Node { + node: Expr( + ExprStmt { + exprs: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "_a", + filename: "", + line: 6, + column: 4, + end_line: 6, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 6, + column: 4, + end_line: 6, + end_column: 6, + }, + ], + }, + ), + filename: "", + line: 6, + column: 4, + end_line: 6, + end_column: 6, + }, + ], + return_ty: None, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 7, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__line_continue.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__line_continue.snap new file mode 100644 index 000000000..f45491884 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__line_continue.snap @@ -0,0 +1,49 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1 + \\\n2\n\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 2, + column: 0, + end_line: 2, + end_column: 1, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 2, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_comp_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_comp_expr_0.snap new file mode 100644 index 000000000..9e0d2a633 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_comp_expr_0.snap @@ -0,0 +1,162 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[x ** 2 for x in [1, 2, 3]]\"####)" +--- +Node { + node: ListComp( + ListComp { + elt: Node { + node: Binary( + BinaryExpr { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + op: Bin( + Pow, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 7, + }, + generators: [ + Node { + node: CompClause { + targets: [ + Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 13, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 13, + }, + ], + iter: Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 18, + end_line: 1, + end_column: 19, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 24, + end_line: 1, + end_column: 25, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 17, + end_line: 1, + end_column: 26, + }, + ifs: [], + }, + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 26, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 27, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_comp_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_comp_expr_1.snap new file mode 100644 index 000000000..724c18610 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_comp_expr_1.snap @@ -0,0 +1,188 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[i for i in [1, 2, 3] if i > 2]\"####)" +--- +Node { + node: ListComp( + ListComp { + elt: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "i", + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + generators: [ + Node { + node: CompClause { + targets: [ + Node { + node: Identifier { + names: [ + Node { + node: "i", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + iter: Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 14, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 16, + end_line: 1, + end_column: 17, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 19, + end_line: 1, + end_column: 20, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 21, + }, + ifs: [ + Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "i", + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 26, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 26, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 29, + end_line: 1, + end_column: 30, + }, + ], + }, + ), + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 30, + }, + ], + }, + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 30, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 31, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_expr_0.snap new file mode 100644 index 000000000..356ee9454 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_expr_0.snap @@ -0,0 +1,64 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[1, 2, 3]\"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 9, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_expr_1.snap new file mode 100644 index 000000000..3401d3c7f --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__list_expr_1.snap @@ -0,0 +1,90 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"[1, if True: 2, 3]\"####)" +--- +Node { + node: List( + ListExpr { + elts: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + Node { + node: ListIfItem( + ListIfItemExpr { + if_cond: Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 11, + }, + exprs: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 14, + }, + ], + orelse: None, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 14, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 16, + end_line: 1, + end_column: 17, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 18, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_0.snap new file mode 100644 index 000000000..6f3ba2059 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_0.snap @@ -0,0 +1,75 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"0 < a < 100\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ops: [ + Lt, + Lt, + ], + comparators: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 100, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 11, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 11, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_1.snap new file mode 100644 index 000000000..d52a567e1 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_1.snap @@ -0,0 +1,112 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"0 < a < 100 + a\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ops: [ + Lt, + Lt, + ], + comparators: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 100, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 11, + }, + op: Bin( + Add, + ), + right: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 15, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 15, + }, + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 15, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 15, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_2.snap new file mode 100644 index 000000000..b8df91bfb --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_2.snap @@ -0,0 +1,75 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"100 > a > 0\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 100, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + ops: [ + Gt, + Gt, + ], + comparators: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 11, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_3.snap new file mode 100644 index 000000000..9bdc33aff --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_3.snap @@ -0,0 +1,112 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"100 + a > a > 0\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 100, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + op: Bin( + Add, + ), + right: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, + }, + ops: [ + Gt, + Gt, + ], + comparators: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 15, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 15, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_4.snap new file mode 100644 index 000000000..4d1179f19 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_4.snap @@ -0,0 +1,67 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a is b\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ops: [ + Is, + ], + comparators: [ + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "b", + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_5.snap new file mode 100644 index 000000000..45e278b7b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_5.snap @@ -0,0 +1,56 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a is not True\"####)" +--- +Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ops: [ + IsNot, + ], + comparators: [ + Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 1, + column: 9, + end_line: 1, + end_column: 13, + }, + ], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 13, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_6.snap new file mode 100644 index 000000000..5d1e2bbf0 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__logic_expr_6.snap @@ -0,0 +1,162 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"not False or a > 0 and b is True\"####)" +--- +Node { + node: Binary( + BinaryExpr { + left: Node { + node: Unary( + UnaryExpr { + op: Not, + operand: Node { + node: NameConstantLit( + NameConstantLit { + value: False, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 9, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 9, + }, + op: Bin( + Or, + ), + right: Node { + node: Binary( + BinaryExpr { + left: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 14, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 14, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 17, + end_line: 1, + end_column: 18, + }, + ], + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 32, + }, + op: Bin( + And, + ), + right: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "b", + filename: "", + line: 1, + column: 23, + end_line: 1, + end_column: 24, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 23, + end_line: 1, + end_column: 24, + }, + ops: [ + Is, + ], + comparators: [ + Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 1, + column: 28, + end_line: 1, + end_column: 32, + }, + ], + }, + ), + filename: "", + line: 1, + column: 23, + end_line: 1, + end_column: 32, + }, + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 32, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 32, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_0.snap new file mode 100644 index 000000000..7de5ef740 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_0.snap @@ -0,0 +1,17 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(\"Undefined\")" +--- +Node { + node: NameConstantLit( + NameConstantLit { + value: Undefined, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 9, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_1.snap new file mode 100644 index 000000000..7f5c7ef9d --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_1.snap @@ -0,0 +1,17 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(\"None\")" +--- +Node { + node: NameConstantLit( + NameConstantLit { + value: None, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 4, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_2.snap new file mode 100644 index 000000000..2da8eaa4c --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_2.snap @@ -0,0 +1,17 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(\"True\")" +--- +Node { + node: NameConstantLit( + NameConstantLit { + value: True, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 4, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_3.snap new file mode 100644 index 000000000..2f6bf66cc --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__named_literal_expr_3.snap @@ -0,0 +1,17 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(\"False\")" +--- +Node { + node: NameConstantLit( + NameConstantLit { + value: False, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__nonstring_literal_expr.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__nonstring_literal_expr.snap new file mode 100644 index 000000000..565de3ff4 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__nonstring_literal_expr.snap @@ -0,0 +1,20 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1234\"####)" +--- +Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1234, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 4, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__number_bin_suffix_expr.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__number_bin_suffix_expr.snap new file mode 100644 index 000000000..5082423ff --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__number_bin_suffix_expr.snap @@ -0,0 +1,22 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"1234Ki\"####)" +--- +Node { + node: NumberLit( + NumberLit { + binary_suffix: Some( + Ki, + ), + value: Int( + 1234, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__parse_joined_string_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__parse_joined_string_0.snap new file mode 100644 index 000000000..91caf5d34 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__parse_joined_string_0.snap @@ -0,0 +1,77 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"'${123+200}'\"####)" +--- +Node { + node: JoinedString( + JoinedString { + is_long_string: false, + values: [ + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Binary( + BinaryExpr { + left: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 123, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 6, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 200, + ), + }, + ), + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 10, + }, + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 10, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 10, + }, + ], + raw_value: "'${123+200}'", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 12, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__parse_joined_string_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__parse_joined_string_1.snap new file mode 100644 index 000000000..cf0d73a0d --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__parse_joined_string_1.snap @@ -0,0 +1,113 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"'abc${a+1}cde'\"####)" +--- +Node { + node: JoinedString( + JoinedString { + is_long_string: false, + values: [ + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "abc", + value: "abc", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Binary( + BinaryExpr { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 9, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 9, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "cde", + value: "cde", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + ], + raw_value: "'abc${a+1}cde'", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 14, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_0.snap new file mode 100644 index 000000000..a028192b6 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_0.snap @@ -0,0 +1,44 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a.b.c\"####)" +--- +Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + Node { + node: "b", + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + Node { + node: "c", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_1.snap new file mode 100644 index 000000000..df2ad88f0 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_1.snap @@ -0,0 +1,82 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"'{}'.format(1)\"####)" +--- +Node { + node: Call( + CallExpr { + func: Node { + node: Selector( + SelectorExpr { + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "'{}'", + value: "{}", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 4, + }, + attr: Node { + node: Identifier { + names: [ + Node { + node: "format", + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 11, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 11, + }, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 11, + }, + args: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 13, + }, + ], + keywords: [], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 14, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_2.snap new file mode 100644 index 000000000..45416f506 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__primary_expr_2.snap @@ -0,0 +1,104 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"str(1).isdigit()\"####)" +--- +Node { + node: Call( + CallExpr { + func: Node { + node: Selector( + SelectorExpr { + value: Node { + node: Call( + CallExpr { + func: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "str", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, + }, + args: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + keywords: [], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + attr: Node { + node: Identifier { + names: [ + Node { + node: "isdigit", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 14, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 14, + }, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 14, + }, + args: [], + keywords: [], + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 16, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_0.snap new file mode 100644 index 000000000..2da80a01e --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_0.snap @@ -0,0 +1,119 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"all x in collection {x > 0}\"####)" +--- +Node { + node: Quant( + QuantExpr { + target: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "collection", + filename: "", + line: 1, + column: 9, + end_line: 1, + end_column: 19, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 9, + end_line: 1, + end_column: 19, + }, + variables: [ + Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + op: All, + test: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 26, + }, + ], + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 26, + }, + if_cond: None, + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 27, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_1.snap new file mode 100644 index 000000000..2191519ad --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_1.snap @@ -0,0 +1,119 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"any y in collection {y < 0}\"####)" +--- +Node { + node: Quant( + QuantExpr { + target: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "collection", + filename: "", + line: 1, + column: 9, + end_line: 1, + end_column: 19, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 9, + end_line: 1, + end_column: 19, + }, + variables: [ + Node { + node: Identifier { + names: [ + Node { + node: "y", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + op: Any, + test: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "y", + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + ops: [ + Lt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 26, + }, + ], + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 26, + }, + if_cond: None, + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 27, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_2.snap new file mode 100644 index 000000000..7910878c3 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_2.snap @@ -0,0 +1,117 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"map x in collection {x + 1}\"####)" +--- +Node { + node: Quant( + QuantExpr { + target: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "collection", + filename: "", + line: 1, + column: 9, + end_line: 1, + end_column: 19, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 9, + end_line: 1, + end_column: 19, + }, + variables: [ + Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + op: Map, + test: Node { + node: Binary( + BinaryExpr { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 22, + }, + op: Bin( + Add, + ), + right: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 26, + }, + }, + ), + filename: "", + line: 1, + column: 21, + end_line: 1, + end_column: 26, + }, + if_cond: None, + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 27, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_3.snap new file mode 100644 index 000000000..272131f54 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_3.snap @@ -0,0 +1,119 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"filter x in collection {x > 1}\"####)" +--- +Node { + node: Quant( + QuantExpr { + target: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "collection", + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 22, + }, + variables: [ + Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + op: Filter, + test: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 24, + end_line: 1, + end_column: 25, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 24, + end_line: 1, + end_column: 25, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 28, + end_line: 1, + end_column: 29, + }, + ], + }, + ), + filename: "", + line: 1, + column: 24, + end_line: 1, + end_column: 29, + }, + if_cond: None, + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 30, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_4.snap new file mode 100644 index 000000000..272131f54 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_4.snap @@ -0,0 +1,119 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"filter x in collection {x > 1}\"####)" +--- +Node { + node: Quant( + QuantExpr { + target: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "collection", + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 22, + }, + variables: [ + Node { + node: Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + op: Filter, + test: Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "x", + filename: "", + line: 1, + column: 24, + end_line: 1, + end_column: 25, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 24, + end_line: 1, + end_column: 25, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 28, + end_line: 1, + end_column: 29, + }, + ], + }, + ), + filename: "", + line: 1, + column: 24, + end_line: 1, + end_column: 29, + }, + if_cond: None, + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 30, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_5.snap new file mode 100644 index 000000000..b80e8af80 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_5.snap @@ -0,0 +1,213 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"map i, e in [{k1 = \"v1\", k2 = \"v2\"}] { e }\"####)" +--- +Node { + node: Quant( + QuantExpr { + target: Node { + node: List( + ListExpr { + elts: [ + Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k1", + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 16, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 16, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"v1\"", + value: "v1", + }, + ), + filename: "", + line: 1, + column: 19, + end_line: 1, + end_column: 23, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 23, + }, + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k2", + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 27, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 27, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"v2\"", + value: "v2", + }, + ), + filename: "", + line: 1, + column: 30, + end_line: 1, + end_column: 34, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 34, + }, + ], + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 35, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 36, + }, + variables: [ + Node { + node: Identifier { + names: [ + Node { + node: "i", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + Node { + node: Identifier { + names: [ + Node { + node: "e", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + op: Map, + test: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "e", + filename: "", + line: 1, + column: 39, + end_line: 1, + end_column: 40, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 39, + end_line: 1, + end_column: 40, + }, + if_cond: None, + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 42, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_6.snap new file mode 100644 index 000000000..6112b0f13 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__quant_expr_6.snap @@ -0,0 +1,268 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"map i, e in [{k1 = \"v1\", k2 = \"v2\"}] { e if i > 0 }\"####)" +--- +Node { + node: Quant( + QuantExpr { + target: Node { + node: List( + ListExpr { + elts: [ + Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k1", + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 16, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 16, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"v1\"", + value: "v1", + }, + ), + filename: "", + line: 1, + column: 19, + end_line: 1, + end_column: 23, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 23, + }, + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k2", + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 27, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 27, + }, + ), + value: Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"v2\"", + value: "v2", + }, + ), + filename: "", + line: 1, + column: 30, + end_line: 1, + end_column: 34, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 25, + end_line: 1, + end_column: 34, + }, + ], + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 35, + }, + ], + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 12, + end_line: 1, + end_column: 36, + }, + variables: [ + Node { + node: Identifier { + names: [ + Node { + node: "i", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + Node { + node: Identifier { + names: [ + Node { + node: "e", + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 8, + }, + ], + op: Map, + test: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "e", + filename: "", + line: 1, + column: 39, + end_line: 1, + end_column: 40, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 39, + end_line: 1, + end_column: 40, + }, + if_cond: Some( + Node { + node: Compare( + Compare { + left: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "i", + filename: "", + line: 1, + column: 44, + end_line: 1, + end_column: 45, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 44, + end_line: 1, + end_column: 45, + }, + ops: [ + Gt, + ], + comparators: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 48, + end_line: 1, + end_column: 49, + }, + ], + }, + ), + filename: "", + line: 1, + column: 44, + end_line: 1, + end_column: 49, + }, + ), + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 51, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_0.snap new file mode 100644 index 000000000..ca2d929a2 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_0.snap @@ -0,0 +1,51 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"Schema {}\"####)" +--- +Node { + node: Schema( + SchemaExpr { + name: Node { + node: Identifier { + names: [ + Node { + node: "Schema", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + args: [], + kwargs: [], + config: Node { + node: Config( + ConfigExpr { + items: [], + }, + ), + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 9, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 9, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_1.snap new file mode 100644 index 000000000..e73ebd8fd --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_1.snap @@ -0,0 +1,111 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"Schema {k=v}\"####)" +--- +Node { + node: Schema( + SchemaExpr { + name: Node { + node: Identifier { + names: [ + Node { + node: "Schema", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + args: [], + kwargs: [], + config: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k", + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + ), + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "v", + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 11, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 11, + }, + ], + }, + ), + filename: "", + line: 1, + column: 7, + end_line: 1, + end_column: 12, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 12, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_2.snap new file mode 100644 index 000000000..8d63ad2c7 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_2.snap @@ -0,0 +1,111 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"Schema () {k=v}\"####)" +--- +Node { + node: Schema( + SchemaExpr { + name: Node { + node: Identifier { + names: [ + Node { + node: "Schema", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + args: [], + kwargs: [], + config: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k", + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 12, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 12, + }, + ), + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "v", + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 14, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 14, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 14, + }, + ], + }, + ), + filename: "", + line: 1, + column: 10, + end_line: 1, + end_column: 15, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 15, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_3.snap new file mode 100644 index 000000000..01fcebee5 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_3.snap @@ -0,0 +1,142 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"Schema (1, 2) {k=v}\"####)" +--- +Node { + node: Schema( + SchemaExpr { + name: Node { + node: Identifier { + names: [ + Node { + node: "Schema", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + args: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 12, + }, + ], + kwargs: [], + config: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k", + filename: "", + line: 1, + column: 15, + end_line: 1, + end_column: 16, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 15, + end_line: 1, + end_column: 16, + }, + ), + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "v", + filename: "", + line: 1, + column: 17, + end_line: 1, + end_column: 18, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 17, + end_line: 1, + end_column: 18, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 1, + column: 15, + end_line: 1, + end_column: 18, + }, + ], + }, + ), + filename: "", + line: 1, + column: 14, + end_line: 1, + end_column: 19, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 19, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_4.snap new file mode 100644 index 000000000..9fa625d2e --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__schema_expr_4.snap @@ -0,0 +1,142 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"Schema (1, 2) {\n k=v\n}\"####)" +--- +Node { + node: Schema( + SchemaExpr { + name: Node { + node: Identifier { + names: [ + Node { + node: "Schema", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + ], + pkgpath: "", + ctx: Load, + }, + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, + }, + args: [ + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 8, + end_line: 1, + end_column: 9, + }, + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 11, + end_line: 1, + end_column: 12, + }, + ], + kwargs: [], + config: Node { + node: Config( + ConfigExpr { + items: [ + Node { + node: ConfigEntry { + key: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "k", + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 5, + }, + ), + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "v", + filename: "", + line: 2, + column: 6, + end_line: 2, + end_column: 7, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 2, + column: 6, + end_line: 2, + end_column: 7, + }, + operation: Override, + insert_index: -1, + }, + filename: "", + line: 2, + column: 4, + end_line: 2, + end_column: 7, + }, + ], + }, + ), + filename: "", + line: 1, + column: 14, + end_line: 3, + end_column: 1, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 3, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__smoke_test_parsing_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__smoke_test_parsing_expr_0.snap new file mode 100644 index 000000000..896509e1b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__smoke_test_parsing_expr_0.snap @@ -0,0 +1,20 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(\"1\\n\")" +--- +Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__smoke_test_parsing_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__smoke_test_parsing_expr_1.snap new file mode 100644 index 000000000..2e7abca86 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__smoke_test_parsing_expr_1.snap @@ -0,0 +1,19 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(\"\\\"1\\\"\\n\")" +--- +Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"1\"", + value: "1", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 3, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_0.snap new file mode 100644 index 000000000..6c8c37538 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_0.snap @@ -0,0 +1,19 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"'1234'\"####)" +--- +Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "'1234'", + value: "1234", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_1.snap new file mode 100644 index 000000000..1f108e406 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_1.snap @@ -0,0 +1,19 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"\"1234\"\"####)" +--- +Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"1234\"", + value: "1234", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_2.snap new file mode 100644 index 000000000..a5f3e2e53 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__string_literal_expr_2.snap @@ -0,0 +1,19 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"\"1234\\n\"\"####)" +--- +Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"1234\\n\"", + value: "1234\n", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 8, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_0.snap new file mode 100644 index 000000000..3752cbeac --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_0.snap @@ -0,0 +1,61 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[0]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + lower: None, + upper: None, + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 4, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_1.snap new file mode 100644 index 000000000..9b32e231a --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_1.snap @@ -0,0 +1,60 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"b[\"k\"]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "b", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: Some( + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\"k\"", + value: "k", + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 5, + }, + ), + lower: None, + upper: None, + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_10.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_10.snap new file mode 100644 index 000000000..ce08b1682 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_10.snap @@ -0,0 +1,73 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[::-1]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: None, + upper: None, + step: Some( + Node { + node: Unary( + UnaryExpr { + op: USub, + operand: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 6, + }, + ), + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_11.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_11.snap new file mode 100644 index 000000000..a5cc8ab34 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_11.snap @@ -0,0 +1,77 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[1::2]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + upper: None, + step: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ), + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_12.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_12.snap new file mode 100644 index 000000000..f6cfe4beb --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_12.snap @@ -0,0 +1,77 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[:2:1]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: None, + upper: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + ), + step: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + ), + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_13.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_13.snap new file mode 100644 index 000000000..61b668cca --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_13.snap @@ -0,0 +1,77 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[1:2:]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + upper: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 2, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ), + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_14.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_14.snap new file mode 100644 index 000000000..001416f3a --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_14.snap @@ -0,0 +1,93 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[1:3:1]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + upper: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 3, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + ), + step: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 6, + end_line: 1, + end_column: 7, + }, + ), + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 8, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_2.snap new file mode 100644 index 000000000..1c4f15312 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_2.snap @@ -0,0 +1,61 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"c?[1]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "c", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + ), + lower: None, + upper: None, + step: None, + ctx: Load, + has_question: true, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_3.snap new file mode 100644 index 000000000..a288ead99 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_3.snap @@ -0,0 +1,61 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[1:]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + upper: None, + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_4.snap new file mode 100644 index 000000000..d65b89649 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_4.snap @@ -0,0 +1,73 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[:-1]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: None, + upper: Some( + Node { + node: Unary( + UnaryExpr { + op: USub, + operand: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 5, + }, + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 5, + }, + ), + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_5.snap new file mode 100644 index 000000000..d095deb1f --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_5.snap @@ -0,0 +1,85 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[1:len]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + upper: Some( + Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "len", + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 7, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 7, + }, + ), + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 8, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_6.snap new file mode 100644 index 000000000..16596547b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_6.snap @@ -0,0 +1,89 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[0:-1]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + upper: Some( + Node { + node: Unary( + UnaryExpr { + op: USub, + operand: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 5, + end_line: 1, + end_column: 6, + }, + }, + ), + filename: "", + line: 1, + column: 4, + end_line: 1, + end_column: 6, + }, + ), + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 7, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_7.snap new file mode 100644 index 000000000..efdc7b695 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_7.snap @@ -0,0 +1,45 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[::]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: None, + upper: None, + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 5, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_8.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_8.snap new file mode 100644 index 000000000..6a16c990c --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_8.snap @@ -0,0 +1,61 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[1::]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 2, + end_line: 1, + end_column: 3, + }, + ), + upper: None, + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_9.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_9.snap new file mode 100644 index 000000000..14164675c --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__subscript_expr_9.snap @@ -0,0 +1,61 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"a[:0:]\"####)" +--- +Node { + node: Subscript( + Subscript { + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "a", + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 1, + }, + index: None, + lower: None, + upper: Some( + Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 0, + ), + }, + ), + filename: "", + line: 1, + column: 3, + end_line: 1, + end_column: 4, + }, + ), + step: None, + ctx: Load, + has_question: false, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 6, +} + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__unary_expr.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__unary_expr.snap new file mode 100644 index 000000000..174b7eeec --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__expr__unary_expr.snap @@ -0,0 +1,32 @@ +--- +source: parser/src/tests/expr.rs +expression: "crate::tests::parsing_expr_string(r####\"+1\"####)" +--- +Node { + node: Unary( + UnaryExpr { + op: UAdd, + operand: Node { + node: NumberLit( + NumberLit { + binary_suffix: None, + value: Int( + 1, + ), + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 2, + }, + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 2, +} +