From 1cab9f4f6a300b1acdec446d1bb733ea042b13c6 Mon Sep 17 00:00:00 2001 From: he1pa <18012015693@163.com> Date: Tue, 15 Oct 2024 11:50:15 +0800 Subject: [PATCH] refactor: refactor parser. 1. remove pkg in module 2. Parser traversal import files from dfs to bfs Signed-off-by: he1pa <18012015693@163.com> --- kclvm/Cargo.lock | 1 + kclvm/api/src/capi_test.rs | 13 +- kclvm/api/src/service/service_impl.rs | 2 +- .../api/src/testdata/parse-file.response.json | 2 +- kclvm/ast/src/ast.rs | 1 - kclvm/ast/src/tests.rs | 3 - kclvm/loader/Cargo.toml | 1 + kclvm/loader/src/lib.rs | 6 +- kclvm/parser/src/file_graph.rs | 216 +++- kclvm/parser/src/lib.rs | 985 ++++++++++-------- kclvm/parser/src/parser/module.rs | 1 - kclvm/parser/src/tests.rs | 1 + ...kclvm_parser__tests__ast__assign_stmt.snap | 1 - .../kclvm_parser__tests__ast__basic_stmt.snap | 1 - .../kclvm_parser__tests__ast__if_stmt_0.snap | 1 - .../kclvm_parser__tests__ast__if_stmt_1.snap | 1 - ...kclvm_parser__tests__ast__schema_stmt.snap | 1 - ...rror_recovery__assert_stmt_recovery_0.snap | 2 - ...rror_recovery__assert_stmt_recovery_1.snap | 2 - ...rror_recovery__assert_stmt_recovery_2.snap | 2 - ...rror_recovery__assert_stmt_recovery_3.snap | 2 - ...rror_recovery__assign_stmt_recovery_0.snap | 1 - ...rror_recovery__assign_stmt_recovery_1.snap | 2 - ...ror_recovery__assign_stmt_recovery_10.snap | 1 - ...ror_recovery__assign_stmt_recovery_11.snap | 1 - ...ror_recovery__assign_stmt_recovery_12.snap | 1 - ...ror_recovery__assign_stmt_recovery_13.snap | 1 - ...ror_recovery__assign_stmt_recovery_14.snap | 1 - ...ror_recovery__assign_stmt_recovery_15.snap | 1 - ...ror_recovery__assign_stmt_recovery_16.snap | 1 - ...ror_recovery__assign_stmt_recovery_17.snap | 1 - ...ror_recovery__assign_stmt_recovery_18.snap | 1 - ...rror_recovery__assign_stmt_recovery_2.snap | 1 - ...rror_recovery__assign_stmt_recovery_3.snap | 1 - ...rror_recovery__assign_stmt_recovery_4.snap | 1 - ...rror_recovery__assign_stmt_recovery_5.snap | 1 - ...rror_recovery__assign_stmt_recovery_6.snap | 1 - ...rror_recovery__assign_stmt_recovery_7.snap | 1 - ...rror_recovery__assign_stmt_recovery_8.snap | 1 - ...rror_recovery__assign_stmt_recovery_9.snap | 1 - ...recovery__fn_ty_annotation_recovery_0.snap | 1 - ...recovery__fn_ty_annotation_recovery_1.snap | 1 - ...ecovery__fn_ty_annotation_recovery_10.snap | 1 - ...ecovery__fn_ty_annotation_recovery_11.snap | 1 - ...ecovery__fn_ty_annotation_recovery_12.snap | 1 - ...ecovery__fn_ty_annotation_recovery_13.snap | 1 - ...ecovery__fn_ty_annotation_recovery_14.snap | 1 - ...ecovery__fn_ty_annotation_recovery_15.snap | 1 - ...ecovery__fn_ty_annotation_recovery_16.snap | 1 - ...ecovery__fn_ty_annotation_recovery_17.snap | 1 - ...ecovery__fn_ty_annotation_recovery_18.snap | 1 - ...ecovery__fn_ty_annotation_recovery_19.snap | 1 - ...recovery__fn_ty_annotation_recovery_2.snap | 1 - ...ecovery__fn_ty_annotation_recovery_20.snap | 1 - ...ecovery__fn_ty_annotation_recovery_21.snap | 1 - ...ecovery__fn_ty_annotation_recovery_22.snap | 1 - ...ecovery__fn_ty_annotation_recovery_23.snap | 1 - ...recovery__fn_ty_annotation_recovery_3.snap | 1 - ...recovery__fn_ty_annotation_recovery_4.snap | 1 - ...recovery__fn_ty_annotation_recovery_5.snap | 1 - ...recovery__fn_ty_annotation_recovery_6.snap | 1 - ...recovery__fn_ty_annotation_recovery_7.snap | 1 - ...recovery__fn_ty_annotation_recovery_8.snap | 1 - ...recovery__fn_ty_annotation_recovery_9.snap | 1 - ...s__error_recovery__if_stmt_recovery_0.snap | 1 - ...s__error_recovery__if_stmt_recovery_1.snap | 1 - ...s__error_recovery__if_stmt_recovery_2.snap | 1 - ...s__error_recovery__if_stmt_recovery_3.snap | 1 - ...s__error_recovery__if_stmt_recovery_4.snap | 1 - ...s__error_recovery__if_stmt_recovery_5.snap | 2 - ...s__error_recovery__if_stmt_recovery_6.snap | 2 - ...s__error_recovery__if_stmt_recovery_7.snap | 2 - ...s__error_recovery__if_stmt_recovery_8.snap | 1 - ...s__error_recovery__if_stmt_recovery_9.snap | 1 - ...ts__error_recovery__import_recovery_0.snap | 2 - ...rror_recovery__import_stmt_recovery_0.snap | 2 - ...rror_recovery__import_stmt_recovery_1.snap | 2 - ...rror_recovery__import_stmt_recovery_2.snap | 2 - ...rror_recovery__import_stmt_recovery_3.snap | 2 - ...rror_recovery__import_stmt_recovery_4.snap | 2 - ...rror_recovery__import_stmt_recovery_5.snap | 2 - ...rror_recovery__import_stmt_recovery_6.snap | 2 - ..._error_recovery__rule_stmt_recovery_0.snap | 2 - ..._error_recovery__rule_stmt_recovery_1.snap | 2 - ..._error_recovery__rule_stmt_recovery_2.snap | 3 - ..._error_recovery__rule_stmt_recovery_3.snap | 2 - ..._error_recovery__rule_stmt_recovery_4.snap | 2 - ..._error_recovery__rule_stmt_recovery_5.snap | 2 - ..._error_recovery__rule_stmt_recovery_6.snap | 2 - ..._error_recovery__rule_stmt_recovery_7.snap | 2 - ...rror_recovery__schema_stmt_recovery_0.snap | 2 - ...rror_recovery__schema_stmt_recovery_1.snap | 2 - ...ror_recovery__schema_stmt_recovery_10.snap | 1 - ...ror_recovery__schema_stmt_recovery_11.snap | 1 - ...ror_recovery__schema_stmt_recovery_12.snap | 1 - ...ror_recovery__schema_stmt_recovery_13.snap | 1 - ...ror_recovery__schema_stmt_recovery_14.snap | 2 - ...ror_recovery__schema_stmt_recovery_15.snap | 2 - ...ror_recovery__schema_stmt_recovery_16.snap | 2 - ...ror_recovery__schema_stmt_recovery_17.snap | 1 - ...ror_recovery__schema_stmt_recovery_19.snap | 3 - ...rror_recovery__schema_stmt_recovery_2.snap | 3 - ...ror_recovery__schema_stmt_recovery_20.snap | 1 - ...ror_recovery__schema_stmt_recovery_21.snap | 1 - ...ror_recovery__schema_stmt_recovery_22.snap | 3 - ...ror_recovery__schema_stmt_recovery_23.snap | 1 - ...ror_recovery__schema_stmt_recovery_24.snap | 1 - ...ror_recovery__schema_stmt_recovery_25.snap | 2 - ...ror_recovery__schema_stmt_recovery_26.snap | 2 - ...ror_recovery__schema_stmt_recovery_27.snap | 2 - ...ror_recovery__schema_stmt_recovery_28.snap | 2 - ...ror_recovery__schema_stmt_recovery_29.snap | 2 - ...rror_recovery__schema_stmt_recovery_3.snap | 2 - ...ror_recovery__schema_stmt_recovery_30.snap | 2 - ...ror_recovery__schema_stmt_recovery_31.snap | 3 - ...ror_recovery__schema_stmt_recovery_32.snap | 3 - ...ror_recovery__schema_stmt_recovery_33.snap | 3 - ...ror_recovery__schema_stmt_recovery_34.snap | 1 - ...ror_recovery__schema_stmt_recovery_35.snap | 3 - ...ror_recovery__schema_stmt_recovery_36.snap | 1 - ...ror_recovery__schema_stmt_recovery_37.snap | 1 - ...ror_recovery__schema_stmt_recovery_38.snap | 1 - ...ror_recovery__schema_stmt_recovery_39.snap | 1 - ...rror_recovery__schema_stmt_recovery_4.snap | 2 - ...ror_recovery__schema_stmt_recovery_40.snap | 1 - ...rror_recovery__schema_stmt_recovery_5.snap | 2 - ...rror_recovery__schema_stmt_recovery_6.snap | 2 - ...rror_recovery__schema_stmt_recovery_7.snap | 1 - ...rror_recovery__schema_stmt_recovery_8.snap | 1 - ...rror_recovery__schema_stmt_recovery_9.snap | 1 - ...error_recovery__type_alias_recovery_0.snap | 2 - ...error_recovery__type_alias_recovery_1.snap | 2 - ...error_recovery__type_alias_recovery_2.snap | 2 - ...error_recovery__type_alias_recovery_3.snap | 2 - ...error_recovery__type_alias_recovery_4.snap | 2 - ...error_recovery__type_alias_recovery_5.snap | 2 - ...error_recovery__type_alias_recovery_6.snap | 2 - ...recovery__unification_stmt_recovery_0.snap | 1 - ...recovery__unification_stmt_recovery_1.snap | 1 - ...recovery__unification_stmt_recovery_2.snap | 1 - ...recovery__unification_stmt_recovery_3.snap | 1 - ...recovery__unification_stmt_recovery_4.snap | 1 - ...recovery__unification_stmt_recovery_5.snap | 1 - ...recovery__unification_stmt_recovery_6.snap | 1 - .../kclvm_parser__tests__file__assert_1.snap | 1 - .../kclvm_parser__tests__file__assert_2.snap | 1 - .../kclvm_parser__tests__file__assert_3.snap | 1 - ...clvm_parser__tests__file__assert_if_0.snap | 1 - ...clvm_parser__tests__file__assert_if_1.snap | 1 - ...clvm_parser__tests__file__assert_if_2.snap | 1 - .../kclvm_parser__tests__file__assign_1.snap | 1 - ...vm_parser__tests__file__config_expr_1.snap | 1 - ...vm_parser__tests__file__config_expr_2.snap | 1 - ...vm_parser__tests__file__config_expr_3.snap | 1 - ...vm_parser__tests__file__config_expr_4.snap | 1 - .../kclvm_parser__tests__file__hello_win.snap | 1 - .../kclvm_parser__tests__file__if_1.snap | 1 - .../kclvm_parser__tests__file__if_2.snap | 1 - .../kclvm_parser__tests__file__if_3.snap | 1 - .../kclvm_parser__tests__file__import_1.snap | 1 - .../kclvm_parser__tests__file__type_1.snap | 1 - kclvm/runner/src/lib.rs | 4 +- kclvm/runner/src/tests.rs | 3 +- kclvm/sema/src/pre_process/tests.rs | 2 +- kclvm/sema/src/resolver/import.rs | 1 - kclvm/sema/src/resolver/mod.rs | 1 + kclvm/sema/src/resolver/tests.rs | 1 - kclvm/sema/src/resolver/ty_alias.rs | 5 +- kclvm/tools/src/LSP/src/compile.rs | 3 - kclvm/tools/src/LSP/src/tests.rs | 30 +- kclvm/utils/src/path.rs | 3 + 171 files changed, 721 insertions(+), 774 deletions(-) diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 686c46163..69d66a520 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -1985,6 +1985,7 @@ dependencies = [ "kclvm-parser", "kclvm-query", "kclvm-sema", + "kclvm-utils", "maplit", ] diff --git a/kclvm/api/src/capi_test.rs b/kclvm/api/src/capi_test.rs index e48a49924..24ca0b32d 100644 --- a/kclvm/api/src/capi_test.rs +++ b/kclvm/api/src/capi_test.rs @@ -1,5 +1,6 @@ use crate::service::capi::*; use crate::{call, gpyrpc::*}; +use kclvm_utils::path::PathPrefix; use once_cell::sync::Lazy; use prost::Message; use serde::de::DeserializeOwned; @@ -9,7 +10,6 @@ use std::fs; use std::os::raw::c_char; use std::path::{Path, PathBuf}; use std::sync::Mutex; - const TEST_DATA_PATH: &str = "./src/testdata"; static TEST_MUTEX: Lazy> = Lazy::new(|| Mutex::new(0i32)); @@ -101,8 +101,17 @@ fn test_c_api_get_schema_type_mapping() { "get-schema-type-mapping.json", "get-schema-type-mapping.response.json", |r| { + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); for (_, s_ty) in &mut r.schema_type_mapping { - s_ty.filename = s_ty.filename.replace('/', "").replace('\\', "") + let filename = { + let filename = s_ty.filename.adjust_canonicalization(); + match filename.strip_prefix(root.to_str().unwrap()) { + Some(f) => f.to_string(), + None => s_ty.filename.clone(), + } + }; + + s_ty.filename = filename.replace('.', "").replace('/', "").replace('\\', "") } }, ); diff --git a/kclvm/api/src/service/service_impl.rs b/kclvm/api/src/service/service_impl.rs index 88ed0de7b..d63dae59a 100644 --- a/kclvm/api/src/service/service_impl.rs +++ b/kclvm/api/src/service/service_impl.rs @@ -188,7 +188,7 @@ impl KclvmServiceImpl { deps: result .deps .iter() - .map(|p| p.to_str().unwrap().to_string()) + .map(|p| p.path.to_str().unwrap().to_string()) .collect(), errors: result.errors.into_iter().map(|e| e.into_error()).collect(), }) diff --git a/kclvm/api/src/testdata/parse-file.response.json b/kclvm/api/src/testdata/parse-file.response.json index 8f259400e..740e3d84e 100644 --- a/kclvm/api/src/testdata/parse-file.response.json +++ b/kclvm/api/src/testdata/parse-file.response.json @@ -1,5 +1,5 @@ { - "ast_json": "{\"filename\":\"source.k\",\"pkg\":\"__main__\",\"doc\":null,\"name\":\"__main__\",\"body\":[{\"node\":{\"type\":\"Import\",\"path\":{\"node\":\"units\",\"filename\":\"source.k\",\"line\":1,\"column\":7,\"end_line\":1,\"end_column\":12},\"rawpath\":\"units\",\"name\":\"units\",\"asname\":null,\"pkg_name\":\"__main__\"},\"filename\":\"source.k\",\"line\":1,\"column\":0,\"end_line\":1,\"end_column\":12},{\"node\":{\"type\":\"Import\",\"path\":{\"node\":\"data.cloud\",\"filename\":\"source.k\",\"line\":2,\"column\":7,\"end_line\":2,\"end_column\":17},\"rawpath\":\"data.cloud\",\"name\":\"cloud_pkg\",\"asname\":{\"node\":\"cloud_pkg\",\"filename\":\"source.k\",\"line\":2,\"column\":21,\"end_line\":2,\"end_column\":30},\"pkg_name\":\"__main__\"},\"filename\":\"source.k\",\"line\":2,\"column\":0,\"end_line\":2,\"end_column\":30},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"data1\",\"filename\":\"source.k\",\"line\":4,\"column\":0,\"end_line\":4,\"end_column\":5},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":4,\"column\":0,\"end_line\":4,\"end_column\":5}],\"value\":{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"NumberLit\",\"binary_suffix\":null,\"value\":{\"type\":\"Int\",\"value\":32}},\"filename\":\"source.k\",\"line\":4,\"column\":8,\"end_line\":4,\"end_column\":10},\"op\":\"Mul\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"units\",\"filename\":\"source.k\",\"line\":4,\"column\":13,\"end_line\":4,\"end_column\":18},{\"node\":\"Ki\",\"filename\":\"source.k\",\"line\":4,\"column\":19,\"end_line\":4,\"end_column\":21}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":4,\"column\":13,\"end_line\":4,\"end_column\":21}},\"filename\":\"source.k\",\"line\":4,\"column\":8,\"end_line\":4,\"end_column\":21},\"ty\":null},\"filename\":\"source.k\",\"line\":4,\"column\":0,\"end_line\":4,\"end_column\":21},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"Data2\",\"filename\":\"source.k\",\"line\":5,\"column\":0,\"end_line\":5,\"end_column\":5},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":5,\"column\":0,\"end_line\":5,\"end_column\":5}],\"value\":{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"NumberLit\",\"binary_suffix\":null,\"value\":{\"type\":\"Int\",\"value\":42}},\"filename\":\"source.k\",\"line\":5,\"column\":8,\"end_line\":5,\"end_column\":10},\"op\":\"Mul\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"units\",\"filename\":\"source.k\",\"line\":5,\"column\":13,\"end_line\":5,\"end_column\":18},{\"node\":\"Ki\",\"filename\":\"source.k\",\"line\":5,\"column\":19,\"end_line\":5,\"end_column\":21}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":5,\"column\":13,\"end_line\":5,\"end_column\":21}},\"filename\":\"source.k\",\"line\":5,\"column\":8,\"end_line\":5,\"end_column\":21},\"op\":\"Mul\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"cloud_pkg\",\"filename\":\"source.k\",\"line\":5,\"column\":24,\"end_line\":5,\"end_column\":33},{\"node\":\"Foo\",\"filename\":\"source.k\",\"line\":5,\"column\":34,\"end_line\":5,\"end_column\":37}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":5,\"column\":24,\"end_line\":5,\"end_column\":37}},\"filename\":\"source.k\",\"line\":5,\"column\":8,\"end_line\":5,\"end_column\":37},\"ty\":null},\"filename\":\"source.k\",\"line\":5,\"column\":0,\"end_line\":5,\"end_column\":37},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"lambda1\",\"filename\":\"source.k\",\"line\":7,\"column\":0,\"end_line\":7,\"end_column\":7},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":7,\"column\":0,\"end_line\":7,\"end_column\":7}],\"value\":{\"node\":{\"type\":\"Lambda\",\"args\":{\"node\":{\"args\":[{\"node\":{\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":7,\"column\":17,\"end_line\":7,\"end_column\":18}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":7,\"column\":17,\"end_line\":7,\"end_column\":18},{\"node\":{\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":7,\"column\":25,\"end_line\":7,\"end_column\":26}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":7,\"column\":25,\"end_line\":7,\"end_column\":26}],\"defaults\":[null,null],\"ty_list\":[{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":7,\"column\":20,\"end_line\":7,\"end_column\":23},{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":7,\"column\":28,\"end_line\":7,\"end_column\":31}]},\"filename\":\"source.k\",\"line\":7,\"column\":17,\"end_line\":7,\"end_column\":31},\"body\":[{\"node\":{\"type\":\"Expr\",\"exprs\":[{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":5}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":5},\"op\":\"Sub\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":8,\"column\":8,\"end_line\":8,\"end_column\":9}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":8,\"column\":8,\"end_line\":8,\"end_column\":9}},\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":9}]},\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":9}],\"return_ty\":{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":7,\"column\":35,\"end_line\":7,\"end_column\":38}},\"filename\":\"source.k\",\"line\":7,\"column\":10,\"end_line\":9,\"end_column\":1},\"ty\":null},\"filename\":\"source.k\",\"line\":7,\"column\":0,\"end_line\":9,\"end_column\":1},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"Lambda2\",\"filename\":\"source.k\",\"line\":10,\"column\":0,\"end_line\":10,\"end_column\":7},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":10,\"column\":0,\"end_line\":10,\"end_column\":7}],\"value\":{\"node\":{\"type\":\"Lambda\",\"args\":{\"node\":{\"args\":[{\"node\":{\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":10,\"column\":17,\"end_line\":10,\"end_column\":18}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":10,\"column\":17,\"end_line\":10,\"end_column\":18},{\"node\":{\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":10,\"column\":25,\"end_line\":10,\"end_column\":26}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":10,\"column\":25,\"end_line\":10,\"end_column\":26}],\"defaults\":[null,null],\"ty_list\":[{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":10,\"column\":20,\"end_line\":10,\"end_column\":23},{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":10,\"column\":28,\"end_line\":10,\"end_column\":31}]},\"filename\":\"source.k\",\"line\":10,\"column\":17,\"end_line\":10,\"end_column\":31},\"body\":[{\"node\":{\"type\":\"Expr\",\"exprs\":[{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":5}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":5},\"op\":\"Add\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":11,\"column\":8,\"end_line\":11,\"end_column\":9}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":11,\"column\":8,\"end_line\":11,\"end_column\":9}},\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":9}]},\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":9}],\"return_ty\":{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":10,\"column\":35,\"end_line\":10,\"end_column\":38}},\"filename\":\"source.k\",\"line\":10,\"column\":10,\"end_line\":12,\"end_column\":1},\"ty\":null},\"filename\":\"source.k\",\"line\":10,\"column\":0,\"end_line\":12,\"end_column\":1}],\"comments\":[]}", + "ast_json": "{\"filename\":\"source.k\",\"doc\":null,\"name\":\"__main__\",\"body\":[{\"node\":{\"type\":\"Import\",\"path\":{\"node\":\"units\",\"filename\":\"source.k\",\"line\":1,\"column\":7,\"end_line\":1,\"end_column\":12},\"rawpath\":\"units\",\"name\":\"units\",\"asname\":null,\"pkg_name\":\"__main__\"},\"filename\":\"source.k\",\"line\":1,\"column\":0,\"end_line\":1,\"end_column\":12},{\"node\":{\"type\":\"Import\",\"path\":{\"node\":\"data.cloud\",\"filename\":\"source.k\",\"line\":2,\"column\":7,\"end_line\":2,\"end_column\":17},\"rawpath\":\"data.cloud\",\"name\":\"cloud_pkg\",\"asname\":{\"node\":\"cloud_pkg\",\"filename\":\"source.k\",\"line\":2,\"column\":21,\"end_line\":2,\"end_column\":30},\"pkg_name\":\"__main__\"},\"filename\":\"source.k\",\"line\":2,\"column\":0,\"end_line\":2,\"end_column\":30},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"data1\",\"filename\":\"source.k\",\"line\":4,\"column\":0,\"end_line\":4,\"end_column\":5},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":4,\"column\":0,\"end_line\":4,\"end_column\":5}],\"value\":{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"NumberLit\",\"binary_suffix\":null,\"value\":{\"type\":\"Int\",\"value\":32}},\"filename\":\"source.k\",\"line\":4,\"column\":8,\"end_line\":4,\"end_column\":10},\"op\":\"Mul\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"units\",\"filename\":\"source.k\",\"line\":4,\"column\":13,\"end_line\":4,\"end_column\":18},{\"node\":\"Ki\",\"filename\":\"source.k\",\"line\":4,\"column\":19,\"end_line\":4,\"end_column\":21}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":4,\"column\":13,\"end_line\":4,\"end_column\":21}},\"filename\":\"source.k\",\"line\":4,\"column\":8,\"end_line\":4,\"end_column\":21},\"ty\":null},\"filename\":\"source.k\",\"line\":4,\"column\":0,\"end_line\":4,\"end_column\":21},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"Data2\",\"filename\":\"source.k\",\"line\":5,\"column\":0,\"end_line\":5,\"end_column\":5},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":5,\"column\":0,\"end_line\":5,\"end_column\":5}],\"value\":{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"NumberLit\",\"binary_suffix\":null,\"value\":{\"type\":\"Int\",\"value\":42}},\"filename\":\"source.k\",\"line\":5,\"column\":8,\"end_line\":5,\"end_column\":10},\"op\":\"Mul\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"units\",\"filename\":\"source.k\",\"line\":5,\"column\":13,\"end_line\":5,\"end_column\":18},{\"node\":\"Ki\",\"filename\":\"source.k\",\"line\":5,\"column\":19,\"end_line\":5,\"end_column\":21}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":5,\"column\":13,\"end_line\":5,\"end_column\":21}},\"filename\":\"source.k\",\"line\":5,\"column\":8,\"end_line\":5,\"end_column\":21},\"op\":\"Mul\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"cloud_pkg\",\"filename\":\"source.k\",\"line\":5,\"column\":24,\"end_line\":5,\"end_column\":33},{\"node\":\"Foo\",\"filename\":\"source.k\",\"line\":5,\"column\":34,\"end_line\":5,\"end_column\":37}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":5,\"column\":24,\"end_line\":5,\"end_column\":37}},\"filename\":\"source.k\",\"line\":5,\"column\":8,\"end_line\":5,\"end_column\":37},\"ty\":null},\"filename\":\"source.k\",\"line\":5,\"column\":0,\"end_line\":5,\"end_column\":37},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"lambda1\",\"filename\":\"source.k\",\"line\":7,\"column\":0,\"end_line\":7,\"end_column\":7},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":7,\"column\":0,\"end_line\":7,\"end_column\":7}],\"value\":{\"node\":{\"type\":\"Lambda\",\"args\":{\"node\":{\"args\":[{\"node\":{\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":7,\"column\":17,\"end_line\":7,\"end_column\":18}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":7,\"column\":17,\"end_line\":7,\"end_column\":18},{\"node\":{\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":7,\"column\":25,\"end_line\":7,\"end_column\":26}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":7,\"column\":25,\"end_line\":7,\"end_column\":26}],\"defaults\":[null,null],\"ty_list\":[{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":7,\"column\":20,\"end_line\":7,\"end_column\":23},{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":7,\"column\":28,\"end_line\":7,\"end_column\":31}]},\"filename\":\"source.k\",\"line\":7,\"column\":17,\"end_line\":7,\"end_column\":31},\"body\":[{\"node\":{\"type\":\"Expr\",\"exprs\":[{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":5}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":5},\"op\":\"Sub\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":8,\"column\":8,\"end_line\":8,\"end_column\":9}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":8,\"column\":8,\"end_line\":8,\"end_column\":9}},\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":9}]},\"filename\":\"source.k\",\"line\":8,\"column\":4,\"end_line\":8,\"end_column\":9}],\"return_ty\":{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":7,\"column\":35,\"end_line\":7,\"end_column\":38}},\"filename\":\"source.k\",\"line\":7,\"column\":10,\"end_line\":9,\"end_column\":1},\"ty\":null},\"filename\":\"source.k\",\"line\":7,\"column\":0,\"end_line\":9,\"end_column\":1},{\"node\":{\"type\":\"Assign\",\"targets\":[{\"node\":{\"name\":{\"node\":\"Lambda2\",\"filename\":\"source.k\",\"line\":10,\"column\":0,\"end_line\":10,\"end_column\":7},\"paths\":[],\"pkgpath\":\"\"},\"filename\":\"source.k\",\"line\":10,\"column\":0,\"end_line\":10,\"end_column\":7}],\"value\":{\"node\":{\"type\":\"Lambda\",\"args\":{\"node\":{\"args\":[{\"node\":{\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":10,\"column\":17,\"end_line\":10,\"end_column\":18}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":10,\"column\":17,\"end_line\":10,\"end_column\":18},{\"node\":{\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":10,\"column\":25,\"end_line\":10,\"end_column\":26}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":10,\"column\":25,\"end_line\":10,\"end_column\":26}],\"defaults\":[null,null],\"ty_list\":[{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":10,\"column\":20,\"end_line\":10,\"end_column\":23},{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":10,\"column\":28,\"end_line\":10,\"end_column\":31}]},\"filename\":\"source.k\",\"line\":10,\"column\":17,\"end_line\":10,\"end_column\":31},\"body\":[{\"node\":{\"type\":\"Expr\",\"exprs\":[{\"node\":{\"type\":\"Binary\",\"left\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"x\",\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":5}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":5},\"op\":\"Add\",\"right\":{\"node\":{\"type\":\"Identifier\",\"names\":[{\"node\":\"y\",\"filename\":\"source.k\",\"line\":11,\"column\":8,\"end_line\":11,\"end_column\":9}],\"pkgpath\":\"\",\"ctx\":\"Load\"},\"filename\":\"source.k\",\"line\":11,\"column\":8,\"end_line\":11,\"end_column\":9}},\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":9}]},\"filename\":\"source.k\",\"line\":11,\"column\":4,\"end_line\":11,\"end_column\":9}],\"return_ty\":{\"node\":{\"type\":\"Basic\",\"value\":\"Int\"},\"filename\":\"source.k\",\"line\":10,\"column\":35,\"end_line\":10,\"end_column\":38}},\"filename\":\"source.k\",\"line\":10,\"column\":10,\"end_line\":12,\"end_column\":1},\"ty\":null},\"filename\":\"source.k\",\"line\":10,\"column\":0,\"end_line\":12,\"end_column\":1}],\"comments\":[]}", "deps": [], "errors": [ { diff --git a/kclvm/ast/src/ast.rs b/kclvm/ast/src/ast.rs index 9f89c35ea..5196d3341 100644 --- a/kclvm/ast/src/ast.rs +++ b/kclvm/ast/src/ast.rs @@ -422,7 +422,6 @@ impl Program { #[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)] pub struct Module { pub filename: String, - pub pkg: String, pub doc: Option>, pub name: String, pub body: Vec>, diff --git a/kclvm/ast/src/tests.rs b/kclvm/ast/src/tests.rs index cdc5f903e..bfb931a86 100644 --- a/kclvm/ast/src/tests.rs +++ b/kclvm/ast/src/tests.rs @@ -179,7 +179,6 @@ fn test_try_from_for_nameconstant() { fn test_filter_schema_with_no_schema() { let ast_mod = Module { filename: "".to_string(), - pkg: "".to_string(), doc: Some(node_ref!("".to_string())), name: "".to_string(), body: vec![], @@ -193,7 +192,6 @@ fn test_filter_schema_with_no_schema() { fn test_filter_schema_with_one_schema() { let mut ast_mod = Module { filename: "".to_string(), - pkg: "".to_string(), doc: Some(node_ref!("".to_string())), name: "".to_string(), body: vec![], @@ -210,7 +208,6 @@ fn test_filter_schema_with_one_schema() { fn test_filter_schema_with_mult_schema() { let mut ast_mod = Module { filename: "".to_string(), - pkg: "".to_string(), doc: Some(node_ref!("".to_string())), name: "".to_string(), body: vec![], diff --git a/kclvm/loader/Cargo.toml b/kclvm/loader/Cargo.toml index bab3aff8f..6fab51e8b 100644 --- a/kclvm/loader/Cargo.toml +++ b/kclvm/loader/Cargo.toml @@ -15,6 +15,7 @@ kclvm-parser = {path = "../parser"} kclvm-sema = {path = "../sema"} kclvm-error = {path = "../error"} kclvm-query = {path = "../query"} +kclvm-utils = {path = "../utils"} maplit = "1.0.2" [dev-dependencies] diff --git a/kclvm/loader/src/lib.rs b/kclvm/loader/src/lib.rs index df07b00de..721657fa4 100644 --- a/kclvm/loader/src/lib.rs +++ b/kclvm/loader/src/lib.rs @@ -23,6 +23,7 @@ use kclvm_sema::{ }, ty::{Type, TypeRef}, }; +use kclvm_utils::path::PathPrefix; use std::path::PathBuf; type Errors = IndexSet; @@ -195,8 +196,9 @@ pub fn load_packages_with_cache( for path in &packages.paths { let path_str = path .to_str() - .ok_or(anyhow::anyhow!("path {} to str failed", path.display()))?; - if let Some(files) = gs.get_sema_db().get_file_sema(path_str) { + .ok_or(anyhow::anyhow!("path {} to str failed", path.display()))? + .adjust_canonicalization(); + if let Some(files) = gs.get_sema_db().get_file_sema(&path_str) { for symbol_ref in files.get_symbols() { if let Some(symbol) = symbols.get_symbol(*symbol_ref) { let def_ty = match symbol.get_definition() { diff --git a/kclvm/parser/src/file_graph.rs b/kclvm/parser/src/file_graph.rs index 31ad0322b..84ca6d188 100644 --- a/kclvm/parser/src/file_graph.rs +++ b/kclvm/parser/src/file_graph.rs @@ -1,23 +1,49 @@ +use std::{collections::HashMap, path::PathBuf}; + use indexmap::IndexMap; -use petgraph::visit::EdgeRef; -use std::path::{Path, PathBuf}; +use kclvm_ast::ast::Module; +use petgraph::{prelude::StableDiGraph, visit::EdgeRef}; +use std::hash::Hash; +/// File with package info +#[derive(Debug, Clone, Hash, Eq, PartialEq)] +pub struct PkgFile { + pub path: PathBuf, + pub pkg_path: String, +} + +impl PkgFile { + pub fn canonicalize(&self) -> PathBuf { + match self.path.canonicalize() { + Ok(p) => p.clone(), + _ => self.path.clone(), + } + } +} + +#[derive(Debug, Clone, Hash, Eq, PartialEq)] +pub struct Pkg { + pub pkg_name: String, + pub pkg_root: String, +} + +pub type PkgMap = HashMap; /// A graph of files, where each file depends on zero or more other files. #[derive(Default)] -pub struct FileGraph { - graph: petgraph::stable_graph::StableDiGraph, - path_to_node_index: IndexMap, +pub struct PkgFileGraph { + graph: StableDiGraph, + path_to_node_index: IndexMap, } -impl FileGraph { +impl PkgFileGraph { /// Sets a file to depend on the given other files. /// /// For example, if the current graph has file A depending on B, and /// `update_file(pathA, &[pathC])` was called, then this function will remove the edge /// from A to B, and add an edge from A to C. - pub fn update_file<'a, I: IntoIterator>( + pub fn update_file<'a, I: IntoIterator>( &mut self, - from_path: &Path, + from_path: &PkgFile, to_paths: I, ) { let from_node_index = self.get_or_insert_node_index(from_path); @@ -39,68 +65,152 @@ impl FileGraph { } /// Returns true if the given file is in the graph - pub fn contains_file(&mut self, path: &Path) -> bool { - self.path_to_node_index.contains_key(path) + pub fn contains_file(&self, file: &PkgFile) -> bool { + contains_file(file, &self.path_to_node_index) } /// Returns a list of the direct dependencies of the given file. /// (does not include all transitive dependencies) /// The file path must be relative to the root of the file graph. - pub fn dependencies_of(&self, path: &Path) -> Vec<&PathBuf> { - let node_index = self - .path_to_node_index - .get(path) - .expect("path not in graph"); - self.graph - .edges(*node_index) - .map(|edge| &self.graph[edge.target()]) - .collect::>() + pub fn dependencies_of(&self, file: &PkgFile) -> Vec { + dependencies_of(file, &self.graph, &self.path_to_node_index) } - /// Returns a list of files in the order they should be compiled - /// Or a list of files that are part of a cycle, if one exists - pub fn toposort(&self) -> Result, Vec> { - match petgraph::algo::toposort(&self.graph, None) { - Ok(indices) => Ok(indices - .into_iter() - .rev() - .map(|n| self.graph[n].clone()) - .collect::>()), - Err(err) => { - // toposort function in the `petgraph` library doesn't return the cycle itself, - // so we need to use Tarjan's algorithm to find one instead - let strongly_connected_components = petgraph::algo::tarjan_scc(&self.graph); - - // a strongly connected component is a cycle if it has more than one node - // let's just return the first one we find - let cycle = match strongly_connected_components - .into_iter() - .find(|component| component.len() > 1) - { - Some(vars) => vars, - None => vec![err.node_id()], - }; - Err(cycle - .iter() - .map(|n| self.graph[*n].clone()) - .collect::>()) - } - } + pub fn toposort(&self) -> Result, Vec> { + toposort(&self.graph) } /// Returns all paths. #[inline] - pub fn paths(&self) -> Vec { + pub fn paths(&self) -> Vec { self.path_to_node_index.keys().cloned().collect::>() } - fn get_or_insert_node_index(&mut self, path: &Path) -> petgraph::graph::NodeIndex { - if let Some(node_index) = self.path_to_node_index.get(path) { + fn get_or_insert_node_index(&mut self, file: &PkgFile) -> petgraph::graph::NodeIndex { + if let Some(node_index) = self.path_to_node_index.get(file) { return *node_index; } - let node_index = self.graph.add_node(path.to_owned()); - self.path_to_node_index.insert(path.to_owned(), node_index); + let node_index = self.graph.add_node(file.to_owned()); + self.path_to_node_index.insert(file.to_owned(), node_index); node_index } + + pub fn file_path_graph( + &self, + ) -> ( + StableDiGraph, + IndexMap, + ) { + let mut graph = StableDiGraph::new(); + let mut node_map = IndexMap::new(); + for node in self.graph.node_indices() { + let path = self.graph[node].path.clone(); + let idx = graph.add_node(path.clone()); + node_map.insert(path, idx); + } + for edge in self.graph.edge_indices() { + if let Some((source, target)) = self.graph.edge_endpoints(edge) { + let source_path = self.graph[source].path.clone(); + let target_path = self.graph[target].path.clone(); + graph.add_edge( + node_map.get(&source_path).unwrap().clone(), + node_map.get(&target_path).unwrap().clone(), + (), + ); + } + } + (graph, node_map) + } + + pub fn pkg_graph( + &self, + pkgs: &HashMap>, + ) -> ( + StableDiGraph, + IndexMap, + ) { + let mut graph = StableDiGraph::new(); + let mut node_map = IndexMap::new(); + + for pkg in pkgs.keys() { + let idx = graph.add_node(pkg.clone()); + node_map.insert(pkg.clone(), idx); + } + + for node in self.graph.node_indices() { + let path = self.graph[node].pkg_path.clone(); + let idx = graph.add_node(path.clone()); + node_map.insert(path, idx); + } + for edge in self.graph.edge_indices() { + if let Some((source, target)) = self.graph.edge_endpoints(edge) { + let source_path = self.graph[source].pkg_path.clone(); + let target_path = self.graph[target].pkg_path.clone(); + graph.add_edge( + node_map.get(&source_path).unwrap().clone(), + node_map.get(&target_path).unwrap().clone(), + (), + ); + } + } + (graph, node_map) + } +} + +/// Returns a list of files in the order they should be compiled +/// Or a list of files that are part of a cycle, if one exists +pub fn toposort(graph: &StableDiGraph) -> Result, Vec> +where + T: Clone, +{ + match petgraph::algo::toposort(graph, None) { + Ok(indices) => Ok(indices + .into_iter() + .rev() + .map(|n| graph[n].clone()) + .collect::>()), + Err(err) => { + // toposort function in the `petgraph` library doesn't return the cycle itself, + // so we need to use Tarjan's algorithm to find one instead + let strongly_connected_components = petgraph::algo::tarjan_scc(&graph); + // a strongly connected component is a cycle if it has more than one node + // let's just return the first one we find + let cycle = match strongly_connected_components + .into_iter() + .find(|component| component.len() > 1) + { + Some(vars) => vars, + None => vec![err.node_id()], + }; + Err(cycle.iter().map(|n| graph[*n].clone()).collect::>()) + } + } +} + +/// Returns a list of the direct dependencies of the given file. +/// (does not include all transitive dependencies) +/// The file path must be relative to the root of the file graph. +pub fn dependencies_of( + node: &T, + graph: &StableDiGraph, + id_map: &IndexMap, +) -> Vec +where + T: Clone + Hash + Eq + PartialEq, +{ + let node_index = id_map.get(node).expect("node not in graph"); + graph + .edges(*node_index) + .map(|edge| &graph[edge.target()]) + .map(|node| node.clone()) + .collect::>() +} + +/// Returns true if the given file is in the graph +pub fn contains_file(node: &T, id_map: &IndexMap) -> bool +where + T: Clone + Hash + Eq + PartialEq, +{ + id_map.contains_key(node) } diff --git a/kclvm/parser/src/lib.rs b/kclvm/parser/src/lib.rs index 01b31bcbe..cd7390ea5 100644 --- a/kclvm/parser/src/lib.rs +++ b/kclvm/parser/src/lib.rs @@ -16,9 +16,10 @@ pub use crate::session::{ParseSession, ParseSessionRef}; use compiler_base_macros::bug; use compiler_base_session::Session; use compiler_base_span::span::new_byte_pos; -use file_graph::FileGraph; +use file_graph::{toposort, Pkg, PkgFile, PkgFileGraph, PkgMap}; use indexmap::IndexMap; -use kclvm_ast::ast; +use kclvm_ast::ast::Module; +use kclvm_ast::{ast, MAIN_PKG}; use kclvm_config::modfile::{get_vendor_home, KCL_FILE_EXTENSION, KCL_FILE_SUFFIX, KCL_MOD_FILE}; use kclvm_error::diagnostic::{Errors, Range}; use kclvm_error::{ErrorKind, Message, Position, Style}; @@ -30,8 +31,8 @@ use kclvm_utils::pkgpath::rm_external_pkg_name; use anyhow::Result; use lexer::parse_token_streams; use parser::Parser; -use std::collections::HashMap; -use std::path::{Path, PathBuf}; +use std::collections::{HashMap, VecDeque}; +use std::path::PathBuf; use std::sync::{Arc, RwLock}; use kclvm_span::create_session_globals_then; @@ -94,7 +95,7 @@ pub struct ParseFileResult { /// Parse errors pub errors: Errors, /// Dependency paths. - pub deps: Vec, + pub deps: Vec, } /// Parse a KCL file to the AST module with parse errors. @@ -119,21 +120,20 @@ pub fn parse_file(filename: &str, code: Option) -> Result module.clone(), None => ast::Module::default(), }; - let filename = module.filename.clone(); - let path = Path::new(&filename); + let file_graph = loader.file_graph.read().unwrap(); + let file = PkgFile { + path: PathBuf::from(filename), + pkg_path: MAIN_PKG.to_string(), + }; + let deps = if file_graph.contains_file(&file) { + file_graph.dependencies_of(&file).into_iter().collect() + } else { + vec![] + }; Ok(ParseFileResult { module, errors: result.errors.clone(), - deps: if loader.file_graph.contains_file(path) { - loader - .file_graph - .dependencies_of(path) - .into_iter() - .cloned() - .collect() - } else { - vec![] - }, + deps, }) } @@ -193,7 +193,6 @@ pub fn parse_file_with_session( let mut p = parser::Parser::new(&sess, stream); let mut m = p.parse_module(); m.filename = filename.to_string().adjust_canonicalization(); - m.pkg = kclvm_ast::MAIN_PKG.to_string(); m.name = kclvm_ast::MAIN_PKG.to_string(); Ok(m) @@ -311,6 +310,7 @@ pub type KCLModuleCache = Arc>; #[derive(Default, Debug)] pub struct ModuleCache { pub ast_cache: IndexMap, + pub asts: ASTCache, /// Invalid modules and new code, equivalent to paths and k_code_list. The difference is that paths is in the main package. pub invalidate_module: HashMap>, } @@ -318,9 +318,8 @@ struct Loader { sess: ParseSessionRef, paths: Vec, opts: LoadProgramOptions, - missing_pkgs: Vec, module_cache: Option, - file_graph: FileGraph, + file_graph: FileGraphCache, } impl Loader { @@ -338,8 +337,7 @@ impl Loader { .collect(), opts: opts.unwrap_or_default(), module_cache, - missing_pkgs: Default::default(), - file_graph: FileGraph::default(), + file_graph: FileGraphCache::default(), } } @@ -349,509 +347,580 @@ impl Loader { } fn _load_main(&mut self) -> Result { - let compile_entries = get_compile_entries_from_paths(&self.paths, &self.opts)?; - let workdir = compile_entries.get_root_path().to_string(); - let mut pkgs = HashMap::new(); - let mut pkg_files = Vec::new(); - // update cache - if let Some(module_cache) = self.module_cache.as_ref() { - for entry in compile_entries.iter() { - let k_files = entry.get_k_files(); - let maybe_k_codes = entry.get_k_codes(); - // update main pkg ast cache - for (i, filename) in k_files.iter().enumerate() { - let m = parse_file_with_session( - self.sess.clone(), - filename, - maybe_k_codes[i].clone(), - )?; - let mut module_cache_ref = module_cache.write().unwrap(); - module_cache_ref - .ast_cache - .insert(filename.clone(), m.clone()); - } - // update invalidate module ast cache - let mut module_cache_ref = module_cache.write().unwrap(); - let invalidate_module = module_cache_ref.invalidate_module.clone(); - module_cache_ref.invalidate_module.clear(); - drop(module_cache_ref); - - for (filename, code) in invalidate_module.iter() { - let m = parse_file_with_session(self.sess.clone(), filename, code.clone())?; - let mut module_cache_ref = module_cache.write().unwrap(); - module_cache_ref - .ast_cache - .insert(filename.clone(), m.clone()); - } - } - } + let asts = match &self.module_cache { + Some(c) => c.read().unwrap().asts.clone(), + None => ASTCache::default(), + }; + let res = parse_kcl_program( + self.sess.clone(), + self.paths.clone(), + asts, + self.file_graph.clone(), + &self.opts, + ); + return res; + } +} - for entry in compile_entries.iter() { - let k_files = entry.get_k_files(); - let maybe_k_codes = entry.get_k_codes(); - // Load main package. - for (i, filename) in k_files.iter().enumerate() { - let mut m = if let Some(module_cache) = self.module_cache.as_ref() { - let module_cache_ref = module_cache.read().unwrap(); - module_cache_ref.ast_cache.get(filename).unwrap().clone() - } else { - parse_file_with_session(self.sess.clone(), filename, maybe_k_codes[i].clone())? - }; - fix_rel_import_path(entry.path(), &mut m); - pkg_files.push(m); +fn fix_rel_import_path_with_file( + pkgroot: &str, + m: &mut ast::Module, + file: &PkgFile, + pkgmap: &PkgMap, + opts: LoadProgramOptions, + sess: ParseSessionRef, +) { + for stmt in &mut m.body { + let pos = stmt.pos().clone(); + if let ast::Stmt::Import(ref mut import_spec) = &mut stmt.node { + let fix_path = kclvm_config::vfs::fix_import_path( + pkgroot, + &m.filename, + import_spec.path.node.as_str(), + ); + import_spec.path.node = fix_path.clone(); + + let pkg = pkgmap.get(&file).expect("file not in pkgmap").clone(); + import_spec.pkg_name = pkg.pkg_name.clone(); + // Load the import package source code and compile. + let pkg_info = find_packages( + pos.into(), + &pkg.pkg_name, + &pkg.pkg_root, + &fix_path, + opts.clone(), + sess.clone(), + ) + .unwrap(); + if let Some(pkg_info) = &pkg_info { + // Add the external package name as prefix of the [`kclvm_ast::ImportStmt`]'s member [`path`]. + import_spec.path.node = pkg_info.pkg_path.to_string(); + import_spec.pkg_name = pkg_info.pkg_name.clone(); } - - // Insert an empty vec to determine whether there is a circular import. - pkgs.insert(kclvm_ast::MAIN_PKG.to_string(), vec![]); - self.load_import_package( - entry.path(), - entry.name().to_string(), - &mut pkg_files, - &mut pkgs, - )?; } - // Insert the complete ast to replace the empty list. - pkgs.insert(kclvm_ast::MAIN_PKG.to_string(), pkg_files); - let program = ast::Program { - root: workdir, - pkgs, - }; - // Return the files in the order they should be compiled - let paths = match self.file_graph.toposort() { - Ok(files) => files, - Err(cycle) => { - let formatted_cycle = cycle - .iter() - .map(|path| format!("- {}\n", path.to_string_lossy())) - .collect::(); - - self.sess.1.write().add_error( - ErrorKind::RecursiveLoad, - &[Message { - range: (Position::dummy_pos(), Position::dummy_pos()), - style: Style::Line, - message: format!( - "Could not compiles due to cyclic import statements\n{}", - formatted_cycle.trim_end() - ), - note: None, - suggested_replacement: None, - }], - ); + } +} - // Return a list of all paths. - self.file_graph.paths() - } - }; +fn is_plugin_pkg(pkgpath: &str) -> bool { + pkgpath.starts_with(PLUGIN_MODULE_PREFIX) +} - Ok(LoadProgramResult { - program, - errors: self.sess.1.read().diagnostics.clone(), - paths, - }) +fn is_builtin_pkg(pkgpath: &str) -> bool { + let system_modules = kclvm_sema::builtin::system_module::STANDARD_SYSTEM_MODULES; + system_modules.contains(&pkgpath) +} + +fn find_packages( + pos: ast::Pos, + pkg_name: &str, + pkg_root: &str, + pkg_path: &str, + opts: LoadProgramOptions, + sess: ParseSessionRef, +) -> Result> { + if pkg_path.is_empty() { + return Ok(None); } - /// [`find_packages`] will find the kcl package. - /// If the package is found, the basic information of the package [`PkgInfo`] will be returned. - /// - /// # Errors - /// - /// This method will return an error in the following two cases: - /// - /// 1. The package not found. - /// 2. The package was found both internal and external the current package. - fn find_packages( - &self, - pos: ast::Pos, - pkg_name: &str, - pkg_root: &str, - pkg_path: &str, - ) -> Result> { - // 1. Look for in the current package's directory. - let is_internal = self.is_internal_pkg(pkg_name, pkg_root, pkg_path)?; - - // 2. Look for in the vendor path. - let is_external = self.is_external_pkg(pkg_path)?; - - // 3. Internal and external packages cannot be duplicated - if is_external.is_some() && is_internal.is_some() { - self.sess.1.write().add_error( + // plugin pkgs + if is_plugin_pkg(pkg_path) { + if !opts.load_plugins { + sess.1.write().add_error( ErrorKind::CannotFindModule, &[Message { range: Into::::into(pos), style: Style::Line, - message: format!( - "the `{}` is found multiple times in the current package and vendor package", - pkg_path - ), + message: format!("the plugin package `{}` is not found, please confirm if plugin mode is enabled", pkg_path), note: None, suggested_replacement: None, }], ); - return Ok(None); - } - - // 4. Get package information based on whether the package is internal or external. - match is_internal.or(is_external) { - Some(pkg_info) => Ok(Some(pkg_info)), - None => { - self.sess.1.write().add_error( - ErrorKind::CannotFindModule, - &[Message { - range: Into::::into(pos), - style: Style::Line, - message: format!("pkgpath {} not found in the program", pkg_path), - note: None, - suggested_replacement: None, - }], - ); - let mut suggestions = - vec![format!("browse more packages at 'https://artifacthub.io'")]; - - if let Ok(pkg_name) = parse_external_pkg_name(pkg_path) { - suggestions.insert( - 0, - format!( - "try 'kcl mod add {}' to download the missing package", - pkg_name - ), - ); - } - self.sess.1.write().add_suggestions(suggestions); - Ok(None) - } } + return Ok(None); } - /// [`load_import_package`] will traverse all the [`kclvm_ast::ImportStmt`] on the input AST nodes [`pkg`], - /// load the source code and parse the code to corresponding AST. - /// - /// And store the result of parse in [`pkgs`]. - /// - /// # Note - /// [`load_import_package`] will add the external package name as prefix of the [`kclvm_ast::ImportStmt`]'s member [`path`]. - fn load_import_package( - &mut self, - pkgroot: &str, - pkg_name: String, - pkg: &mut [ast::Module], - pkgs: &mut HashMap>, - ) -> Result<()> { - for m in pkg { - let mut to_paths: Vec = vec![]; - for stmt in &mut m.body { - let pos = stmt.pos().clone(); - if let ast::Stmt::Import(ref mut import_spec) = &mut stmt.node { - import_spec.path.node = kclvm_config::vfs::fix_import_path( - pkgroot, - &m.filename, - import_spec.path.node.as_str(), - ); - import_spec.pkg_name = pkg_name.to_string(); - // Load the import package source code and compile. - let pkg_info = self.load_package( - pkgroot, - pkg_name.to_string(), - import_spec.path.node.to_string(), - pos.into(), - pkgs, - )?; - if let Some(pkg_info) = &pkg_info { - // Add the external package name as prefix of the [`kclvm_ast::ImportStmt`]'s member [`path`]. - import_spec.path.node = pkg_info.pkg_path.to_string(); - import_spec.pkg_name = pkg_info.pkg_name.clone(); - // Add file dependencies. - let mut paths: Vec = - pkg_info.k_files.iter().map(PathBuf::from).collect(); - to_paths.append(&mut paths); - } - } - } - self.file_graph - .update_file(Path::new(&m.filename), &to_paths); - } - Ok(()) + // builtin pkgs + if is_builtin_pkg(pkg_path) { + return Ok(None); } - /// [`load_package`] will return some basic information about the package - /// according to whether the package is internal or external. - fn load_package( - &mut self, - pkgroot: &str, - pkgname: String, - pkgpath: String, - pos: ast::Pos, - pkgs: &mut HashMap>, - ) -> Result> { - if pkgpath.is_empty() { - return Ok(None); - } + // 1. Look for in the current package's directory. + let is_internal = is_internal_pkg(pkg_name, pkg_root, pkg_path)?; + // 2. Look for in the vendor path. + let is_external = is_external_pkg(pkg_path, opts)?; + + // 3. Internal and external packages cannot be duplicated + if is_external.is_some() && is_internal.is_some() { + sess.1.write().add_error( + ErrorKind::CannotFindModule, + &[Message { + range: Into::::into(pos), + style: Style::Line, + message: format!( + "the `{}` is found multiple times in the current package and vendor package", + pkg_path + ), + note: None, + suggested_replacement: None, + }], + ); + return Ok(None); + } - if pkgs.contains_key(&pkgpath) { - return Ok(None); - } - if self.missing_pkgs.contains(&pkgpath) { - return Ok(None); - } + // 4. Get package information based on whether the package is internal or external. - // plugin pkgs - if self.is_plugin_pkg(pkgpath.as_str()) { - if !self.opts.load_plugins { - self.sess.1.write().add_error( - ErrorKind::CannotFindModule, - &[Message { - range: Into::::into(pos), - style: Style::Line, - message: format!("the plugin package `{}` is not found, please confirm if plugin mode is enabled", pkgpath), - note: None, - suggested_replacement: None, - }], + match is_internal.or(is_external) { + Some(pkg_info) => Ok(Some(pkg_info)), + None => { + sess.1.write().add_error( + ErrorKind::CannotFindModule, + &[Message { + range: Into::::into(pos), + style: Style::Line, + message: format!("pkgpath {} not found in the program", pkg_path), + note: None, + suggested_replacement: None, + }], + ); + let mut suggestions = vec![format!("browse more packages at 'https://artifacthub.io'")]; + + if let Ok(pkg_name) = parse_external_pkg_name(pkg_path) { + suggestions.insert( + 0, + format!( + "try 'kcl mod add {}' to download the missing package", + pkg_name + ), ); } - return Ok(None); - } - - // builtin pkgs - if self.is_builtin_pkg(pkgpath.as_str()) { - return Ok(None); + sess.1.write().add_suggestions(suggestions); + Ok(None) } + } +} - // find the package. - let pkg_info = match self.find_packages(pos.clone(), &pkgname, pkgroot, &pkgpath)? { - Some(info) => info, - None => return Ok(None), - }; - - // If there is a circular import, return the information of the found package. - if pkgs.contains_key(&pkg_info.pkg_path) { - return Ok(Some(pkg_info)); - } +/// Search [`pkgpath`] among all the paths in [`pkgroots`]. +/// +/// # Notes +/// +/// All paths in [`pkgpath`] must contain the kcl.mod file. +/// It returns the parent directory of kcl.mod if present, or none if not. +fn pkg_exists(pkgroots: &[String], pkgpath: &str) -> Option { + pkgroots + .into_iter() + .find(|root| pkg_exists_in_path(root, pkgpath)) + .cloned() +} - if !self.opts.load_packages { - return Ok(Some(pkg_info)); - } +/// Search for [`pkgpath`] under [`path`]. +/// It only returns [`true`] if [`path`]/[`pkgpath`] or [`path`]/[`pkgpath.k`] exists. +fn pkg_exists_in_path(path: &str, pkgpath: &str) -> bool { + let mut pathbuf = PathBuf::from(path); + pkgpath.split('.').for_each(|s| pathbuf.push(s)); + pathbuf.exists() || pathbuf.with_extension(KCL_FILE_EXTENSION).exists() +} - // Load packages - let mut pkg_files = Vec::new(); - let k_files = pkg_info.k_files.clone(); - for filename in k_files { - let mut m = if let Some(module_cache) = self.module_cache.as_ref() { - let module_cache_ref = module_cache.read().unwrap(); - if let Some(module) = module_cache_ref.ast_cache.get(&filename) { - module.clone() - } else { - let m = parse_file_with_session(self.sess.clone(), &filename, None)?; - drop(module_cache_ref); - let mut module_cache_ref = module_cache.write().unwrap(); - module_cache_ref - .ast_cache - .insert(filename.clone(), m.clone()); - m - } +/// Look for [`pkgpath`] in the current package's [`pkgroot`]. +/// If found, return to the [`PkgInfo`], else return [`None`] +/// +/// # Error +/// +/// [`is_internal_pkg`] will return an error if the package's source files cannot be found. +fn is_internal_pkg(pkg_name: &str, pkg_root: &str, pkg_path: &str) -> Result> { + match pkg_exists(&[pkg_root.to_string()], pkg_path) { + Some(internal_pkg_root) => { + let fullpath = if pkg_name == kclvm_ast::MAIN_PKG { + pkg_path.to_string() } else { - parse_file_with_session(self.sess.clone(), &filename, None)? + format!("{}.{}", pkg_name, pkg_path) }; - - m.pkg = pkg_info.pkg_path.clone(); - m.name = "".to_string(); - fix_rel_import_path(&pkg_info.pkg_root, &mut m); - - pkg_files.push(m); + let k_files = get_pkg_kfile_list(pkg_root, pkg_path)?; + Ok(Some(PkgInfo::new( + pkg_name.to_string(), + internal_pkg_root, + fullpath, + k_files, + ))) } + None => Ok(None), + } +} - // Insert an empty vec to determine whether there is a circular import. - pkgs.insert(pkg_info.pkg_path.clone(), vec![]); - - self.load_import_package( - &pkg_info.pkg_root.to_string(), - pkg_info.pkg_name.to_string(), - &mut pkg_files, - pkgs, - )?; +fn get_pkg_kfile_list(pkgroot: &str, pkgpath: &str) -> Result> { + // plugin pkgs + if is_plugin_pkg(pkgpath) { + return Ok(Vec::new()); + } - // Insert the complete ast to replace the empty list. - pkgs.insert(pkg_info.pkg_path.clone(), pkg_files); + // builtin pkgs + if is_builtin_pkg(pkgpath) { + return Ok(Vec::new()); + } - Ok(Some(pkg_info)) + if pkgroot.is_empty() { + return Err(anyhow::anyhow!("pkgroot not found")); } - fn get_pkg_kfile_list(&self, pkgroot: &str, pkgpath: &str) -> Result> { - // plugin pkgs - if self.is_plugin_pkg(pkgpath) { - return Ok(Vec::new()); - } + let mut pathbuf = std::path::PathBuf::new(); + pathbuf.push(pkgroot); - // builtin pkgs - if self.is_builtin_pkg(pkgpath) { - return Ok(Vec::new()); - } + for s in pkgpath.split('.') { + pathbuf.push(s); + } - if pkgroot.is_empty() { - return Err(anyhow::anyhow!("pkgroot not found")); - } + let abspath = match pathbuf.canonicalize() { + Ok(p) => p.to_str().unwrap().to_string(), + Err(_) => pathbuf.as_path().to_str().unwrap().to_string(), + }; + if std::path::Path::new(abspath.as_str()).exists() { + return get_dir_files(abspath.as_str()); + } - let mut pathbuf = std::path::PathBuf::new(); - pathbuf.push(pkgroot); + let as_k_path = abspath + KCL_FILE_SUFFIX; + if std::path::Path::new((as_k_path).as_str()).exists() { + return Ok(vec![as_k_path]); + } - for s in pkgpath.split('.') { - pathbuf.push(s); - } + Ok(Vec::new()) +} - let abspath: String = pathbuf.as_path().to_str().unwrap().to_string(); +/// Get file list in the directory. +fn get_dir_files(dir: &str) -> Result> { + if !std::path::Path::new(dir).exists() { + return Ok(Vec::new()); + } - if std::path::Path::new(abspath.as_str()).exists() { - return self.get_dir_files(abspath.as_str()); + let mut list = Vec::new(); + for path in std::fs::read_dir(dir).unwrap() { + let path = path.unwrap(); + if !path + .file_name() + .to_str() + .unwrap() + .ends_with(KCL_FILE_SUFFIX) + { + continue; } - - let as_k_path = abspath + KCL_FILE_SUFFIX; - if std::path::Path::new((as_k_path).as_str()).exists() { - return Ok(vec![as_k_path]); + if path.file_name().to_str().unwrap().ends_with("_test.k") { + continue; + } + if path.file_name().to_str().unwrap().starts_with('_') { + continue; } - Ok(Vec::new()) + let s = format!("{}", path.path().display()); + list.push(s); } - /// Get file list in the directory. - fn get_dir_files(&self, dir: &str) -> Result> { - if !std::path::Path::new(dir).exists() { - return Ok(Vec::new()); - } - - let mut list = Vec::new(); - - for path in std::fs::read_dir(dir).unwrap() { - let path = path.unwrap(); - if !path - .file_name() - .to_str() - .unwrap() - .ends_with(KCL_FILE_SUFFIX) - { - continue; - } - if path.file_name().to_str().unwrap().ends_with("_test.k") { - continue; - } - if path.file_name().to_str().unwrap().starts_with('_') { - continue; - } + list.sort(); + Ok(list) +} - let s = format!("{}", path.path().display()); - list.push(s); +/// Look for [`pkgpath`] in the external package's home. +/// If found, return to the [`PkgInfo`], else return [`None`] +/// +/// # Error +/// +/// - [`is_external_pkg`] will return an error if the package's source files cannot be found. +/// - The name of the external package could not be resolved from [`pkg_path`]. +fn is_external_pkg(pkg_path: &str, opts: LoadProgramOptions) -> Result> { + let pkg_name = parse_external_pkg_name(pkg_path)?; + let external_pkg_root = if let Some(root) = opts.package_maps.get(&pkg_name) { + PathBuf::from(root).join(KCL_MOD_FILE) + } else { + match pkg_exists(&opts.vendor_dirs, pkg_path) { + Some(path) => PathBuf::from(path).join(&pkg_name).join(KCL_MOD_FILE), + None => return Ok(None), } + }; - list.sort(); - Ok(list) + if external_pkg_root.exists() { + return Ok(Some(match external_pkg_root.parent() { + Some(root) => { + let abs_root: String = match root.canonicalize() { + Ok(p) => p.to_str().unwrap().to_string(), + Err(_) => root.display().to_string(), + }; + let k_files = get_pkg_kfile_list(&abs_root, &rm_external_pkg_name(pkg_path)?)?; + PkgInfo::new( + pkg_name.to_string(), + abs_root, + pkg_path.to_string(), + k_files, + ) + } + None => return Ok(None), + })); + } else { + Ok(None) } +} - fn is_builtin_pkg(&self, pkgpath: &str) -> bool { - let system_modules = kclvm_sema::builtin::system_module::STANDARD_SYSTEM_MODULES; - system_modules.contains(&pkgpath) - } +pub type ASTCache = Arc>>>; +pub type FileGraphCache = Arc>; - fn is_plugin_pkg(&self, pkgpath: &str) -> bool { - pkgpath.starts_with(PLUGIN_MODULE_PREFIX) - } +pub fn parse_kcl_file( + sess: ParseSessionRef, + file: PkgFile, + src: Option, + asts: ASTCache, + pkgs: &mut HashMap>, + pkgmap: &mut PkgMap, + file_graph: FileGraphCache, + opts: &LoadProgramOptions, +) -> Result> { + let m = Arc::new(parse_file_with_session( + sess.clone(), + file.path.to_str().unwrap(), + src, + )?); + asts.write().unwrap().insert(file.canonicalize(), m.clone()); + let deps = get_deps(&file, m.as_ref(), pkgs, pkgmap, opts, sess)?; + file_graph.write().unwrap().update_file(&file, &deps); + Ok(deps) +} - /// Look for [`pkgpath`] in the current package's [`pkgroot`]. - /// If found, return to the [`PkgInfo`], else return [`None`] - /// - /// # Error - /// - /// [`is_internal_pkg`] will return an error if the package's source files cannot be found. - fn is_internal_pkg( - &self, - pkg_name: &str, - pkg_root: &str, - pkg_path: &str, - ) -> Result> { - match self.pkg_exists(&[pkg_root.to_string()], pkg_path) { - Some(internal_pkg_root) => { - let full_pkg_path = if pkg_name == kclvm_ast::MAIN_PKG { - pkg_path.to_string() - } else { - format!("{}.{}", pkg_name, pkg_path) - }; - let k_files = self.get_pkg_kfile_list(pkg_root, pkg_path)?; - Ok(Some(PkgInfo::new( - pkg_name.to_string(), - internal_pkg_root, - full_pkg_path, - k_files, - ))) +pub fn get_deps( + file: &PkgFile, + m: &Module, + modules: &mut HashMap>, + pkgmap: &mut PkgMap, + opts: &LoadProgramOptions, + sess: ParseSessionRef, +) -> Result> { + let mut deps: Vec = vec![]; + for stmt in &m.body { + let pos = stmt.pos().clone(); + let pkg = pkgmap.get(file).expect("file not in pkgmap").clone(); + if let ast::Stmt::Import(import_spec) = &stmt.node { + let fix_path = kclvm_config::vfs::fix_import_path( + &pkg.pkg_root, + &m.filename, + import_spec.path.node.as_str(), + ); + let pkg_info = find_packages( + pos.into(), + &pkg.pkg_name, + &pkg.pkg_root, + &fix_path, + opts.clone(), + sess.clone(), + )?; + if let Some(pkg_info) = &pkg_info { + // If k_files is empty, the pkg information will not be found in the file graph. + // Record the empty pkg to prevent loss. After the parse file is completed, fill in the modules + if pkg_info.k_files.is_empty() { + modules.insert(pkg_info.pkg_path.clone(), vec![]); + } + // Add file dependencies. + let mut paths: Vec = pkg_info + .k_files + .iter() + .map(|p| { + let file = PkgFile { + path: p.into(), + pkg_path: pkg_info.pkg_path.clone(), + }; + pkgmap.insert( + file.clone(), + file_graph::Pkg { + pkg_name: pkg_info.pkg_name.clone(), + pkg_root: pkg_info.pkg_root.clone().into(), + }, + ); + file + }) + .collect(); + deps.append(&mut paths); } - None => Ok(None), } } + Ok(deps) +} - /// Look for [`pkgpath`] in the external package's home. - /// If found, return to the [`PkgInfo`], else return [`None`] - /// - /// # Error - /// - /// - [`is_external_pkg`] will return an error if the package's source files cannot be found. - /// - The name of the external package could not be resolved from [`pkg_path`]. - fn is_external_pkg(&self, pkg_path: &str) -> Result> { - let pkg_name = parse_external_pkg_name(pkg_path)?; - let external_pkg_root = if let Some(root) = self.opts.package_maps.get(&pkg_name) { - PathBuf::from(root).join(KCL_MOD_FILE) - } else { - match self.pkg_exists(&self.opts.vendor_dirs, pkg_path) { - Some(path) => PathBuf::from(path).join(&pkg_name).join(KCL_MOD_FILE), - None => return Ok(None), - } +pub fn parse_kcl_pkg( + sess: ParseSessionRef, + files: Vec<(PkgFile, Option)>, + asts: ASTCache, + pkgs: &mut HashMap>, + pkgmap: &mut PkgMap, + file_graph: FileGraphCache, + opts: &LoadProgramOptions, +) -> Result> { + let mut dependent = vec![]; + for (file, src) in files { + let deps = parse_kcl_file( + sess.clone(), + file.clone(), + src, + asts.clone(), + pkgs, + pkgmap, + file_graph.clone(), + opts, + )?; + dependent.extend(deps); + } + Ok(dependent) +} + +pub fn parse_kcl_entry( + sess: ParseSessionRef, + entry: &entry::Entry, + asts: ASTCache, + pkgs: &mut HashMap>, + pkgmap: &mut PkgMap, + file_graph: FileGraphCache, + opts: &LoadProgramOptions, +) -> Result<()> { + let k_files = entry.get_k_files(); + let maybe_k_codes = entry.get_k_codes(); + let mut files = vec![]; + for (i, f) in k_files.iter().enumerate() { + let file = PkgFile { + path: f.into(), + pkg_path: MAIN_PKG.to_string(), }; + files.push((file.clone(), maybe_k_codes.get(i).unwrap().clone())); + pkgmap.insert( + file, + Pkg { + pkg_name: entry.name().clone(), + pkg_root: entry.path().into(), + }, + ); + } + let dependent_paths = parse_kcl_pkg( + sess.clone(), + files, + asts.clone(), + pkgs, + pkgmap, + file_graph.clone(), + opts, + ) + .unwrap(); + let mut unparsed_file: VecDeque = dependent_paths.into(); + + while let Some(file) = unparsed_file.pop_front() { + if let Some(m) = asts.read().unwrap().get(&file.canonicalize()) { + let deps = get_deps(&file, m.as_ref(), pkgs, pkgmap, opts, sess.clone())?; + let mut file_graph = file_graph.write().unwrap(); + file_graph.update_file(&file, &deps); + + if file_graph.toposort().is_ok() { + unparsed_file.extend(deps); + } - if external_pkg_root.exists() { - return Ok(Some(match external_pkg_root.parent() { - Some(root) => { - let k_files = self.get_pkg_kfile_list( - &root.display().to_string(), - &rm_external_pkg_name(pkg_path)?, - )?; - PkgInfo::new( - pkg_name.to_string(), - root.display().to_string(), - pkg_path.to_string(), - k_files, - ) - } - None => return Ok(None), - })); - } else { - Ok(None) + continue; } + let deps = parse_kcl_file( + sess.clone(), + file, + None, + asts.clone(), + pkgs, + pkgmap, + file_graph.clone(), + &opts, + ) + .unwrap(); + + unparsed_file.extend(deps); } + Ok(()) +} - /// Search [`pkgpath`] among all the paths in [`pkgroots`]. - /// - /// # Notes - /// - /// It returns the parent directory of kcl.mod if present, or none if not. - fn pkg_exists(&self, pkgroots: &[String], pkgpath: &str) -> Option { - pkgroots - .into_iter() - .find(|root| self.pkg_exists_in_path(root, pkgpath)) - .cloned() +pub fn parse_kcl_program( + sess: ParseSessionRef, + paths: Vec, + asts: ASTCache, + file_graph: FileGraphCache, + opts: &LoadProgramOptions, +) -> Result { + let compile_entries = get_compile_entries_from_paths(&paths, &opts)?; + let workdir = compile_entries.get_root_path().to_string(); + let mut pkgs: HashMap> = HashMap::new(); + let mut pkgmap = PkgMap::new(); + for entry in compile_entries.iter() { + parse_kcl_entry( + sess.clone(), + entry, + asts.clone(), + &mut pkgs, + &mut pkgmap, + file_graph.clone(), + &opts, + )?; } - /// Search for [`pkgpath`] under [`path`]. - /// It only returns [`true`] if [`path`]/[`pkgpath`] or [`path`]/[`pkgpath.k`] exists. - fn pkg_exists_in_path(&self, path: &str, pkgpath: &str) -> bool { - let mut pathbuf = PathBuf::from(path); - pkgpath.split('.').for_each(|s| pathbuf.push(s)); - pathbuf.exists() || pathbuf.with_extension(KCL_FILE_EXTENSION).exists() + // Return the files in the order they should be compiled + let file_graph = file_graph.read().unwrap(); + let files = match file_graph.toposort() { + Ok(files) => files, + Err(_) => file_graph.paths(), + }; + + let file_path_graph = file_graph.file_path_graph().0; + if let Err(cycle) = toposort(&file_path_graph) { + let formatted_cycle = cycle + .iter() + .map(|file| format!("- {}\n", file.to_string_lossy())) + .collect::(); + + sess.1.write().add_error( + ErrorKind::RecursiveLoad, + &[Message { + range: (Position::dummy_pos(), Position::dummy_pos()), + style: Style::Line, + message: format!( + "Could not compiles due to cyclic import statements\n{}", + formatted_cycle.trim_end() + ), + note: None, + suggested_replacement: None, + }], + ); } -} -fn fix_rel_import_path(pkgroot: &str, m: &mut ast::Module) { - for stmt in &mut m.body { - if let ast::Stmt::Import(ref mut import_spec) = &mut stmt.node { - import_spec.path.node = kclvm_config::vfs::fix_import_path( - pkgroot, - &m.filename, - import_spec.path.node.as_str(), - ); + let asts = asts.read().unwrap(); + for file in files.iter() { + let mut m = asts.get(&file.canonicalize()).unwrap().as_ref().clone(); + let pkg = pkgmap.get(file).expect("file not in pkgmap"); + match pkgs.get_mut(&file.pkg_path) { + Some(modules) => { + fix_rel_import_path_with_file( + &pkg.pkg_root, + &mut m, + file, + &pkgmap, + opts.clone(), + sess.clone(), + ); + modules.push(m); + } + None => { + fix_rel_import_path_with_file( + &pkg.pkg_root, + &mut m, + file, + &pkgmap, + opts.clone(), + sess.clone(), + ); + pkgs.insert(file.pkg_path.clone(), vec![m]); + } } } + + let program = ast::Program { + root: workdir, + pkgs, + }; + + Ok(LoadProgramResult { + program, + errors: sess.1.read().diagnostics.clone(), + paths: files.iter().map(|file| file.path.clone()).collect(), + }) } diff --git a/kclvm/parser/src/parser/module.rs b/kclvm/parser/src/parser/module.rs index 69194457b..b674146dc 100644 --- a/kclvm/parser/src/parser/module.rs +++ b/kclvm/parser/src/parser/module.rs @@ -12,7 +12,6 @@ impl<'a> Parser<'a> { let body = self.parse_body(); Module { filename: "".to_string(), - pkg: "".to_string(), name: "".to_string(), doc, comments: self.comments.clone(), diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index b797ed0e1..7fbeecf0d 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -1,6 +1,7 @@ use std::{ env, panic::{catch_unwind, set_hook}, + path::Path, }; use compiler_base_span::{FilePathMapping, SourceMap}; diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap index c2e9055ec..d252815f0 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_ast_json(\"hello.k\", r####\"a=123\"#### --- { "filename": "hello.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap index c5263f21d..e5c26ec4c 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\n# co --- { "filename": "hello.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap index 319091997..0d07b3188 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\na = --- { "filename": "hello.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap index d159e1068..d5790596f 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\ndata --- { "filename": "hello.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap index fe180f810..ef774f597 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\nsche --- { "filename": "hello.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_0.snap index 0e563b4aa..37072379a 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"assert\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -34,4 +33,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_1.snap index b8f640899..86e81a427 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"assert a.\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -55,4 +54,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_2.snap index 66f232e90..a02028ac5 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"assert True,,, 'msg'\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -74,4 +73,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_3.snap index bc04b5ace..8bddc2dad 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assert_stmt_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"assert True if data else 'm --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -123,4 +122,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_0.snap index 8f6eff69f..636cbd82d 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a = \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_1.snap index 017872b98..0352b7273 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\" = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -39,4 +38,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_10.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_10.snap index b45793928..172909869 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_10.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_10.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a[0] -= 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_11.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_11.snap index 20489eadc..6f44ed266 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_11.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_11.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a[0].b -= 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_12.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_12.snap index 39573c11a..5bca01236 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_12.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_12.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a.b[0] = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_13.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_13.snap index af11fd921..abdc6ad18 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_13.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_13.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a().b = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_14.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_14.snap index 9a756dd9c..b4db461f5 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_14.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_14.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a.b[1:2] = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_15.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_15.snap index 9572b43f4..f8c6f208b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_15.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_15.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a.b[1::2].c = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_16.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_16.snap index 5986cb533..657112235 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_16.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_16.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a.b[c.d].e = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_17.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_17.snap index 0f4c80099..b6c7ac379 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_17.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_17.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a.b[1 + 1].e = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_18.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_18.snap index c816ff096..1e3a7b1bf 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_18.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_18.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a.b[f()].e = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_2.snap index c0d2f3cfa..8575408c0 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a: int =\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_3.snap index 666b30721..5749d7eb8 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a: a = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_4.snap index 9f974cf44..6f5d04184 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_5.snap index 34efcb2b2..e44f3b742 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a = b = \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_6.snap index b7f3b05bf..2dbe24652 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a() = b. = c\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_7.snap index 8bf85e696..11e6dd146 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_7.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_7.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a: () = 0\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_8.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_8.snap index 8bf85e696..11e6dd146 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_8.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_8.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a: () = 0\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_9.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_9.snap index 9d03b317d..6d69ac49f 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_9.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__assign_stmt_recovery_9.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a ++= 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [], diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_0.snap index 057379397..ae26b85ce 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:(\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_1.snap index c3c8d8e96..2de1f7622 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:(i\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_10.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_10.snap index 9feb547ef..412a5b6be 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_10.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_10.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_11.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_11.snap index 6df6a93be..9f5a8315b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_11.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_11.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({i\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_12.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_12.snap index d16a4a19d..c8da07b6f 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_12.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_12.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({i:\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_13.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_13.snap index eaa9a0fff..3cab185bf 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_13.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_13.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({i:i\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_14.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_14.snap index 4c9c34dc5..7cc922b9a 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_14.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_14.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({i:int\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_15.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_15.snap index 4404f5c0c..9e4f44b75 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_15.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_15.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({i:int]\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_16.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_16.snap index 6a4d6fe27..4a578cc76 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_16.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_16.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({str:int]\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_17.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_17.snap index 4416f2323..95c9b8c28 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_17.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_17.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({str:int}\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_18.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_18.snap index 3a844ef56..cc098244d 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_18.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_18.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({str:int} ->\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_19.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_19.snap index 8ec647cfe..845452194 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_19.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_19.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({str:int}) -> i\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_2.snap index d3e0422bf..de6636e20 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:(int\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_20.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_20.snap index 6d1b1e3fb..0392dd933 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_20.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_20.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:(str|int) -> i\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_21.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_21.snap index add4ff92d..d4438d557 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_21.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_21.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:(str|int, int) -> i\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_22.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_22.snap index c8530dec9..929ef283b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_22.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_22.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:(str|int, int|\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_23.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_23.snap index bb3ecd599..415b1f77a 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_23.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_23.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:(str|int, int|) ->\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_3.snap index 2fb839279..f5d1a3154 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:i)\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_4.snap index 1ce3daeef..b355e24c7 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:([i\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_5.snap index ab1f9884f..6cff27806 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:([i:\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_6.snap index 792e25934..41fc9dacf 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:([i]\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_7.snap index 3135b60f2..a7f525a41 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_7.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_7.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:([int]\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_8.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_8.snap index a31c8371d..6890202d0 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_8.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_8.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:([int\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_9.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_9.snap index 0e19ecb2d..7721f4a90 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_9.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__fn_ty_annotation_recovery_9.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"a:({}\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_0.snap index cd4937e56..f27ed9032 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if True a = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_1.snap index 42e15e952..6499f5844 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if True: a = 1 else if b = --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_2.snap index e56ef7c74..2d4915cbd 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if : a = 1\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_3.snap index df366c9dd..65c74f220 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if True: a = 1 else b = 2\" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_4.snap index f9533f5b9..3fb4319fb 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if True: else: b = 2\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_5.snap index 3e5f79f13..52e633ef5 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -58,4 +57,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_6.snap index fa9ef7dd6..4c95e28f1 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if else\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -71,4 +70,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_7.snap index c2d9dc939..fd0f13a99 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_7.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_7.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if True:\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -36,4 +35,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_8.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_8.snap index a870f260e..f79856e34 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_8.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_8.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if True: a = 1\nelse if Fal --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_9.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_9.snap index f9b49cdb6..78520747e 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_9.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__if_stmt_recovery_9.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"if True: a = 1\nelse False: --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_recovery_0.snap index 2e07fd5ae..4828cba07 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import json as j.a\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -34,4 +33,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_0.snap index d8bee29dd..ec8b4a911 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -34,4 +33,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_1.snap index 0fcc1117b..b34e3d839 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import 'pkg_path'\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -61,4 +60,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_2.snap index 731f2e915..8c046c485 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import pkg_path.\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -34,4 +33,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_3.snap index ebbc792ed..ae19e55f2 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import pkg_path[0]\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -76,4 +75,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_4.snap index 657f42f79..aa4a4c832 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import .pkg_path.\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -34,4 +33,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_5.snap index 714829607..67fb6a4a6 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import pkg_path as \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -43,4 +42,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_6.snap index dd46cb3d0..2ba84a1ef 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__import_stmt_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"import pkg_path as 'data'\" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -70,4 +69,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_0.snap index 3fc5d9f81..33f7e159d 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"rule\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -36,4 +35,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_1.snap index 49c016809..db80f1617 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"rule A\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -36,4 +35,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_2.snap index ab4335251..e8bd5a454 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_2.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 292 expression: "crate::tests::parsing_module_string(r#\"rule A[\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -50,4 +48,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_3.snap index bedad302e..ec013bc77 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"rule A::\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -58,4 +57,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_4.snap index 7ff5d7da5..5b752023b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"rule A:B\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -58,4 +57,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_5.snap index d5d182acf..e1f56f09f 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"rule A(:\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -49,4 +48,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_6.snap index d23d36f27..bdae5ab7e 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nrule A:\n True \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -60,4 +59,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_7.snap index f2d8bb320..124c69b30 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_7.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__rule_stmt_recovery_7.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nrule A:\n @\n\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -79,4 +78,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_0.snap index f94cff29f..fa68ada64 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -41,4 +40,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_1.snap index 13d501d58..d73e8c666 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -41,4 +40,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_10.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_10.snap index 604699848..174c400fe 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_10.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_10.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\n[str:]: []\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_11.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_11.snap index 3508d6663..9ba9aa7f2 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_11.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_11.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\n[str]: str = \"# --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_12.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_12.snap index cbf860fab..b2032bbba 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_12.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_12.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\n[str]: = \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_13.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_13.snap index 2b5561ebc..c9d928b42 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_13.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_13.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\n[str]: ''= \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_14.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_14.snap index 3c5808425..2a09111e7 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_14.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_14.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\na??: int \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -113,4 +112,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_15.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_15.snap index 05b00dd33..df5ce6ce9 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_15.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_15.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\na!: int \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -148,4 +147,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_16.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_16.snap index 989c4159f..360812cbc 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_16.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_16.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\na!!: int \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -183,4 +182,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_17.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_17.snap index 14dbf639f..140373960 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_17.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_17.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\na: \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_19.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_19.snap index a456bde77..e91f2293c 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_19.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_19.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 236 expression: "crate::tests::parsing_module_string(r#\"@deprecated\nschema A:\n a: \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -110,4 +108,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_2.snap index 1869dbab7..8a301c7e7 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_2.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 209 expression: "crate::tests::parsing_module_string(r#\"schema A[\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -55,4 +53,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_20.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_20.snap index 812f92d46..4ad3ef338 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_20.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_20.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"@deprecated(\nschema A:\n --- Module { filename: "", - pkg: "", doc: None, name: "", body: [], diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_21.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_21.snap index 812f92d46..4ad3ef338 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_21.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_21.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"@deprecated(\nschema A:\n --- Module { filename: "", - pkg: "", doc: None, name: "", body: [], diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_22.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_22.snap index cdd1cdef6..11f7717ea 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_22.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_22.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 245 expression: "crate::tests::parsing_module_string(r#\"@deprecated(a\nschema A:\n a: \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -134,4 +132,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_23.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_23.snap index 8104ea428..479c866d1 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_23.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_23.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"@deprecated(a,\nschema A:\n --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_24.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_24.snap index a7d461870..73add5bd0 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_24.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_24.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"@deprecated((),\nschema A:\ --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_25.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_25.snap index ea0098709..b37d39133 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_25.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_25.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n check: \"# --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -63,4 +62,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_26.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_26.snap index 4668c6775..6598b956e 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_26.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_26.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n check: \n --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -84,4 +83,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_27.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_27.snap index 26a7501ef..2580c9d20 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_27.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_27.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n [.str]: st --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -145,4 +144,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_28.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_28.snap index a03501873..cd60abd09 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_28.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_28.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n [....str]: --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -168,4 +167,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_29.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_29.snap index af9dc19f1..8dad045ea 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_29.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_29.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n @\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -74,4 +73,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_3.snap index 58ca309cd..8b1ab6d5b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A::\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -41,4 +40,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_30.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_30.snap index f16793e95..0caaec186 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_30.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_30.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n .\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -99,4 +98,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_31.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_31.snap index c6be13f8f..f5b531ce4 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_31.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_31.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 273 expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n [str]: str\n [str]: int\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -88,4 +86,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_32.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_32.snap index e8eaa3848..3f9a82049 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_32.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_32.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 277 expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n \"attr\": str\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -77,4 +75,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_33.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_33.snap index 30f0e4146..3c95a1be0 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_33.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_33.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 280 expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n \"\"\"Schema Doc\"\"\"\n \"attr\": str\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -86,4 +84,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_34.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_34.snap index 6d706d055..08ce1c0c0 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_34.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_34.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n \"attr: st --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_35.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_35.snap index 5d5215a7b..0ee6faacf 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_35.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_35.snap @@ -1,11 +1,9 @@ --- source: parser/src/tests/error_recovery.rs -assertion_line: 287 expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n \"attr\":\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -75,4 +73,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_36.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_36.snap index 80f8f9e59..a4a0b1a5c 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_36.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_36.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n mixin: \"# --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_37.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_37.snap index c619018df..ff0b8f8b9 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_37.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_37.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n mixin: [\" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_38.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_38.snap index 7b141fc2d..ceb0dd9ac 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_38.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_38.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n mixin: []\ --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_39.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_39.snap index 6424ce536..b40575fe9 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_39.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_39.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n mixin []\" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_4.snap index 968e818fe..43af0620e 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:B\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -77,4 +76,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_40.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_40.snap index fbec01127..30a1ceb09 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_40.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_40.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"\nschema A:\n mixin [\"# --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_5.snap index 16fc98cdc..75d248d6f 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A(:\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -63,4 +62,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_6.snap index fc1dcfd5a..52e2b2c93 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A():\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -63,4 +62,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_7.snap index 657cae7ba..da44cd188 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_7.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_7.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\na:: int\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_8.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_8.snap index 413bea2c2..0d8cd0f2c 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_8.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_8.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\na: int =\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_9.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_9.snap index b54777efe..079131f94 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_9.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__schema_stmt_recovery_9.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"schema A:\n[]: []\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_0.snap index 7a0ed7d64..7dad188d8 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"type\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -50,4 +49,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_1.snap index 01dc17c63..2e303103c 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"type 'pkg_path'\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -50,4 +49,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_2.snap index 746fbccdb..1ffa5a74e 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"type pkg_path.\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -67,4 +66,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_3.snap index f30ae2784..fb52196f5 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"type pkg_path[0]\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -50,4 +49,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_4.snap index 2ed5a48c0..54cd493b8 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"type .pkg_path.\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -50,4 +49,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_5.snap index 5441492f3..5dacb7c5b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"type pkg_path = \"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -59,4 +58,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_6.snap index 0367449a7..0290d6edc 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__type_alias_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"type pkg_path = 'data'\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ @@ -63,4 +62,3 @@ Module { ], comments: [], } - diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_0.snap index 50c8d9816..fbc7cac5b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"s: Server {\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_1.snap index 3c17ecec0..cc8874637 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"s: Server {}\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_2.snap index 0269244e3..a3065ae3c 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"s: Server (\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_3.snap index 71d6446f2..3665fed5c 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"s: Server ()\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_4.snap index 266e7ac0a..67248d0c8 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"s: Server () {\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_5.snap index 6771f8d6a..da43aefaf 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_5.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_5.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"s: Server ( {\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_6.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_6.snap index a9f975e64..fb102619e 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_6.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__unification_stmt_recovery_6.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_module_string(r#\"s: Server ( }\"#)" --- Module { filename: "", - pkg: "", doc: None, name: "", body: [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap index 7b8712908..ff905c946 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/assert-01.k\")" --- { "filename": "assert-01.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap index f5dca473f..6debaf880 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/assert-02.k\")" --- { "filename": "assert-02.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap index 945e0e24c..68f052ad6 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/assert-03.k\")" --- { "filename": "assert-03.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap index a79d07a3c..f5a6ffd44 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/assert-if-0.k\")" --- { "filename": "assert-if-0.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap index eeb5a50bf..3dfc8f62e 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/assert-if-1.k\")" --- { "filename": "assert-if-1.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap index b8a3bd858..0af75c0d2 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/assert-if-2.k\")" --- { "filename": "assert-if-2.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap index d59a6e793..c7e6bacea 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/assign-01.k\")" --- { "filename": "assign-01.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap index 43e25d6e6..35164fd0b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/config_expr-01.k\")" --- { "filename": "config_expr-01.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap index ddbe3a471..864a018bb 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/config_expr-02.k\")" --- { "filename": "config_expr-02.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap index e322721d3..ac5ef46ec 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/config_expr-03.k\")" --- { "filename": "config_expr-03.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap index 3f774c6f9..13e3e0665 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/config_expr-04.k\")" --- { "filename": "config_expr-04.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap index 4c1b0cbcf..15c0b00f1 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/hello_win.k\")" --- { "filename": "hello_win.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_1.snap index 022175f39..050b120d4 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/if-01.k\")" --- { "filename": "if-01.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_2.snap index 8bd23ab8b..a8f88c4c3 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_2.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_2.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/if-02.k\")" --- { "filename": "if-02.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_3.snap index 20cd7d244..a99e68b5a 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_3.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_3.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/if-03.k\")" --- { "filename": "if-03.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__import_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__import_1.snap index 887c422e5..a7f021521 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__import_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__import_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/import-01.k\")" --- { "filename": "import-01.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__type_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__type_1.snap index 91ac6fa3a..94d62aa6b 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__type_1.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__type_1.snap @@ -4,7 +4,6 @@ expression: "crate::tests::parsing_file_string(\"testdata/type-01.k\")" --- { "filename": "type-01.k", - "pkg": "__main__", "doc": null, "name": "__main__", "body": [ diff --git a/kclvm/runner/src/lib.rs b/kclvm/runner/src/lib.rs index 4d361976c..7d918872d 100644 --- a/kclvm/runner/src/lib.rs +++ b/kclvm/runner/src/lib.rs @@ -246,9 +246,7 @@ pub fn execute( /// For more information, see doc above method `execute`. /// /// **Note that it is not thread safe.** -pub fn execute_module(mut m: Module) -> Result { - m.pkg = MAIN_PKG.to_string(); - +pub fn execute_module(m: Module) -> Result { let mut pkgs = HashMap::new(); pkgs.insert(MAIN_PKG.to_string(), vec![m]); diff --git a/kclvm/runner/src/tests.rs b/kclvm/runner/src/tests.rs index e6f60c1e7..ea0ea72d3 100644 --- a/kclvm/runner/src/tests.rs +++ b/kclvm/runner/src/tests.rs @@ -177,8 +177,7 @@ fn parse_program(test_kcl_case_path: &str) -> Program { /// Default configuration: /// module.pkg = "__main__" /// Program.root = "__main__" -fn construct_program(mut module: Module) -> Program { - module.pkg = MAIN_PKG_NAME.to_string(); +fn construct_program(module: Module) -> Program { let mut pkgs_ast = HashMap::new(); pkgs_ast.insert(MAIN_PKG_NAME.to_string(), vec![module]); Program { diff --git a/kclvm/sema/src/pre_process/tests.rs b/kclvm/sema/src/pre_process/tests.rs index 6400436c8..3b187132b 100644 --- a/kclvm/sema/src/pre_process/tests.rs +++ b/kclvm/sema/src/pre_process/tests.rs @@ -171,7 +171,7 @@ fn test_config_merge() { .program; merge_program(&mut program); let modules = program.pkgs.get_mut(kclvm_ast::MAIN_PKG).unwrap(); - assert_eq!(modules.len(), 4); + assert_eq!(modules.len(), 3); // Test the module merge result let module = modules.last().unwrap(); if let ast::Stmt::Unification(unification) = &module.body[0].node { diff --git a/kclvm/sema/src/resolver/import.rs b/kclvm/sema/src/resolver/import.rs index 6fcb5aaa0..6fab52bb7 100644 --- a/kclvm/sema/src/resolver/import.rs +++ b/kclvm/sema/src/resolver/import.rs @@ -122,7 +122,6 @@ impl<'ctx> Resolver<'ctx> { let mut import_table: IndexMap = IndexMap::default(); for module in modules { self.ctx.filename = module.filename.clone(); - self.ctx.pkgpath = module.pkg.clone(); for stmt in &module.body { if let ast::Stmt::Import(import_stmt) = &stmt.node { // 'import sub as s' and 'import sub.sub as s' will raise this error. diff --git a/kclvm/sema/src/resolver/mod.rs b/kclvm/sema/src/resolver/mod.rs index 4544c6cb6..3cff2a40a 100644 --- a/kclvm/sema/src/resolver/mod.rs +++ b/kclvm/sema/src/resolver/mod.rs @@ -195,6 +195,7 @@ pub fn resolve_program_with_opts( } } let scope = resolver.check_and_lint(kclvm_ast::MAIN_PKG); + if let Some(cached_scope) = cached_scope.as_ref() { if let Some(mut cached_scope) = cached_scope.try_write() { cached_scope.update(program); diff --git a/kclvm/sema/src/resolver/tests.rs b/kclvm/sema/src/resolver/tests.rs index 834b1fc4d..ba7c68a15 100644 --- a/kclvm/sema/src/resolver/tests.rs +++ b/kclvm/sema/src/resolver/tests.rs @@ -32,7 +32,6 @@ pub fn parse_program(filename: &str) -> Result { let mut module = parse_file_force_errors(abspath.to_str().unwrap(), None)?; module.filename = filename.to_string(); - module.pkg = kclvm_ast::MAIN_PKG.to_string(); module.name = kclvm_ast::MAIN_PKG.to_string(); prog.pkgs diff --git a/kclvm/sema/src/resolver/ty_alias.rs b/kclvm/sema/src/resolver/ty_alias.rs index 7139107f1..be2b47292 100644 --- a/kclvm/sema/src/resolver/ty_alias.rs +++ b/kclvm/sema/src/resolver/ty_alias.rs @@ -130,11 +130,12 @@ impl<'ctx> MutSelfMutWalker<'ctx> for TypeAliasTransformer { /// Replace type alias. fn fix_type_alias_identifier<'ctx>( + pkg: &String, module: &'ctx mut ast::Module, type_alias_mapping: IndexMap, ) { let mut type_alias_transformer = TypeAliasTransformer { - pkgpath: module.pkg.clone(), + pkgpath: pkg.clone(), type_alias_mapping, }; type_alias_transformer.walk_module(module); @@ -148,7 +149,7 @@ pub fn type_alias_pass( for (pkgpath, modules) in program.pkgs.iter_mut() { for module in modules.iter_mut() { if let Some(type_alias_mapping) = type_alias_mapping.get(pkgpath) { - fix_type_alias_identifier(module, type_alias_mapping.clone()); + fix_type_alias_identifier(pkgpath, module, type_alias_mapping.clone()); } } } diff --git a/kclvm/tools/src/LSP/src/compile.rs b/kclvm/tools/src/LSP/src/compile.rs index 65b7d9cdf..6c9c8f2b2 100644 --- a/kclvm/tools/src/LSP/src/compile.rs +++ b/kclvm/tools/src/LSP/src/compile.rs @@ -157,8 +157,5 @@ pub fn compile_with_params( .to_string(); // Lookup compile workspace from the cursor file. let (mut files, opts, _) = lookup_compile_workspace(&toolchain::default(), &file, true); - if !files.contains(&file) { - files.push(file); - } compile(params, &mut files, opts) } diff --git a/kclvm/tools/src/LSP/src/tests.rs b/kclvm/tools/src/LSP/src/tests.rs index 676b58df0..9b9a54b1d 100644 --- a/kclvm/tools/src/LSP/src/tests.rs +++ b/kclvm/tools/src/LSP/src/tests.rs @@ -1,7 +1,6 @@ use crossbeam_channel::after; use crossbeam_channel::select; use indexmap::IndexSet; -use kclvm_ast::MAIN_PKG; use kclvm_driver::lookup_compile_workspace; use kclvm_driver::toolchain; use kclvm_driver::toolchain::Metadata; @@ -91,7 +90,7 @@ use crate::util::to_json; macro_rules! wait_async_compile { () => { - thread::sleep(Duration::from_millis(50)); + thread::sleep(Duration::from_millis(100)); }; } @@ -2201,33 +2200,6 @@ fn rename_test() { assert_eq!(res.result.unwrap(), to_json(expect).unwrap()); } -#[test] -fn compile_unit_test() { - let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut test_file = path.clone(); - test_file.push("src/test_data/compile_unit/b.k"); - let p = test_file.canonicalize().unwrap(); - let file = p.to_str().unwrap().adjust_canonicalization(); - - let prog = compile_with_params(Params { - file: Some(file.to_string()), - module_cache: None, - scope_cache: None, - vfs: Some(KCLVfs::default()), - gs_cache: Some(KCLGlobalStateCache::default()), - }) - .1 - .unwrap() - .0; - // b.k is not contained in kcl.yaml but need to be contained in main pkg - assert!(prog - .pkgs - .get(MAIN_PKG) - .unwrap() - .iter() - .any(|m| m.filename == file)) -} - #[test] fn kcl_workspace_init_kclwork_test() { let tool: crate::state::KCLToolChain = Arc::new(RwLock::new(toolchain::default())); diff --git a/kclvm/utils/src/path.rs b/kclvm/utils/src/path.rs index 430b1d8c8..baa27ba78 100644 --- a/kclvm/utils/src/path.rs +++ b/kclvm/utils/src/path.rs @@ -61,9 +61,12 @@ where /// ``` fn adjust_canonicalization(&self) -> String { const VERBATIM_PREFIX: &str = r#"\\?\"#; + const ESCAPE_VERBATIM_PREFIX: &str = r#"\\\\?\\"#; let p = self.as_ref().display().to_string(); if p.starts_with(VERBATIM_PREFIX) { p[VERBATIM_PREFIX.len()..].to_string() + } else if p.starts_with(ESCAPE_VERBATIM_PREFIX) { + p[ESCAPE_VERBATIM_PREFIX.len()..].to_string() } else { p }