diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index d85b991a6..e96b9f52c 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -1687,6 +1687,7 @@ dependencies = [ "kclvm-span", "kclvm-utils", "num-bigint", + "petgraph", "regex", "rustc_lexer", "serde", @@ -1827,6 +1828,7 @@ dependencies = [ "criterion 0.3.6", "fancy-regex", "indexmap 1.9.3", + "insta", "json-spanned-value", "kclvm-ast", "kclvm-ast-pretty", @@ -1852,6 +1854,9 @@ dependencies = [ [[package]] name = "kclvm-utils" version = "0.7.2" +dependencies = [ + "anyhow", +] [[package]] name = "kclvm-version" diff --git a/kclvm/api/src/capi_test.rs b/kclvm/api/src/capi_test.rs index 7a3c31d23..cac81ade8 100644 --- a/kclvm/api/src/capi_test.rs +++ b/kclvm/api/src/capi_test.rs @@ -2,7 +2,6 @@ use crate::gpyrpc::*; use crate::service::capi::*; use once_cell::sync::Lazy; use prost::Message; -use ra_ap_vfs::Vfs; use serde::de::DeserializeOwned; use std::default::Default; use std::ffi::{CStr, CString}; @@ -144,16 +143,6 @@ fn test_c_api_call_exec_program_with_compile_only() { ); } -#[test] -fn test_c_api_call_exec_program_with_recursive() { - test_c_api::( - "KclvmService.ExecProgram", - "exec-program-with-recursive.json", - "exec-program-with-recursive.response.json", - |_| {}, - ); -} - #[test] fn test_c_api_validate_code() { test_c_api_without_wrapper::( diff --git a/kclvm/api/src/service/capi.rs b/kclvm/api/src/service/capi.rs index cab3d29f3..322b6989e 100644 --- a/kclvm/api/src/service/capi.rs +++ b/kclvm/api/src/service/capi.rs @@ -106,6 +106,8 @@ pub extern "C" fn kclvm_service_call( pub(crate) fn kclvm_get_service_fn_ptr_by_name(name: &str) -> u64 { match name { "KclvmService.Ping" => ping as *const () as u64, + "KclvmService.ParseFile" => parse_file as *const () as u64, + "KclvmService.ParseProgram" => parse_program as *const () as u64, "KclvmService.ExecProgram" => exec_program as *const () as u64, "KclvmService.OverrideFile" => override_file as *const () as u64, "KclvmService.GetSchemaType" => get_schema_type as *const () as u64, @@ -129,6 +131,46 @@ pub(crate) fn ping(serv: *mut kclvm_service, args: *const c_char) -> *const c_ch call!(serv, args, PingArgs, ping) } +/// parse_file provides users with the ability to parse kcl single file +/// +/// # Parameters +/// +/// `serv`: [*mut kclvm_service] +/// The pointer of &\[[KclvmServiceImpl]] +/// +/// +/// `args`: [*const c_char] +/// the items and compile parameters selected by the user in the KCL CLI +/// serialized as protobuf byte sequence +/// +/// # Returns +/// +/// result: [*const c_char] +/// Result of the call serialized as protobuf byte sequence +pub(crate) fn parse_file(serv: *mut kclvm_service, args: *const c_char) -> *const c_char { + call!(serv, args, ParseFileArgs, parse_file) +} + +/// parse_program provides users with the ability to parse kcl program +/// +/// # Parameters +/// +/// `serv`: [*mut kclvm_service] +/// The pointer of &\[[KclvmServiceImpl]] +/// +/// +/// `args`: [*const c_char] +/// the items and compile parameters selected by the user in the KCL CLI +/// serialized as protobuf byte sequence +/// +/// # Returns +/// +/// result: [*const c_char] +/// Result of the call serialized as protobuf byte sequence +pub(crate) fn parse_program(serv: *mut kclvm_service, args: *const c_char) -> *const c_char { + call!(serv, args, ParseProgramArgs, parse_program) +} + /// exec_program provides users with the ability to execute KCL code /// /// # Parameters diff --git a/kclvm/api/src/service/into.rs b/kclvm/api/src/service/into.rs index f38795a70..d4f263fe0 100644 --- a/kclvm/api/src/service/into.rs +++ b/kclvm/api/src/service/into.rs @@ -1,11 +1,16 @@ -use crate::gpyrpc::{CliConfig, KeyValuePair, LoadSettingsFilesResult}; +use crate::gpyrpc::{CliConfig, Error, KeyValuePair, LoadSettingsFilesResult, Message, Position}; use kclvm_config::settings::SettingsFile; +use kclvm_error::Diagnostic; pub(crate) trait IntoLoadSettingsFiles { /// Convert self into the LoadSettingsFiles structure. fn into_load_settings_files(self, files: &[String]) -> LoadSettingsFilesResult; } +pub(crate) trait IntoError { + fn into_error(self) -> Error; +} + impl IntoLoadSettingsFiles for SettingsFile { fn into_load_settings_files(self, files: &[String]) -> LoadSettingsFilesResult { LoadSettingsFilesResult { @@ -34,3 +39,29 @@ impl IntoLoadSettingsFiles for SettingsFile { } } } + +impl IntoError for Diagnostic { + fn into_error(self) -> Error { + Error { + level: self.level.to_string(), + code: format!( + "{:?}", + self.code.unwrap_or(kclvm_error::DiagnosticId::Error( + kclvm_error::ErrorKind::InvalidSyntax, + )) + ), + messages: self + .messages + .iter() + .map(|m| Message { + msg: m.message.clone(), + pos: Some(Position { + filename: m.range.0.filename.clone(), + line: m.range.0.line as i64, + column: m.range.0.column.unwrap_or_default() as i64, + }), + }) + .collect(), + } + } +} diff --git a/kclvm/api/src/service/jsonrpc.rs b/kclvm/api/src/service/jsonrpc.rs index 9d274d631..2dd5b1e7d 100644 --- a/kclvm/api/src/service/jsonrpc.rs +++ b/kclvm/api/src/service/jsonrpc.rs @@ -67,6 +67,22 @@ fn register_kclvm_service(io: &mut IoHandler) { }; futures::future::ready(catch!(kclvm_service_impl, args, ping)) }); + io.add_method("KclvmService.ParseFile", |params: Params| { + let kclvm_service_impl = KclvmServiceImpl::default(); + let args: ParseFileArgs = match params.parse() { + Ok(val) => val, + Err(err) => return futures::future::ready(Err(err)), + }; + futures::future::ready(catch!(kclvm_service_impl, args, parse_file)) + }); + io.add_method("KclvmService.ParseProgram", |params: Params| { + let kclvm_service_impl = KclvmServiceImpl::default(); + let args: ParseProgramArgs = match params.parse() { + Ok(val) => val, + Err(err) => return futures::future::ready(Err(err)), + }; + futures::future::ready(catch!(kclvm_service_impl, args, parse_program)) + }); io.add_method("KclvmService.ExecProgram", |params: Params| { let kclvm_service_impl = KclvmServiceImpl::default(); let args: ExecProgramArgs = match params.parse() { @@ -183,6 +199,8 @@ fn register_builtin_service(io: &mut IoHandler) { let result = ListMethodResult { method_name_list: vec![ "KclvmService.Ping".to_owned(), + "KclvmService.ParseFile".to_owned(), + "KclvmService.ParseProgram".to_owned(), "KclvmService.ExecProgram".to_owned(), "KclvmService.OverrideFile".to_owned(), "KclvmService.GetSchemaType".to_owned(), diff --git a/kclvm/api/src/service/service_impl.rs b/kclvm/api/src/service/service_impl.rs index 4ec63f73d..13872800e 100644 --- a/kclvm/api/src/service/service_impl.rs +++ b/kclvm/api/src/service/service_impl.rs @@ -10,6 +10,9 @@ use anyhow::anyhow; use kcl_language_server::rename; use kclvm_config::settings::build_settings_pathbuf; use kclvm_driver::canonicalize_input_files; +use kclvm_parser::load_program; +use kclvm_parser::parse_file; +use kclvm_parser::LoadProgramOptions; use kclvm_parser::ParseSession; use kclvm_query::get_schema_type; use kclvm_query::override_file; @@ -27,6 +30,7 @@ use kclvm_tools::vet::validator::LoaderKind; use kclvm_tools::vet::validator::ValidateOption; use tempfile::NamedTempFile; +use super::into::IntoError; use super::into::IntoLoadSettingsFiles; use super::ty::kcl_schema_ty_to_pb_ty; use super::util::transform_str_para; @@ -60,6 +64,88 @@ impl KclvmServiceImpl { }) } + /// Parse KCL program with entry files. + /// + /// # Examples + /// + /// ``` + /// use kclvm_api::service::service_impl::KclvmServiceImpl; + /// use kclvm_api::gpyrpc::*; + /// use std::path::Path; + /// // File case + /// let serv = KclvmServiceImpl::default(); + /// let args = &ParseProgramArgs { + /// paths: vec![Path::new(".").join("src").join("testdata").join("test.k").canonicalize().unwrap().display().to_string(),], + /// ..Default::default() + /// }; + /// let result = serv.parse_program(args).unwrap(); + /// assert_eq!(result.errors.len(), 0); + /// assert_eq!(result.paths.len(), 1); + /// ``` + pub fn parse_program(&self, args: &ParseProgramArgs) -> anyhow::Result { + let sess = Arc::new(ParseSession::default()); + let mut package_maps = HashMap::new(); + for p in &args.external_pkgs { + package_maps.insert(p.pkg_name.to_string(), p.pkg_path.to_string()); + } + let paths: Vec<&str> = args.paths.iter().map(|p| p.as_str()).collect(); + let result = load_program( + sess, + &paths, + Some(LoadProgramOptions { + k_code_list: args.sources.clone(), + package_maps, + ..Default::default() + }), + None, + )?; + let ast_json = serde_json::to_string(&result.program)?; + + Ok(ParseProgramResult { + ast_json, + paths: result + .paths + .iter() + .map(|p| p.to_str().unwrap().to_string()) + .collect(), + errors: result.errors.into_iter().map(|e| e.into_error()).collect(), + }) + } + + /// Parse KCL single file to Module AST JSON string with import + /// dependencies and parse errors. + /// + /// # Examples + /// + /// ``` + /// use kclvm_api::service::service_impl::KclvmServiceImpl; + /// use kclvm_api::gpyrpc::*; + /// use std::path::Path; + /// // File case + /// let serv = KclvmServiceImpl::default(); + /// let args = &ParseFileArgs { + /// path: Path::new(".").join("src").join("testdata").join("parse").join("main.k").canonicalize().unwrap().display().to_string(), + /// ..Default::default() + /// }; + /// let result = serv.parse_file(args).unwrap(); + /// assert_eq!(result.errors.len(), 0); + /// assert_eq!(result.deps.len(), 2); + /// ``` + pub fn parse_file(&self, args: &ParseFileArgs) -> anyhow::Result { + let result = parse_file(&args.path, transform_str_para(&args.source))?; + let ast_json = serde_json::to_string(&result.module)?; + + Ok(ParseFileResult { + ast_json, + deps: result + .deps + .iter() + .map(|p| p.to_str().unwrap().to_string()) + .collect(), + errors: result.errors.into_iter().map(|e| e.into_error()).collect(), + }) + } + /// Execute KCL file with args. **Note that it is not thread safe.** /// /// # Examples diff --git a/kclvm/api/src/testdata/exec-program-with-recursive.json b/kclvm/api/src/testdata/exec-program-with-recursive.json deleted file mode 100644 index 331b3ca40..000000000 --- a/kclvm/api/src/testdata/exec-program-with-recursive.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "work_dir" : "./src/testdata", - "k_filename_list":[ - "compile_recursive" - ], - "recursive": true -} \ No newline at end of file diff --git a/kclvm/api/src/testdata/exec-program-with-recursive.response.json b/kclvm/api/src/testdata/exec-program-with-recursive.response.json deleted file mode 100644 index 7f8414248..000000000 --- a/kclvm/api/src/testdata/exec-program-with-recursive.response.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "json_result": "[{\"k1\": \"Hello k1!\", \"k2\": \"Hello k2!\", \"The_first_kcl_program\": \"Hello World!\"}]", - "yaml_result": "k1: Hello k1!\nk2: Hello k2!\nThe_first_kcl_program: Hello World!", - "escaped_time": "0.002061128616333008" -} diff --git a/kclvm/api/src/testdata/parse/kcl.mod b/kclvm/api/src/testdata/parse/kcl.mod new file mode 100644 index 000000000..e69de29bb diff --git a/kclvm/api/src/testdata/parse/main.k b/kclvm/api/src/testdata/parse/main.k new file mode 100644 index 000000000..1f0792f7b --- /dev/null +++ b/kclvm/api/src/testdata/parse/main.k @@ -0,0 +1,5 @@ +import pkg1 +import pkg2 + +a1 = pkg1.a +a2 = pkg2.a diff --git a/kclvm/api/src/testdata/parse/pkg1/pkg.k b/kclvm/api/src/testdata/parse/pkg1/pkg.k new file mode 100644 index 000000000..1337a530c --- /dev/null +++ b/kclvm/api/src/testdata/parse/pkg1/pkg.k @@ -0,0 +1 @@ +a = 1 diff --git a/kclvm/api/src/testdata/parse/pkg2/pkg.k b/kclvm/api/src/testdata/parse/pkg2/pkg.k new file mode 100644 index 000000000..1337a530c --- /dev/null +++ b/kclvm/api/src/testdata/parse/pkg2/pkg.k @@ -0,0 +1 @@ +a = 1 diff --git a/kclvm/ast/src/ast.rs b/kclvm/ast/src/ast.rs index d5ff6d34b..fe3b1ae9c 100644 --- a/kclvm/ast/src/ast.rs +++ b/kclvm/ast/src/ast.rs @@ -314,7 +314,6 @@ pub struct SymbolSelectorSpec { #[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)] pub struct Program { pub root: String, - pub main: String, pub pkgs: HashMap>, } @@ -326,6 +325,13 @@ impl Program { None => vec![], } } + /// Get the first module in the main package. + pub fn get_main_package_first_module(&self) -> Option<&Module> { + match self.pkgs.get(crate::MAIN_PKG) { + Some(modules) => modules.first(), + None => None, + } + } /// Get stmt on position pub fn pos_to_stmt(&self, pos: &Position) -> Option> { for (_, v) in &self.pkgs { @@ -340,7 +346,7 @@ impl Program { } /// Module is an abstract syntax tree for a single KCL file. -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)] pub struct Module { pub filename: String, pub pkg: String, @@ -379,6 +385,7 @@ impl Module { /// A statement #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum Stmt { TypeAlias(TypeAliasStmt), Expr(ExprStmt), @@ -647,6 +654,7 @@ pub struct RuleStmt { /// A expression #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum Expr { Identifier(Identifier), Unary(UnaryExpr), @@ -839,6 +847,7 @@ pub struct ListIfItemExpr { pub orelse: Option>, } +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub enum CompType { List, Dict, @@ -1074,6 +1083,7 @@ pub struct Compare { /// """long string literal""" /// ``` #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum Literal { Number(NumberLit), String(StringLit), @@ -1137,6 +1147,7 @@ impl NumberBinarySuffix { } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum NumberLitValue { Int(i64), Float(f64), @@ -1502,6 +1513,7 @@ impl CmpOp { /// BinOrCmpOp is the set of all binary and comparison operators in KCL. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum BinOrCmpOp { Bin(BinOp), Cmp(CmpOp), @@ -1509,6 +1521,7 @@ pub enum BinOrCmpOp { /// BinOrAugOp is the set of all binary and argument operators in KCL. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum BinOrAugOp { Bin(BinOp), Aug(AugOp), @@ -1525,6 +1538,7 @@ pub enum ExprContext { /// A expression #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum Type { Any, Named(Identifier), @@ -1567,6 +1581,7 @@ pub struct UnionType { } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(tag = "type", content = "data")] pub enum LiteralType { Bool(bool), Int(i64, Option), // value + suffix diff --git a/kclvm/ast_pretty/src/tests.rs b/kclvm/ast_pretty/src/tests.rs index 191327ebe..b75a6c3e5 100644 --- a/kclvm/ast_pretty/src/tests.rs +++ b/kclvm/ast_pretty/src/tests.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; use super::print_ast_module; -use kclvm_parser::parse_file; +use kclvm_parser::parse_file_force_errors; use pretty_assertions::assert_eq; const FILE_INPUT_SUFFIX: &str = ".input"; @@ -35,7 +35,7 @@ fn read_data(data_name: &str) -> (String, String) { .to_string(), ); - let module = parse_file(filename.to_str().unwrap(), None); + let module = parse_file_force_errors(filename.to_str().unwrap(), None); let mut filename_expect = PathBuf::from(env!("CARGO_MANIFEST_DIR")); filename_expect.push( diff --git a/kclvm/cmd/src/settings.rs b/kclvm/cmd/src/settings.rs index f695faa66..3a8d27928 100644 --- a/kclvm/cmd/src/settings.rs +++ b/kclvm/cmd/src/settings.rs @@ -52,7 +52,6 @@ pub(crate) fn build_settings(matches: &ArgMatches) -> Result { verbose: u32_from_matches(matches, "verbose"), debug: bool_from_matches(matches, "debug"), sort_keys: bool_from_matches(matches, "sort_keys"), - recursive: bool_from_matches(matches, "recursive"), package_maps, ..Default::default() }), diff --git a/kclvm/config/src/cache.rs b/kclvm/config/src/cache.rs index 98b5158e9..f8f3f0414 100644 --- a/kclvm/config/src/cache.rs +++ b/kclvm/config/src/cache.rs @@ -1,6 +1,7 @@ // Copyright 2021 The KCL Authors. All rights reserved. extern crate chrono; use super::modfile::KCL_FILE_SUFFIX; +use anyhow::Result; use crypto::digest::Digest; use crypto::md5::Md5; use fslock::LockFile; @@ -102,12 +103,16 @@ pub fn save_pkg_cache( data: T, option: CacheOption, external_pkgs: &HashMap, -) -> Result<(), String> +) -> Result<()> where T: Serialize, { if root.is_empty() || pkgpath.is_empty() { - return Err("failed to save cache".to_string()); + return Err(anyhow::anyhow!( + "failed to save package cache {} to root {}", + pkgpath, + root + )); } let dst_filename = get_cache_filename(root, target, pkgpath, Some(&option.cache_dir)); let real_path = get_pkg_realpath_from_pkgpath(root, pkgpath); @@ -117,7 +122,9 @@ where // If the file does not exist, it is an external package. let pkg_name = parse_external_pkg_name(pkgpath)?; let real_path = get_pkg_realpath_from_pkgpath( - external_pkgs.get(&pkg_name).ok_or("failed to save cache")?, + external_pkgs + .get(&pkg_name) + .ok_or(anyhow::anyhow!("failed to save cache"))?, &rm_external_pkg_name(pkgpath)?, ); if Path::new(&real_path).exists() { diff --git a/kclvm/config/src/path.rs b/kclvm/config/src/path.rs index afe73aef2..622069bce 100644 --- a/kclvm/config/src/path.rs +++ b/kclvm/config/src/path.rs @@ -12,9 +12,7 @@ //! The real path of `${my_pkg:KCL_MOD}/xxx/main.k` is `/usr/my_pkg/sub/main.k`. use anyhow::Result; use pcre2::bytes::Regex; -use std::path::{Path, PathBuf}; - -use crate::modfile::KCL_FILE_SUFFIX; +use std::path::PathBuf; #[derive(Clone, Debug, Default)] /// [`ModRelativePath`] is a path that is relative to the root package path. @@ -146,21 +144,6 @@ impl ModRelativePath { }, )) } - - /// [`is_dir`] returns true if the path is a directory. - /// - /// # Examples - /// - /// ```rust - /// use kclvm_config::path::ModRelativePath; - /// let path = ModRelativePath::new("${name:KCL_MOD}/src/path".to_string()); - /// assert_eq!(path.is_dir(), true); - /// let path = ModRelativePath::new("${name:KCL_MOD}/src/path/main.k".to_string()); - /// assert_eq!(path.is_dir(), false); - /// ``` - pub fn is_dir(&self) -> bool { - Path::new(&self.path).is_dir() || !self.path.ends_with(KCL_FILE_SUFFIX) - } } #[cfg(test)] diff --git a/kclvm/config/src/settings.rs b/kclvm/config/src/settings.rs index 8d77ba799..dff2aabd9 100644 --- a/kclvm/config/src/settings.rs +++ b/kclvm/config/src/settings.rs @@ -60,8 +60,6 @@ pub struct Config { pub verbose: Option, pub debug: Option, pub sort_keys: Option, - /// Whether recursively compile all sub directories. - pub recursive: Option, /// Whether including schema type in JSON/YAML result. pub include_schema_type_path: Option, /// kcl needs a mapping between the package name and the package path @@ -85,7 +83,6 @@ impl SettingsFile { sort_keys: Some(false), include_schema_type_path: Some(false), package_maps: Some(HashMap::default()), - recursive: Some(false), }), kcl_options: Some(vec![]), } @@ -384,7 +381,6 @@ pub fn merge_settings(settings: &[SettingsFile]) -> SettingsFile { set_if!(result_kcl_cli_configs, verbose, kcl_cli_configs); set_if!(result_kcl_cli_configs, debug, kcl_cli_configs); set_if!(result_kcl_cli_configs, sort_keys, kcl_cli_configs); - set_if!(result_kcl_cli_configs, recursive, kcl_cli_configs); set_if!( result_kcl_cli_configs, include_schema_type_path, diff --git a/kclvm/driver/src/lib.rs b/kclvm/driver/src/lib.rs index e849deea6..533cbb595 100644 --- a/kclvm/driver/src/lib.rs +++ b/kclvm/driver/src/lib.rs @@ -7,7 +7,6 @@ pub const DEFAULT_PROJECT_FILE: &str = "project.yaml"; mod tests; use glob::glob; -use kclvm_ast::ast; use kclvm_config::{ modfile::{get_pkg_root, KCL_FILE_EXTENSION, KCL_FILE_SUFFIX, KCL_MOD_PATH_ENV}, path::ModRelativePath, @@ -162,17 +161,6 @@ pub fn lookup_compile_unit( let mut load_opt = kclvm_parser::LoadProgramOptions { work_dir: work_dir.clone(), - cmd_args: if let Some(options) = setting.clone().kcl_options { - options - .iter() - .map(|o| ast::CmdArgSpec { - name: o.key.to_string(), - value: o.value.to_string(), - }) - .collect() - } else { - vec![] - }, ..Default::default() }; match canonicalize_input_files(&files, work_dir, true) { diff --git a/kclvm/parser/Cargo.toml b/kclvm/parser/Cargo.toml index a1a1d42b5..146666f2d 100644 --- a/kclvm/parser/Cargo.toml +++ b/kclvm/parser/Cargo.toml @@ -19,6 +19,7 @@ either = "1.1.0" enquote = "1.1.0" unicode_names2 = "0.4" bstr = "0.2.16" +petgraph = "0.6.0" num-bigint = "0.4" regex = "1.7.0" anyhow = "1.0" diff --git a/kclvm/parser/src/entry.rs b/kclvm/parser/src/entry.rs index a8da17585..c607e8ae9 100644 --- a/kclvm/parser/src/entry.rs +++ b/kclvm/parser/src/entry.rs @@ -91,7 +91,7 @@ impl Entries { } count += 1; } - return None; + None } /// [`get_nth_entry_by_name`] will return the nth [`Entry`] by name in [`Entries`]. @@ -105,12 +105,12 @@ impl Entries { } /// [`apply_to_all_entries`] will apply the given function to all [`Entry`] in [`Entries`]. - pub fn apply_to_all_entries(&mut self, f: F) -> Result<(), String> + pub fn apply_to_all_entries(&mut self, f: F) -> Result<()> where - F: FnMut(&mut Entry) -> Result<(), String>, + F: FnMut(&mut Entry) -> Result<()>, { self.entries.iter_mut().try_for_each(f)?; - return Ok(()); + Ok(()) } /// [`get_root_path`] will return the root path of [`Entries`]. @@ -278,34 +278,24 @@ impl Entry { pub fn get_compile_entries_from_paths( file_paths: &[String], opts: &LoadProgramOptions, -) -> Result { +) -> Result { if file_paths.is_empty() { - return Err("No input KCL files or paths".to_string()); + return Err(anyhow::anyhow!("No input KCL files or paths")); } let mut result = Entries::default(); let mut k_code_queue = VecDeque::from(opts.k_code_list.clone()); - for (i, s) in file_paths.iter().enumerate() { + for s in file_paths { let path = ModRelativePath::from(s.to_string()); - if path.is_dir() && opts.k_code_list.len() > i { - return Err("Invalid code list".to_string()); - } - - // If the path is a [`ModRelativePath`] with preffix '${:KCL_MOD}', + // If the path is a [`ModRelativePath`] with prefix '${:KCL_MOD}', // calculate the real path and the package name. - if let Some((pkg_name, pkg_path)) = path - .get_root_pkg_name() - .map_err(|err| err.to_string())? - .and_then(|name| { - opts.package_maps - .get(&name) - .map(|pkg_path: &String| (name, pkg_path)) - }) - { - // Replace the mod relative path preffix '${:KCL_MOD}' with the real path. - let s = path - .canonicalize_by_root_path(pkg_path) - .map_err(|err| err.to_string())?; + if let Some((pkg_name, pkg_path)) = path.get_root_pkg_name()?.and_then(|name| { + opts.package_maps + .get(&name) + .map(|pkg_path: &String| (name, pkg_path)) + }) { + // Replace the mod relative path prefix '${:KCL_MOD}' with the real path. + let s = path.canonicalize_by_root_path(pkg_path)?; if let Some(root) = get_pkg_root(&s) { let mut entry: Entry = Entry::new(pkg_name.clone(), root.clone()); entry.extend_k_files_and_codes( @@ -315,13 +305,8 @@ pub fn get_compile_entries_from_paths( result.push_entry(entry); continue; } - // If the [`ModRelativePath`] with preffix '${KCL_MOD}' - } else if path.is_relative_path().map_err(|err| err.to_string())? - && path - .get_root_pkg_name() - .map_err(|err| err.to_string())? - .is_none() - { + // If the [`ModRelativePath`] with prefix '${KCL_MOD}' + } else if path.is_relative_path()? && path.get_root_pkg_name()?.is_none() { // Push it into `result`, and deal it later. let mut entry = Entry::new(kclvm_ast::MAIN_PKG.to_string(), path.get_path()); entry.push_k_code(k_code_queue.pop_front()); @@ -331,7 +316,7 @@ pub fn get_compile_entries_from_paths( // If the path is a normal path. let mut entry: Entry = Entry::new(kclvm_ast::MAIN_PKG.to_string(), root.clone()); entry.extend_k_files_and_codes( - get_main_files_from_pkg_path(&s, &root, &kclvm_ast::MAIN_PKG.to_string(), opts)?, + get_main_files_from_pkg_path(s, &root, kclvm_ast::MAIN_PKG, opts)?, &mut k_code_queue, ); result.push_entry(entry); @@ -346,7 +331,7 @@ pub fn get_compile_entries_from_paths( let mut entry = Entry::new(kclvm_ast::MAIN_PKG.to_string(), "".to_string()); for s in file_paths { entry.extend_k_files_and_codes( - get_main_files_from_pkg_path(s, "", &kclvm_ast::MAIN_PKG.to_string(), opts)?, + get_main_files_from_pkg_path(s, "", kclvm_ast::MAIN_PKG, opts)?, &mut k_code_queue, ); } @@ -379,23 +364,19 @@ pub fn get_compile_entries_from_paths( // Replace the '${KCL_MOD}' of all the paths with package name '__main__'. result.apply_to_all_entries(|entry| { let path = ModRelativePath::from(entry.path().to_string()); - if entry.name() == kclvm_ast::MAIN_PKG - && path.is_relative_path().map_err(|err| err.to_string())? - { + if entry.name() == kclvm_ast::MAIN_PKG && path.is_relative_path()? { entry.set_path(pkg_root.to_string()); entry.extend_k_files(get_main_files_from_pkg_path( - &path - .canonicalize_by_root_path(&pkg_root) - .map_err(|err| err.to_string())?, + &path.canonicalize_by_root_path(&pkg_root)?, &pkg_root, - &kclvm_ast::MAIN_PKG.to_string(), + kclvm_ast::MAIN_PKG, opts, )?); } - return Ok(()); + Ok(()) })?; - return Ok(result); + Ok(result) } /// Get files in the main package with the package root. @@ -404,22 +385,20 @@ fn get_main_files_from_pkg_path( root: &str, pkg_name: &str, opts: &LoadProgramOptions, -) -> Result, String> { +) -> Result> { // fix path let mut path_list = Vec::new(); let mut s = pkg_path.to_string(); let path = ModRelativePath::from(s.to_string()); - if path.is_relative_path().map_err(|e| e.to_string())? { - if let Some(name) = path.get_root_pkg_name().map_err(|e| e.to_string())? { + if path.is_relative_path()? { + if let Some(name) = path.get_root_pkg_name()? { if name == pkg_name { - s = path - .canonicalize_by_root_path(root) - .map_err(|e| e.to_string())?; + s = path.canonicalize_by_root_path(root)?; } - } else if path.is_relative_path().map_err(|e| e.to_string())? { - return Err(format!("Can not find {} in the path: {}", s, root)); + } else if path.is_relative_path()? { + return Err(anyhow::anyhow!("Can not find {} in the path: {}", s, root)); } } if !root.is_empty() && !is_absolute(s.as_str()) { @@ -438,10 +417,10 @@ fn get_main_files_from_pkg_path( // read dir/*.k if is_dir(path) { if opts.k_code_list.len() > i { - return Err("Invalid code list".to_string()); + return Err(anyhow::anyhow!("Invalid code list")); } - //k_code_list - for s in get_dir_files(path, opts.recursive)? { + // k_code_list + for s in get_dir_files(path, false)? { k_files.push(s); } continue; @@ -451,7 +430,7 @@ fn get_main_files_from_pkg_path( } if k_files.is_empty() { - return Err("No input KCL files".to_string()); + return Err(anyhow::anyhow!("No input KCL files")); } // check all file exists @@ -461,7 +440,7 @@ fn get_main_files_from_pkg_path( } if !path_exist(filename.as_str()) { - return Err(format!( + return Err(anyhow::anyhow!( "Cannot find the kcl file, please check the file path {}", filename.as_str(), )); @@ -471,7 +450,7 @@ fn get_main_files_from_pkg_path( } /// Get file list in the directory. -pub fn get_dir_files(dir: &str, is_recursive: bool) -> Result, String> { +pub fn get_dir_files(dir: &str, is_recursive: bool) -> Result> { if !std::path::Path::new(dir).exists() { return Ok(Vec::new()); } @@ -497,7 +476,7 @@ pub fn get_dir_files(dir: &str, is_recursive: bool) -> Result, Strin } } Err(err) => { - return Err(format!( + return Err(anyhow::anyhow!( "Failed to read directory: {},{}", path.display(), err diff --git a/kclvm/parser/src/file_graph.rs b/kclvm/parser/src/file_graph.rs new file mode 100644 index 000000000..9fdbe6301 --- /dev/null +++ b/kclvm/parser/src/file_graph.rs @@ -0,0 +1,103 @@ +use indexmap::IndexMap; +use petgraph::visit::EdgeRef; +use std::path::{Path, PathBuf}; + +/// 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, +} + +impl FileGraph { + /// 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>( + &mut self, + from_path: &Path, + to_paths: I, + ) { + let from_node_index = self.get_or_insert_node_index(from_path); + + // remove all current out coming edges from this node + self.graph.retain_edges(|g, edge| { + if let Some((source, _)) = g.edge_endpoints(edge) { + if source == from_node_index { + return false; + } + } + true + }); + + for to_path in to_paths { + let to_node_index = self.get_or_insert_node_index(to_path); + self.graph.add_edge(from_node_index, to_node_index, ()); + } + } + + /// 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) + } + + /// 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::>() + } + + /// 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(_) => { + // 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 = strongly_connected_components + .into_iter() + .find(|component| component.len() > 1) + .unwrap(); + Err(cycle + .iter() + .map(|n| self.graph[*n].clone()) + .collect::>()) + } + } + } + + /// Returns all paths. + #[inline] + 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) { + return *node_index; + } + + let node_index = self.graph.add_node(path.to_owned()); + self.path_to_node_index.insert(path.to_owned(), node_index); + node_index + } +} diff --git a/kclvm/parser/src/lexer/mod.rs b/kclvm/parser/src/lexer/mod.rs index 72eb98d47..fe87dbffb 100644 --- a/kclvm/parser/src/lexer/mod.rs +++ b/kclvm/parser/src/lexer/mod.rs @@ -457,8 +457,9 @@ impl<'a> Lexer<'a> { // and the multi-character tokens that need to be lexed in ['kclvm-parser/lexer'] are only token '->'. // If a new multi-character token is added later, the corresponding operation can be added here. kclvm_lexer::TokenKind::Gt => { - if let Some(_) = - tok_stream_builder.pop_if_tok_kind(&TokenKind::BinOp(BinOpToken::Minus)) + if tok_stream_builder + .pop_if_tok_kind(&TokenKind::BinOp(BinOpToken::Minus)) + .is_some() { // After the previous token pops up, 'self.tok_start_pos' needs to be updated. if self.tok_start_pos >= new_byte_pos(1) { diff --git a/kclvm/parser/src/lexer/tests.rs b/kclvm/parser/src/lexer/tests.rs index 2d601578e..8d6ec4b75 100644 --- a/kclvm/parser/src/lexer/tests.rs +++ b/kclvm/parser/src/lexer/tests.rs @@ -55,7 +55,7 @@ fn lex(src: &str) -> (String, String) { .map(|err| err.as_ref().unwrap().to_string()) .collect(); - return (res, err_msgs); + (res, err_msgs) } /// check the invalid panic message. diff --git a/kclvm/parser/src/lib.rs b/kclvm/parser/src/lib.rs index c2efdd6fa..fc67081e0 100644 --- a/kclvm/parser/src/lib.rs +++ b/kclvm/parser/src/lib.rs @@ -1,6 +1,7 @@ // Copyright 2021 The KCL Authors. All rights reserved. pub mod entry; +pub mod file_graph; mod lexer; mod parser; mod session; @@ -15,20 +16,21 @@ pub use crate::session::ParseSession; use compiler_base_macros::bug; use compiler_base_session::Session; use compiler_base_span::span::new_byte_pos; -use indexmap::IndexMap; +use file_graph::FileGraph; +use indexmap::{IndexMap, IndexSet}; use kclvm_ast::ast; use kclvm_config::modfile::{get_vendor_home, KCL_FILE_EXTENSION, KCL_FILE_SUFFIX, KCL_MOD_FILE}; -use kclvm_error::diagnostic::Range; -use kclvm_error::{ErrorKind, Message, Style}; +use kclvm_error::diagnostic::{Diagnostic, Range}; +use kclvm_error::{ErrorKind, Message, Position, Style}; use kclvm_sema::plugin::PLUGIN_MODULE_PREFIX; -use kclvm_utils::path::PathPrefix; use kclvm_utils::pkgpath::parse_external_pkg_name; 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::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; use kclvm_span::create_session_globals_then; @@ -70,90 +72,93 @@ pub enum ParseMode { ParseComments, } -/// Parse a KCL file to the AST Program. -pub fn parse_program(filename: &str) -> Result { - let abspath = std::fs::canonicalize(std::path::PathBuf::from(filename)).unwrap(); +type Errors = IndexSet; - let mut prog = ast::Program { - root: abspath.parent().unwrap().adjust_canonicalization(), - main: kclvm_ast::MAIN_PKG.to_string(), - pkgs: HashMap::new(), - }; - - let mut module = parse_file(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(); +/// LoadProgramResult denotes the result of the whole program and a topological +/// ordering of all known files, +#[derive(Debug, Clone)] +pub struct LoadProgramResult { + /// Program AST + pub program: ast::Program, + /// Parse errors + pub errors: Errors, + /// The topological ordering of all known files. + pub paths: Vec, +} - prog.pkgs - .insert(kclvm_ast::MAIN_PKG.to_string(), vec![module]); +/// ParseFileResult denotes the result of a single file including AST, +/// errors and import dependencies. +#[derive(Debug, Clone)] +pub struct ParseFileResult { + /// Module AST + pub module: ast::Module, + /// Parse errors + pub errors: Errors, + /// Dependency paths. + pub deps: Vec, +} - Ok(prog) +/// Parse a KCL file to the AST module with parse errors. +pub fn parse_file(filename: &str, code: Option) -> Result { + let sess = Arc::new(ParseSession::default()); + let mut loader = Loader::new( + sess, + &[filename], + Some(LoadProgramOptions { + load_packages: false, + k_code_list: if let Some(code) = code { + vec![code] + } else { + vec![] + }, + ..Default::default() + }), + None, + ); + let result = loader.load_main()?; + let module = match result.program.get_main_package_first_module() { + Some(module) => module.clone(), + None => ast::Module::default(), + }; + let filename = module.filename.clone(); + let path = Path::new(&filename); + 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![] + }, + }) } -/// Parse a KCL file to the AST module. -#[inline] -pub fn parse_file(filename: &str, code: Option) -> Result { +/// Parse a KCL file to the AST module and return errors when meets parse errors as result. +pub fn parse_file_force_errors(filename: &str, code: Option) -> Result { let sess = Arc::new(ParseSession::default()); let result = parse_file_with_global_session(sess.clone(), filename, code); - if sess - .0 - .diag_handler - .has_errors() - .map_err(|e| e.to_string())? - { + if sess.0.diag_handler.has_errors()? { let err = sess .0 - .emit_nth_diag_into_string(0) - .map_err(|e| e.to_string())? - .unwrap_or(Ok(ErrorKind::InvalidSyntax.name())) - .map_err(|e| e.to_string())?; - Err(err) + .emit_nth_diag_into_string(0)? + .unwrap_or(Ok(ErrorKind::InvalidSyntax.name()))?; + Err(anyhow::anyhow!(err)) } else { result } } -/// Parse a KCL file with all errors. -/// -/// Note that an optional AST structure is returned here because there may be other error reasons -/// that may result in no AST being returned, such as file not being found, etc. -pub fn parse_file_with_errors( - filename: &str, - code: Option, -) -> (Option, String) { - let sess = Arc::new(ParseSession::default()); - match parse_file_with_global_session(sess.clone(), filename, code) { - Ok(module) => match sess.0.diag_handler.has_errors() { - Ok(has_error) => { - let get_err = || -> anyhow::Result { - let err = sess - .0 - .emit_nth_diag_into_string(0)? - .unwrap_or(Ok(ErrorKind::InvalidSyntax.name()))?; - Ok(err) - }; - if has_error { - match get_err() { - Ok(err) => (Some(module), err), - Err(err) => (Some(module), err.to_string()), - } - } else { - (Some(module), "".to_string()) - } - } - Err(err) => (Some(module), err.to_string()), - }, - Err(err) => (None, err), - } -} - /// Parse a KCL file to the AST module with the parse session . pub fn parse_file_with_session( sess: Arc, filename: &str, code: Option, -) -> Result { +) -> Result { // Code source. let src = if let Some(s) = code { s @@ -161,7 +166,7 @@ pub fn parse_file_with_session( match std::fs::read_to_string(filename) { Ok(src) => src, Err(err) => { - return Err(format!( + return Err(anyhow::anyhow!( "Failed to load KCL file '{filename}'. Because '{err}'" )); } @@ -177,7 +182,7 @@ pub fn parse_file_with_session( let src_from_sf = match sf.src.as_ref() { Some(src) => src, None => { - return Err(format!( + return Err(anyhow::anyhow!( "Internal Bug: Failed to load KCL file '{filename}'." )); } @@ -201,7 +206,7 @@ pub fn parse_file_with_global_session( sess: Arc, filename: &str, code: Option, -) -> Result { +) -> Result { create_session_globals_then(move || parse_file_with_session(sess, filename, code)) } @@ -248,11 +253,7 @@ pub struct LoadProgramOptions { pub work_dir: String, pub k_code_list: Vec, pub vendor_dirs: Vec, - pub recursive: bool, pub package_maps: HashMap, - - pub cmd_args: Vec, - pub cmd_overrides: Vec, /// The parser mode. pub mode: ParseMode, /// Whether to load packages. @@ -268,12 +269,9 @@ impl Default for LoadProgramOptions { k_code_list: Default::default(), vendor_dirs: vec![get_vendor_home()], package_maps: Default::default(), - cmd_args: Default::default(), - cmd_overrides: Default::default(), mode: ParseMode::ParseComments, load_packages: true, load_plugins: false, - recursive: false, } } } @@ -305,7 +303,7 @@ pub fn load_program( paths: &[&str], opts: Option, module_cache: Option, -) -> Result { +) -> Result { Loader::new(sess, paths, opts, module_cache).load_main() } @@ -316,6 +314,7 @@ struct Loader { opts: LoadProgramOptions, missing_pkgs: Vec, module_cache: Option, + file_graph: FileGraph, } impl Loader { @@ -329,30 +328,28 @@ impl Loader { sess, paths: paths.iter().map(|s| s.to_string()).collect(), opts: opts.unwrap_or_default(), - missing_pkgs: Default::default(), module_cache, + missing_pkgs: Default::default(), + file_graph: FileGraph::default(), } } #[inline] - fn load_main(&mut self) -> Result { + fn load_main(&mut self) -> Result { create_session_globals_then(move || self._load_main()) } - fn _load_main(&mut self) -> Result { - // todo: need to vfs to support only compile kcl code + fn _load_main(&mut self) -> Result { let compile_entries = get_compile_entries_from_paths(&self.paths, &self.opts)?; - let mut pkgs = HashMap::new(); let workdir = compile_entries.get_root_path().to_string(); + let mut pkgs = HashMap::new(); let mut pkg_files = Vec::new(); for entry in compile_entries.iter() { // Get files from options with root. // let k_files = self.get_main_files_from_pkg(entry.path(), entry.name())?; let k_files = entry.get_k_files(); let maybe_k_codes = entry.get_k_codes(); - - // load module - + // 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 m = parse_file_with_session( @@ -366,14 +363,14 @@ impl Loader { } else { parse_file_with_session(self.sess.clone(), filename, maybe_k_codes[i].clone())? }; - self.fix_rel_import_path(entry.path(), &mut m); + fix_rel_import_path(entry.path(), &mut m); pkg_files.push(m); } // 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.path(), entry.name().to_string(), &mut pkg_files, &mut pkgs, @@ -381,10 +378,42 @@ impl Loader { } // Insert the complete ast to replace the empty list. pkgs.insert(kclvm_ast::MAIN_PKG.to_string(), pkg_files); - Ok(ast::Program { + let program = ast::Program { root: workdir, - main: kclvm_ast::MAIN_PKG.to_string(), 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.borrow_mut().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() + } + }; + + Ok(LoadProgramResult { + program, + errors: self.sess.1.borrow().diagnostics.clone(), + paths, }) } @@ -403,7 +432,7 @@ impl Loader { pkg_name: &str, pkg_root: &str, pkg_path: &str, - ) -> Result, String> { + ) -> Result> { // 1. Look for in the current package's directory. let is_internal = self.is_internal_pkg(pkg_name, pkg_root, pkg_path)?; @@ -430,7 +459,7 @@ impl Loader { // 4. Get package information based on whether the package is internal or external. match is_internal.or(is_external) { - Some(pkg_info) => return Ok(Some(pkg_info)), + Some(pkg_info) => Ok(Some(pkg_info)), None => { self.sess.1.borrow_mut().add_error( ErrorKind::CannotFindModule, @@ -455,9 +484,9 @@ impl Loader { ); } self.sess.1.borrow_mut().add_suggestions(suggestions); - return Ok(None); + Ok(None) } - }; + } } /// [`load_import_package`] will traverse all the [`kclvm_ast::ImportStmt`] on the input AST nodes [`pkg`], @@ -473,8 +502,9 @@ impl Loader { pkg_name: String, pkg: &mut [ast::Module], pkgs: &mut HashMap>, - ) -> Result<(), String> { + ) -> 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 { @@ -485,33 +515,28 @@ impl Loader { ); import_spec.pkg_name = pkg_name.to_string(); // Load the import package source code and compile. - if let Some(pkg_info) = self.load_package( - &pkgroot, + 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 + 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); } - return Ok(()); - } - - fn fix_rel_import_path(&mut self, 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(), - ); - } - } + Ok(()) } /// [`load_package`] will return some basic information about the package @@ -523,11 +548,7 @@ impl Loader { pkgpath: String, pos: ast::Pos, pkgs: &mut HashMap>, - ) -> Result, String> { - if !self.opts.load_packages { - return Ok(None); - } - + ) -> Result> { if pkgpath.is_empty() { return Ok(None); } @@ -577,6 +598,11 @@ impl Loader { return Ok(Some(pkg_info)); } + if !self.opts.load_packages { + return Ok(Some(pkg_info)); + } + + // Load packages let mut pkg_files = Vec::new(); let k_files = pkg_info.k_files.clone(); for filename in k_files { @@ -597,7 +623,7 @@ impl Loader { m.pkg = pkg_info.pkg_path.clone(); m.name = "".to_string(); - self.fix_rel_import_path(&pkg_info.pkg_root, &mut m); + fix_rel_import_path(&pkg_info.pkg_root, &mut m); pkg_files.push(m); } @@ -618,7 +644,7 @@ impl Loader { Ok(Some(pkg_info)) } - fn get_pkg_kfile_list(&self, pkgroot: &str, pkgpath: &str) -> Result, String> { + fn get_pkg_kfile_list(&self, pkgroot: &str, pkgpath: &str) -> Result> { // plugin pkgs if self.is_plugin_pkg(pkgpath) { return Ok(Vec::new()); @@ -630,7 +656,7 @@ impl Loader { } if pkgroot.is_empty() { - return Err("pkgroot not found".to_string()); + return Err(anyhow::anyhow!("pkgroot not found")); } let mut pathbuf = std::path::PathBuf::new(); @@ -655,7 +681,7 @@ impl Loader { } /// Get file list in the directory. - fn get_dir_files(&self, dir: &str) -> Result, String> { + fn get_dir_files(&self, dir: &str) -> Result> { if !std::path::Path::new(dir).exists() { return Ok(Vec::new()); } @@ -707,7 +733,7 @@ impl Loader { pkg_name: &str, pkg_root: &str, pkg_path: &str, - ) -> Result, String> { + ) -> Result> { match self.pkg_exists(vec![pkg_root.to_string()], pkg_path) { Some(internal_pkg_root) => { let fullpath = if pkg_name == kclvm_ast::MAIN_PKG { @@ -734,15 +760,13 @@ impl Loader { /// /// - [`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, String> { + 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.clone(), pkg_path) { - Some(path) => PathBuf::from(path) - .join(pkg_name.to_string()) - .join(KCL_MOD_FILE), + Some(path) => PathBuf::from(path).join(&pkg_name).join(KCL_MOD_FILE), None => return Ok(None), } }; @@ -764,7 +788,7 @@ impl Loader { None => return Ok(None), })); } else { - return Ok(None); + Ok(None) } } @@ -788,3 +812,15 @@ impl Loader { pathbuf.exists() || pathbuf.with_extension(KCL_FILE_EXTENSION).exists() } } + +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(), + ); + } + } +} diff --git a/kclvm/parser/src/parser/stmt.rs b/kclvm/parser/src/parser/stmt.rs index 665f0705a..94d7c893e 100644 --- a/kclvm/parser/src/parser/stmt.rs +++ b/kclvm/parser/src/parser/stmt.rs @@ -1049,7 +1049,7 @@ impl<'a> Parser<'a> { if let Stmt::Assign(assign) = x.node.clone() { if assign.targets.len() == 1 { let ident = assign.targets[0].clone().node; - if let Some(_) = assign.ty { + if assign.ty.is_some() { body_body.push(node_ref!( Stmt::SchemaAttr(SchemaAttr { doc: "".to_string(), diff --git a/kclvm/parser/src/parser/tests.rs b/kclvm/parser/src/parser/tests.rs index 5c82ed8c0..6315e36b7 100644 --- a/kclvm/parser/src/parser/tests.rs +++ b/kclvm/parser/src/parser/tests.rs @@ -1,9 +1,9 @@ -use crate::parse_file; +use crate::parse_file_force_errors; use regex::Regex; #[test] fn test_parse_file_not_found() { - match parse_file("The file path is invalid", None) { + match parse_file_force_errors("The file path is invalid", None) { Ok(_) => { panic!("unreachable") } @@ -11,7 +11,7 @@ fn test_parse_file_not_found() { assert!( Regex::new(r"^Failed to load KCL file 'The file path is invalid'. Because.*") .unwrap() - .is_match(&err_msg) + .is_match(&err_msg.to_string()) ); } } diff --git a/kclvm/parser/src/parser/ty.rs b/kclvm/parser/src/parser/ty.rs index df693664a..05a23eca6 100644 --- a/kclvm/parser/src/parser/ty.rs +++ b/kclvm/parser/src/parser/ty.rs @@ -234,7 +234,7 @@ impl<'a> Parser<'a> { } } // If there is no params type, set it to None - let params_ty = if params_type.len() == 0 { + let params_ty = if params_type.is_empty() { None } else { Some(params_type) diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index 92ceeb9b1..4934fe4ac 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -141,14 +141,15 @@ pub(crate) fn parsing_file_ast_json(filename: &str, src: &str) -> String { Some(src.into()), ) .unwrap(); - serde_json::ser::to_string(&m).unwrap() + serde_json::ser::to_string_pretty(&m).unwrap() } pub(crate) fn parsing_file_string(filename: &str) -> String { let code = std::fs::read_to_string(filename).unwrap(); - let m = - crate::parse_file(filename.trim_start_matches("testdata/"), Some(code)).expect(filename); - serde_json::ser::to_string(&m).unwrap() + let m = crate::parse_file(filename.trim_start_matches("testdata/"), Some(code)) + .expect(filename) + .module; + serde_json::ser::to_string_pretty(&m).unwrap() } pub fn check_result_panic_info(result: Result<(), Box>) { @@ -188,7 +189,7 @@ const PARSE_FILE_INVALID_TEST_CASES: &[&str] = &[ #[test] pub fn test_parse_file_invalid() { for case in PARSE_FILE_INVALID_TEST_CASES { - let result = parse_file("test.k", Some((&case).to_string())); + let result = parse_file_force_errors("test.k", Some((&case).to_string())); assert!(result.is_err(), "case: {case}, result {result:?}"); } } @@ -291,7 +292,9 @@ pub fn test_import_vendor() { let test_fn = |test_case_name: &&str, pkgs: &Vec<&str>, module_cache: Option| { let test_case_path = dir.join(test_case_name).display().to_string(); - let m = load_program(sess.clone(), &[&test_case_path], None, module_cache).unwrap(); + let m = load_program(sess.clone(), &[&test_case_path], None, module_cache) + .unwrap() + .program; assert_eq!(m.pkgs.len(), pkgs.len()); m.pkgs.into_iter().for_each(|(name, modules)| { println!("{:?} - {:?}", test_case_name, name); @@ -335,7 +338,9 @@ pub fn test_import_vendor_without_kclmod() { test_cases.into_iter().for_each(|(test_case_name, pkgs)| { let test_case_path = dir.join(test_case_name).display().to_string(); - let m = load_program(sess.clone(), &[&test_case_path], None, None).unwrap(); + let m = load_program(sess.clone(), &[&test_case_path], None, None) + .unwrap() + .program; assert_eq!(m.pkgs.len(), pkgs.len()); m.pkgs.into_iter().for_each(|(name, modules)| { assert!(pkgs.contains(&name.as_str())); @@ -569,8 +574,9 @@ fn test_import_vendor_by_external_arguments() { external_dir.join(dep_name).display().to_string(), ); let test_case_path = dir.join(test_case_name).display().to_string(); - let m = load_program(sess.clone(), &[&test_case_path], None, module_cache).unwrap(); - + let m = load_program(sess.clone(), &[&test_case_path], None, module_cache) + .unwrap() + .program; assert_eq!(m.pkgs.len(), pkgs.len()); m.pkgs.into_iter().for_each(|(name, modules)| { assert!(pkgs.contains(&name.as_str())); @@ -692,7 +698,7 @@ fn test_dir_with_k_code_list() { None, ) { Ok(_) => panic!("unreachable code"), - Err(err) => assert_eq!(err, "Invalid code list"), + Err(err) => assert!(err.to_string().contains("Invalid code list")), } match load_program( @@ -702,7 +708,7 @@ fn test_dir_with_k_code_list() { Some(KCLModuleCache::default()), ) { Ok(_) => panic!("unreachable code"), - Err(err) => assert_eq!(err, "Invalid code list"), + Err(err) => assert!(err.to_string().contains("Invalid code list")), } } 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 db43a7927..05bac82f1 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 @@ -3,4 +3,65 @@ source: parser/src/tests/ast.rs assertion_line: 36 expression: "crate::tests::parsing_file_ast_json(\"hello.k\", r####\"a=123\"####)" --- -{"filename":"hello.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":123}}},"filename":"hello.k","line":1,"column":2,"end_line":1,"end_column":5},"ty":null}},"filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":5}],"comments":[]} +{ + "filename": "hello.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 123 + } + } + }, + "filename": "hello.k", + "line": 1, + "column": 2, + "end_line": 1, + "end_column": 5 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 5 + } + ], + "comments": [] +} 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 5913a174f..a52d79d7e 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 @@ -3,4 +3,212 @@ source: parser/src/tests/ast.rs assertion_line: 59 expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\n# comment1\na = 1\n# comment22\nb = 2\n# comment333\nc = 3 # comment4444\n \"####)" --- -{"filename":"hello.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":5},"ty":null}},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":5},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":5,"column":4,"end_line":5,"end_column":5},"ty":null}},"filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":5},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"c","filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":7,"column":4,"end_line":7,"end_column":5},"ty":null}},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":5}],"comments":[{"node":{"text":"# comment1"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":10},{"node":{"text":"# comment22"},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":11},{"node":{"text":"# comment333"},"filename":"hello.k","line":6,"column":0,"end_line":6,"end_column":12},{"node":{"text":"# comment4444"},"filename":"hello.k","line":7,"column":6,"end_line":7,"end_column":19}]} +{ + "filename": "hello.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "hello.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 5 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 5 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "b", + "filename": "hello.k", + "line": 5, + "column": 0, + "end_line": 5, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 5, + "column": 0, + "end_line": 5, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "hello.k", + "line": 5, + "column": 4, + "end_line": 5, + "end_column": 5 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 5, + "column": 0, + "end_line": 5, + "end_column": 5 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "c", + "filename": "hello.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 3 + } + } + }, + "filename": "hello.k", + "line": 7, + "column": 4, + "end_line": 7, + "end_column": 5 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 5 + } + ], + "comments": [ + { + "node": { + "text": "# comment1" + }, + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 10 + }, + { + "node": { + "text": "# comment22" + }, + "filename": "hello.k", + "line": 4, + "column": 0, + "end_line": 4, + "end_column": 11 + }, + { + "node": { + "text": "# comment333" + }, + "filename": "hello.k", + "line": 6, + "column": 0, + "end_line": 6, + "end_column": 12 + }, + { + "node": { + "text": "# comment4444" + }, + "filename": "hello.k", + "line": 7, + "column": 6, + "end_line": 7, + "end_column": 19 + } + ] +} 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 2c4445ed8..ccec9abdb 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 @@ -3,4 +3,632 @@ source: parser/src/tests/ast.rs assertion_line: 37 expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\na = 10\nb = 12\n_condition = 0\nif a == 11 or b == 13: _condition = 1\nelif a == 10 and b == 12: _condition = 2\ncondition = _condition\n \"####)" --- -{"filename":"hello.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"hello.k","line":2,"column":4,"end_line":2,"end_column":6},"ty":null}},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":6},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":12}}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6},"ty":null}},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":6},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":10}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":10}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":0}}},"filename":"hello.k","line":4,"column":13,"end_line":4,"end_column":14},"ty":null}},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":14},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":33}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":33}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":5,"column":36,"end_line":5,"end_column":37},"ty":null}},"filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":37}],"cond":{"node":{"Binary":{"left":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":4},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":11}}},"filename":"hello.k","line":5,"column":8,"end_line":5,"end_column":10}]}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":21},"op":{"Bin":"Or"},"right":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":15}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":15},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":13}}},"filename":"hello.k","line":5,"column":19,"end_line":5,"end_column":21}]}},"filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":21}}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":21},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":36}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":36}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":6,"column":39,"end_line":6,"end_column":40},"ty":null}},"filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":40}],"cond":{"node":{"Binary":{"left":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":6},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"hello.k","line":6,"column":10,"end_line":6,"end_column":12}]}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":24},"op":{"Bin":"And"},"right":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":18}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":18},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":12}}},"filename":"hello.k","line":6,"column":22,"end_line":6,"end_column":24}]}},"filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":24}}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":24},"orelse":[]}},"filename":"hello.k","line":6,"column":0,"end_line":7,"end_column":0}]}},"filename":"hello.k","line":5,"column":0,"end_line":7,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"condition","filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":9}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":9}],"value":{"node":{"Identifier":{"names":[{"node":"_condition","filename":"hello.k","line":7,"column":12,"end_line":7,"end_column":22}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":7,"column":12,"end_line":7,"end_column":22},"ty":null}},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":22}],"comments":[]} +{ + "filename": "hello.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 10 + } + } + }, + "filename": "hello.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 6 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 6 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "b", + "filename": "hello.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 12 + } + } + }, + "filename": "hello.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 6 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 6 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_condition", + "filename": "hello.k", + "line": 4, + "column": 0, + "end_line": 4, + "end_column": 10 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 4, + "column": 0, + "end_line": 4, + "end_column": 10 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 0 + } + } + }, + "filename": "hello.k", + "line": 4, + "column": 13, + "end_line": 4, + "end_column": 14 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 4, + "column": 0, + "end_line": 4, + "end_column": 14 + }, + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_condition", + "filename": "hello.k", + "line": 5, + "column": 23, + "end_line": 5, + "end_column": 33 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 5, + "column": 23, + "end_line": 5, + "end_column": 33 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "hello.k", + "line": 5, + "column": 36, + "end_line": 5, + "end_column": 37 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 5, + "column": 23, + "end_line": 5, + "end_column": 37 + } + ], + "cond": { + "node": { + "type": "Binary", + "data": { + "left": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 5, + "column": 3, + "end_line": 5, + "end_column": 4 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 5, + "column": 3, + "end_line": 5, + "end_column": 4 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 11 + } + } + }, + "filename": "hello.k", + "line": 5, + "column": 8, + "end_line": 5, + "end_column": 10 + } + ] + } + }, + "filename": "hello.k", + "line": 5, + "column": 3, + "end_line": 5, + "end_column": 21 + }, + "op": { + "type": "Bin", + "data": "Or" + }, + "right": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "b", + "filename": "hello.k", + "line": 5, + "column": 14, + "end_line": 5, + "end_column": 15 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 5, + "column": 14, + "end_line": 5, + "end_column": 15 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 13 + } + } + }, + "filename": "hello.k", + "line": 5, + "column": 19, + "end_line": 5, + "end_column": 21 + } + ] + } + }, + "filename": "hello.k", + "line": 5, + "column": 14, + "end_line": 5, + "end_column": 21 + } + } + }, + "filename": "hello.k", + "line": 5, + "column": 3, + "end_line": 5, + "end_column": 21 + }, + "orelse": [ + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_condition", + "filename": "hello.k", + "line": 6, + "column": 26, + "end_line": 6, + "end_column": 36 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 6, + "column": 26, + "end_line": 6, + "end_column": 36 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "hello.k", + "line": 6, + "column": 39, + "end_line": 6, + "end_column": 40 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 6, + "column": 26, + "end_line": 6, + "end_column": 40 + } + ], + "cond": { + "node": { + "type": "Binary", + "data": { + "left": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 6, + "column": 5, + "end_line": 6, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 6, + "column": 5, + "end_line": 6, + "end_column": 6 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 10 + } + } + }, + "filename": "hello.k", + "line": 6, + "column": 10, + "end_line": 6, + "end_column": 12 + } + ] + } + }, + "filename": "hello.k", + "line": 6, + "column": 5, + "end_line": 6, + "end_column": 24 + }, + "op": { + "type": "Bin", + "data": "And" + }, + "right": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "b", + "filename": "hello.k", + "line": 6, + "column": 17, + "end_line": 6, + "end_column": 18 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 6, + "column": 17, + "end_line": 6, + "end_column": 18 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 12 + } + } + }, + "filename": "hello.k", + "line": 6, + "column": 22, + "end_line": 6, + "end_column": 24 + } + ] + } + }, + "filename": "hello.k", + "line": 6, + "column": 17, + "end_line": 6, + "end_column": 24 + } + } + }, + "filename": "hello.k", + "line": 6, + "column": 5, + "end_line": 6, + "end_column": 24 + }, + "orelse": [] + } + }, + "filename": "hello.k", + "line": 6, + "column": 0, + "end_line": 7, + "end_column": 0 + } + ] + } + }, + "filename": "hello.k", + "line": 5, + "column": 0, + "end_line": 7, + "end_column": 0 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "condition", + "filename": "hello.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 9 + } + ], + "value": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_condition", + "filename": "hello.k", + "line": 7, + "column": 12, + "end_line": 7, + "end_column": 22 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 7, + "column": 12, + "end_line": 7, + "end_column": 22 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 22 + } + ], + "comments": [] +} 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 90c6b984e..0468e901c 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 @@ -3,4 +3,358 @@ source: parser/src/tests/ast.rs assertion_line: 49 expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\ndata2 = {\n **{key = \"value1\"}\n if a == 123: if b == 456: key = \"value2\"\n}\n \"####)" --- -{"filename":"hello.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"data2","filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":5}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":5}],"value":{"node":{"Config":{"items":[{"node":{"key":null,"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"key","filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":10}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":10},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"value1\"","value":"value1"}},"filename":"hello.k","line":3,"column":13,"end_line":3,"end_column":21},"operation":"Override","insert_index":-1},"filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":21}]}},"filename":"hello.k","line":3,"column":6,"end_line":3,"end_column":22},"operation":"Union","insert_index":-1},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":22},{"node":{"key":null,"value":{"node":{"ConfigIfEntry":{"if_cond":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":123}}},"filename":"hello.k","line":4,"column":12,"end_line":4,"end_column":15}]}},"filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":15},"items":[{"node":{"key":null,"value":{"node":{"ConfigIfEntry":{"if_cond":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":21}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":21},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":456}}},"filename":"hello.k","line":4,"column":25,"end_line":4,"end_column":28}]}},"filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":28},"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"key","filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"value2\"","value":"value2"}},"filename":"hello.k","line":4,"column":36,"end_line":4,"end_column":44},"operation":"Override","insert_index":-1},"filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":44}],"orelse":null}},"filename":"hello.k","line":4,"column":17,"end_line":5,"end_column":0},"operation":"Override","insert_index":-1},"filename":"hello.k","line":4,"column":17,"end_line":5,"end_column":0}],"orelse":null}},"filename":"hello.k","line":4,"column":4,"end_line":5,"end_column":0},"operation":"Union","insert_index":-1},"filename":"hello.k","line":4,"column":4,"end_line":5,"end_column":0}]}},"filename":"hello.k","line":2,"column":8,"end_line":5,"end_column":1},"ty":null}},"filename":"hello.k","line":2,"column":0,"end_line":5,"end_column":1}],"comments":[]} +{ + "filename": "hello.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "data2", + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 5 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 5 + } + ], + "value": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": null, + "value": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "key", + "filename": "hello.k", + "line": 3, + "column": 7, + "end_line": 3, + "end_column": 10 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 3, + "column": 7, + "end_line": 3, + "end_column": 10 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"value1\"", + "value": "value1" + } + }, + "filename": "hello.k", + "line": 3, + "column": 13, + "end_line": 3, + "end_column": 21 + }, + "operation": "Override", + "insert_index": -1 + }, + "filename": "hello.k", + "line": 3, + "column": 7, + "end_line": 3, + "end_column": 21 + } + ] + } + }, + "filename": "hello.k", + "line": 3, + "column": 6, + "end_line": 3, + "end_column": 22 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "hello.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 22 + }, + { + "node": { + "key": null, + "value": { + "node": { + "type": "ConfigIfEntry", + "data": { + "if_cond": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 8 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 8 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 123 + } + } + }, + "filename": "hello.k", + "line": 4, + "column": 12, + "end_line": 4, + "end_column": 15 + } + ] + } + }, + "filename": "hello.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 15 + }, + "items": [ + { + "node": { + "key": null, + "value": { + "node": { + "type": "ConfigIfEntry", + "data": { + "if_cond": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "b", + "filename": "hello.k", + "line": 4, + "column": 20, + "end_line": 4, + "end_column": 21 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 4, + "column": 20, + "end_line": 4, + "end_column": 21 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 456 + } + } + }, + "filename": "hello.k", + "line": 4, + "column": 25, + "end_line": 4, + "end_column": 28 + } + ] + } + }, + "filename": "hello.k", + "line": 4, + "column": 20, + "end_line": 4, + "end_column": 28 + }, + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "key", + "filename": "hello.k", + "line": 4, + "column": 30, + "end_line": 4, + "end_column": 33 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 4, + "column": 30, + "end_line": 4, + "end_column": 33 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"value2\"", + "value": "value2" + } + }, + "filename": "hello.k", + "line": 4, + "column": 36, + "end_line": 4, + "end_column": 44 + }, + "operation": "Override", + "insert_index": -1 + }, + "filename": "hello.k", + "line": 4, + "column": 30, + "end_line": 4, + "end_column": 44 + } + ], + "orelse": null + } + }, + "filename": "hello.k", + "line": 4, + "column": 17, + "end_line": 5, + "end_column": 0 + }, + "operation": "Override", + "insert_index": -1 + }, + "filename": "hello.k", + "line": 4, + "column": 17, + "end_line": 5, + "end_column": 0 + } + ], + "orelse": null + } + }, + "filename": "hello.k", + "line": 4, + "column": 4, + "end_line": 5, + "end_column": 0 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "hello.k", + "line": 4, + "column": 4, + "end_line": 5, + "end_column": 0 + } + ] + } + }, + "filename": "hello.k", + "line": 2, + "column": 8, + "end_line": 5, + "end_column": 1 + }, + "ty": null + } + }, + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 5, + "end_column": 1 + } + ], + "comments": [] +} 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 e1c6587b1..34d1114db 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 @@ -3,4 +3,1010 @@ source: parser/src/tests/ast.rs assertion_line: 3 expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\nschema TestBool:\n []\n [str ]: int\n [a: str]: int\n [a: ...str]: int\n [...str]: int\n a: int\n b?: str\n c: int = 0\n d?: str = \"\"\n\n [a]\n [a, b, c]\n [\n 1\n ]\n [\n a\n ]\n [a for a in [1, 2, 3]]\n [\n a for a in [1, 2, 3]\n ]\n\n check:\n a > 1, \"msg\"\n name not None, \"we fail here\"\n \"####)" --- -{"filename":"hello.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Schema":{"doc":null,"name":{"node":"TestBool","filename":"hello.k","line":2,"column":7,"end_line":2,"end_column":15},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[],"ctx":"Load"}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6}]}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6},{"node":{"SchemaAttr":{"doc":"","name":{"node":"a","filename":"hello.k","line":8,"column":4,"end_line":8,"end_column":5},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":8,"column":7,"end_line":8,"end_column":10}}},"filename":"hello.k","line":8,"column":4,"end_line":8,"end_column":10},{"node":{"SchemaAttr":{"doc":"","name":{"node":"b","filename":"hello.k","line":9,"column":4,"end_line":9,"end_column":5},"op":null,"value":null,"is_optional":true,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello.k","line":9,"column":8,"end_line":9,"end_column":11}}},"filename":"hello.k","line":9,"column":4,"end_line":10,"end_column":0},{"node":{"SchemaAttr":{"doc":"","name":{"node":"c","filename":"hello.k","line":10,"column":4,"end_line":10,"end_column":5},"op":{"Aug":"Assign"},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":0}}},"filename":"hello.k","line":10,"column":13,"end_line":10,"end_column":14},"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":10,"column":7,"end_line":10,"end_column":10}}},"filename":"hello.k","line":10,"column":4,"end_line":10,"end_column":14},{"node":{"SchemaAttr":{"doc":"","name":{"node":"d","filename":"hello.k","line":11,"column":4,"end_line":11,"end_column":5},"op":{"Aug":"Assign"},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"\"","value":""}},"filename":"hello.k","line":11,"column":14,"end_line":11,"end_column":16},"is_optional":true,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello.k","line":11,"column":8,"end_line":11,"end_column":11}}},"filename":"hello.k","line":11,"column":4,"end_line":13,"end_column":0},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":13,"column":5,"end_line":13,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":13,"column":5,"end_line":13,"end_column":6}],"ctx":"Load"}},"filename":"hello.k","line":13,"column":4,"end_line":13,"end_column":7}]}},"filename":"hello.k","line":13,"column":4,"end_line":13,"end_column":7},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":14,"column":5,"end_line":14,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":5,"end_line":14,"end_column":6},{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":14,"column":8,"end_line":14,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":8,"end_line":14,"end_column":9},{"node":{"Identifier":{"names":[{"node":"c","filename":"hello.k","line":14,"column":11,"end_line":14,"end_column":12}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":11,"end_line":14,"end_column":12}],"ctx":"Load"}},"filename":"hello.k","line":14,"column":4,"end_line":14,"end_column":13}]}},"filename":"hello.k","line":14,"column":4,"end_line":14,"end_column":13},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":16,"column":8,"end_line":16,"end_column":9}],"ctx":"Load"}},"filename":"hello.k","line":15,"column":4,"end_line":17,"end_column":5}]}},"filename":"hello.k","line":15,"column":4,"end_line":17,"end_column":5},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":19,"column":8,"end_line":19,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":19,"column":8,"end_line":19,"end_column":9}],"ctx":"Load"}},"filename":"hello.k","line":18,"column":4,"end_line":20,"end_column":5}]}},"filename":"hello.k","line":18,"column":4,"end_line":20,"end_column":5},{"node":{"Expr":{"exprs":[{"node":{"ListComp":{"elt":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":21,"column":5,"end_line":21,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":21,"column":5,"end_line":21,"end_column":6},"generators":[{"node":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":21,"column":11,"end_line":21,"end_column":12}],"pkgpath":"","ctx":"Load"},"filename":"hello.k","line":21,"column":11,"end_line":21,"end_column":12}],"iter":{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":21,"column":17,"end_line":21,"end_column":18},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":21,"column":20,"end_line":21,"end_column":21},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":21,"column":23,"end_line":21,"end_column":24}],"ctx":"Load"}},"filename":"hello.k","line":21,"column":16,"end_line":21,"end_column":25},"ifs":[]},"filename":"hello.k","line":21,"column":7,"end_line":21,"end_column":25}]}},"filename":"hello.k","line":21,"column":4,"end_line":21,"end_column":26}]}},"filename":"hello.k","line":21,"column":4,"end_line":21,"end_column":26},{"node":{"Expr":{"exprs":[{"node":{"ListComp":{"elt":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":23,"column":8,"end_line":23,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":23,"column":8,"end_line":23,"end_column":9},"generators":[{"node":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":23,"column":14,"end_line":23,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"hello.k","line":23,"column":14,"end_line":23,"end_column":15}],"iter":{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":23,"column":20,"end_line":23,"end_column":21},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":23,"column":23,"end_line":23,"end_column":24},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":23,"column":26,"end_line":23,"end_column":27}],"ctx":"Load"}},"filename":"hello.k","line":23,"column":19,"end_line":23,"end_column":28},"ifs":[]},"filename":"hello.k","line":23,"column":10,"end_line":24,"end_column":0}]}},"filename":"hello.k","line":22,"column":4,"end_line":24,"end_column":5}]}},"filename":"hello.k","line":22,"column":4,"end_line":24,"end_column":5}],"decorators":[],"checks":[{"node":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":9},"ops":["Gt"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":27,"column":12,"end_line":27,"end_column":13}]}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":13},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"msg\"","value":"msg"}},"filename":"hello.k","line":27,"column":15,"end_line":27,"end_column":20}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":20},{"node":{"test":{"node":{"Identifier":{"names":[{"node":"name","filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12},"if_cond":null,"msg":null},"filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12},{"node":{"test":{"node":{"Unary":{"op":"Not","operand":{"node":{"NameConstantLit":{"value":"None"}},"filename":"hello.k","line":28,"column":17,"end_line":28,"end_column":21}}},"filename":"hello.k","line":28,"column":13,"end_line":28,"end_column":21},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"we fail here\"","value":"we fail here"}},"filename":"hello.k","line":28,"column":23,"end_line":28,"end_column":37}},"filename":"hello.k","line":28,"column":13,"end_line":28,"end_column":37}],"index_signature":{"node":{"key_name":null,"value":null,"any_other":true,"key_ty":{"node":{"Basic":"Str"},"filename":"hello.k","line":7,"column":8,"end_line":7,"end_column":11},"value_ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":7,"column":14,"end_line":7,"end_column":17}},"filename":"hello.k","line":7,"column":4,"end_line":8,"end_column":0}}},"filename":"hello.k","line":2,"column":0,"end_line":29,"end_column":8}],"comments":[]} +{ + "filename": "hello.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Schema", + "data": { + "doc": null, + "name": { + "node": "TestBool", + "filename": "hello.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 15 + }, + "parent_name": null, + "for_host_name": null, + "is_mixin": false, + "is_protocol": false, + "args": null, + "mixins": [], + "body": [ + { + "node": { + "type": "Expr", + "data": { + "exprs": [ + { + "node": { + "type": "List", + "data": { + "elts": [], + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 6 + } + ] + } + }, + "filename": "hello.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 6 + }, + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "a", + "filename": "hello.k", + "line": 8, + "column": 4, + "end_line": 8, + "end_column": 5 + }, + "op": null, + "value": null, + "is_optional": false, + "decorators": [], + "ty": { + "node": { + "type": "Basic", + "data": "Int" + }, + "filename": "hello.k", + "line": 8, + "column": 7, + "end_line": 8, + "end_column": 10 + } + } + }, + "filename": "hello.k", + "line": 8, + "column": 4, + "end_line": 8, + "end_column": 10 + }, + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "b", + "filename": "hello.k", + "line": 9, + "column": 4, + "end_line": 9, + "end_column": 5 + }, + "op": null, + "value": null, + "is_optional": true, + "decorators": [], + "ty": { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "hello.k", + "line": 9, + "column": 8, + "end_line": 9, + "end_column": 11 + } + } + }, + "filename": "hello.k", + "line": 9, + "column": 4, + "end_line": 10, + "end_column": 0 + }, + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "c", + "filename": "hello.k", + "line": 10, + "column": 4, + "end_line": 10, + "end_column": 5 + }, + "op": { + "type": "Aug", + "data": "Assign" + }, + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 0 + } + } + }, + "filename": "hello.k", + "line": 10, + "column": 13, + "end_line": 10, + "end_column": 14 + }, + "is_optional": false, + "decorators": [], + "ty": { + "node": { + "type": "Basic", + "data": "Int" + }, + "filename": "hello.k", + "line": 10, + "column": 7, + "end_line": 10, + "end_column": 10 + } + } + }, + "filename": "hello.k", + "line": 10, + "column": 4, + "end_line": 10, + "end_column": 14 + }, + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "d", + "filename": "hello.k", + "line": 11, + "column": 4, + "end_line": 11, + "end_column": 5 + }, + "op": { + "type": "Aug", + "data": "Assign" + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"\"", + "value": "" + } + }, + "filename": "hello.k", + "line": 11, + "column": 14, + "end_line": 11, + "end_column": 16 + }, + "is_optional": true, + "decorators": [], + "ty": { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "hello.k", + "line": 11, + "column": 8, + "end_line": 11, + "end_column": 11 + } + } + }, + "filename": "hello.k", + "line": 11, + "column": 4, + "end_line": 13, + "end_column": 0 + }, + { + "node": { + "type": "Expr", + "data": { + "exprs": [ + { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 13, + "column": 5, + "end_line": 13, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 13, + "column": 5, + "end_line": 13, + "end_column": 6 + } + ], + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 13, + "column": 4, + "end_line": 13, + "end_column": 7 + } + ] + } + }, + "filename": "hello.k", + "line": 13, + "column": 4, + "end_line": 13, + "end_column": 7 + }, + { + "node": { + "type": "Expr", + "data": { + "exprs": [ + { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 14, + "column": 5, + "end_line": 14, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 14, + "column": 5, + "end_line": 14, + "end_column": 6 + }, + { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "b", + "filename": "hello.k", + "line": 14, + "column": 8, + "end_line": 14, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 14, + "column": 8, + "end_line": 14, + "end_column": 9 + }, + { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "c", + "filename": "hello.k", + "line": 14, + "column": 11, + "end_line": 14, + "end_column": 12 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 14, + "column": 11, + "end_line": 14, + "end_column": 12 + } + ], + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 14, + "column": 4, + "end_line": 14, + "end_column": 13 + } + ] + } + }, + "filename": "hello.k", + "line": 14, + "column": 4, + "end_line": 14, + "end_column": 13 + }, + { + "node": { + "type": "Expr", + "data": { + "exprs": [ + { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "hello.k", + "line": 16, + "column": 8, + "end_line": 16, + "end_column": 9 + } + ], + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 15, + "column": 4, + "end_line": 17, + "end_column": 5 + } + ] + } + }, + "filename": "hello.k", + "line": 15, + "column": 4, + "end_line": 17, + "end_column": 5 + }, + { + "node": { + "type": "Expr", + "data": { + "exprs": [ + { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 19, + "column": 8, + "end_line": 19, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 19, + "column": 8, + "end_line": 19, + "end_column": 9 + } + ], + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 18, + "column": 4, + "end_line": 20, + "end_column": 5 + } + ] + } + }, + "filename": "hello.k", + "line": 18, + "column": 4, + "end_line": 20, + "end_column": 5 + }, + { + "node": { + "type": "Expr", + "data": { + "exprs": [ + { + "node": { + "type": "ListComp", + "data": { + "elt": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 21, + "column": 5, + "end_line": 21, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 21, + "column": 5, + "end_line": 21, + "end_column": 6 + }, + "generators": [ + { + "node": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 21, + "column": 11, + "end_line": 21, + "end_column": 12 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "hello.k", + "line": 21, + "column": 11, + "end_line": 21, + "end_column": 12 + } + ], + "iter": { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "hello.k", + "line": 21, + "column": 17, + "end_line": 21, + "end_column": 18 + }, + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "hello.k", + "line": 21, + "column": 20, + "end_line": 21, + "end_column": 21 + }, + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 3 + } + } + }, + "filename": "hello.k", + "line": 21, + "column": 23, + "end_line": 21, + "end_column": 24 + } + ], + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 21, + "column": 16, + "end_line": 21, + "end_column": 25 + }, + "ifs": [] + }, + "filename": "hello.k", + "line": 21, + "column": 7, + "end_line": 21, + "end_column": 25 + } + ] + } + }, + "filename": "hello.k", + "line": 21, + "column": 4, + "end_line": 21, + "end_column": 26 + } + ] + } + }, + "filename": "hello.k", + "line": 21, + "column": 4, + "end_line": 21, + "end_column": 26 + }, + { + "node": { + "type": "Expr", + "data": { + "exprs": [ + { + "node": { + "type": "ListComp", + "data": { + "elt": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 23, + "column": 8, + "end_line": 23, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 23, + "column": 8, + "end_line": 23, + "end_column": 9 + }, + "generators": [ + { + "node": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 23, + "column": 14, + "end_line": 23, + "end_column": 15 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "hello.k", + "line": 23, + "column": 14, + "end_line": 23, + "end_column": 15 + } + ], + "iter": { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "hello.k", + "line": 23, + "column": 20, + "end_line": 23, + "end_column": 21 + }, + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "hello.k", + "line": 23, + "column": 23, + "end_line": 23, + "end_column": 24 + }, + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 3 + } + } + }, + "filename": "hello.k", + "line": 23, + "column": 26, + "end_line": 23, + "end_column": 27 + } + ], + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 23, + "column": 19, + "end_line": 23, + "end_column": 28 + }, + "ifs": [] + }, + "filename": "hello.k", + "line": 23, + "column": 10, + "end_line": 24, + "end_column": 0 + } + ] + } + }, + "filename": "hello.k", + "line": 22, + "column": 4, + "end_line": 24, + "end_column": 5 + } + ] + } + }, + "filename": "hello.k", + "line": 22, + "column": 4, + "end_line": 24, + "end_column": 5 + } + ], + "decorators": [], + "checks": [ + { + "node": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "hello.k", + "line": 27, + "column": 8, + "end_line": 27, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 27, + "column": 8, + "end_line": 27, + "end_column": 9 + }, + "ops": [ + "Gt" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "hello.k", + "line": 27, + "column": 12, + "end_line": 27, + "end_column": 13 + } + ] + } + }, + "filename": "hello.k", + "line": 27, + "column": 8, + "end_line": 27, + "end_column": 13 + }, + "if_cond": null, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"msg\"", + "value": "msg" + } + }, + "filename": "hello.k", + "line": 27, + "column": 15, + "end_line": 27, + "end_column": 20 + } + }, + "filename": "hello.k", + "line": 27, + "column": 8, + "end_line": 27, + "end_column": 20 + }, + { + "node": { + "test": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "name", + "filename": "hello.k", + "line": 28, + "column": 8, + "end_line": 28, + "end_column": 12 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "hello.k", + "line": 28, + "column": 8, + "end_line": 28, + "end_column": 12 + }, + "if_cond": null, + "msg": null + }, + "filename": "hello.k", + "line": 28, + "column": 8, + "end_line": 28, + "end_column": 12 + }, + { + "node": { + "test": { + "node": { + "type": "Unary", + "data": { + "op": "Not", + "operand": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "None" + } + }, + "filename": "hello.k", + "line": 28, + "column": 17, + "end_line": 28, + "end_column": 21 + } + } + }, + "filename": "hello.k", + "line": 28, + "column": 13, + "end_line": 28, + "end_column": 21 + }, + "if_cond": null, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"we fail here\"", + "value": "we fail here" + } + }, + "filename": "hello.k", + "line": 28, + "column": 23, + "end_line": 28, + "end_column": 37 + } + }, + "filename": "hello.k", + "line": 28, + "column": 13, + "end_line": 28, + "end_column": 37 + } + ], + "index_signature": { + "node": { + "key_name": null, + "value": null, + "any_other": true, + "key_ty": { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "hello.k", + "line": 7, + "column": 8, + "end_line": 7, + "end_column": 11 + }, + "value_ty": { + "node": { + "type": "Basic", + "data": "Int" + }, + "filename": "hello.k", + "line": 7, + "column": 14, + "end_line": 7, + "end_column": 17 + } + }, + "filename": "hello.k", + "line": 7, + "column": 4, + "end_line": 8, + "end_column": 0 + } + } + }, + "filename": "hello.k", + "line": 2, + "column": 0, + "end_line": 29, + "end_column": 8 + } + ], + "comments": [] +} 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 44a58bdad..bd86a14bf 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 @@ -1,5 +1,117 @@ --- source: parser/src/tests/file.rs +assertion_line: 3 expression: "crate::tests::parsing_file_string(\"testdata/assert-01.k\")" --- -{"filename":"assert-01.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-01.k","line":1,"column":7,"end_line":1,"end_column":8},"if_cond":null,"msg":null}},"filename":"assert-01.k","line":1,"column":0,"end_line":1,"end_column":8},{"node":{"Assert":{"test":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assert-01.k","line":2,"column":7,"end_line":2,"end_column":8},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"msg\"","value":"msg"}},"filename":"assert-01.k","line":2,"column":10,"end_line":2,"end_column":15}}},"filename":"assert-01.k","line":2,"column":0,"end_line":2,"end_column":15},{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-01.k","line":3,"column":7,"end_line":3,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-01.k","line":3,"column":0,"end_line":3,"end_column":11}],"comments":[]} +{ + "filename": "assert-01.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-01.k", + "line": 1, + "column": 7, + "end_line": 1, + "end_column": 8 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 8 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "assert-01.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 8 + }, + "if_cond": null, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"msg\"", + "value": "msg" + } + }, + "filename": "assert-01.k", + "line": 2, + "column": 10, + "end_line": 2, + "end_column": 15 + } + } + }, + "filename": "assert-01.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 15 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-01.k", + "line": 3, + "column": 7, + "end_line": 3, + "end_column": 11 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-01.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 11 + } + ], + "comments": [] +} 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 841283bd6..cdffc87a4 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 @@ -3,4 +3,225 @@ source: parser/src/tests/file.rs assertion_line: 4 expression: "crate::tests::parsing_file_string(\"testdata/assert-02.k\")" --- -{"filename":"assert-02.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-02.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":1,"column":0,"end_line":1,"end_column":11},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-02.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-02.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-02.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":2,"column":0,"end_line":2,"end_column":13},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-02.k","line":3,"column":5,"end_line":3,"end_column":16},"ty":null}},"filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-02.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":4,"column":0,"end_line":4,"end_column":24}],"comments":[]} +{ + "filename": "assert-02.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-02.k", + "line": 1, + "column": 7, + "end_line": 1, + "end_column": 11 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-02.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 11 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-02.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 8 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-02.k", + "line": 2, + "column": 12, + "end_line": 2, + "end_column": 13 + } + ] + } + }, + "filename": "assert-02.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 13 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-02.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 13 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_x", + "filename": "assert-02.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 2 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assert-02.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 2 + } + ], + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-02.k", + "line": 3, + "column": 5, + "end_line": 3, + "end_column": 16 + }, + "ty": null + } + }, + "filename": "assert-02.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 16 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-02.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-02.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 9 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-02.k", + "line": 4, + "column": 13, + "end_line": 4, + "end_column": 24 + } + ] + } + }, + "filename": "assert-02.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 24 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-02.k", + "line": 4, + "column": 0, + "end_line": 4, + "end_column": 24 + } + ], + "comments": [] +} 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 91b7acfec..a8957b89a 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 @@ -3,4 +3,309 @@ source: parser/src/tests/file.rs assertion_line: 5 expression: "crate::tests::parsing_file_string(\"testdata/assert-03.k\")" --- -{"filename":"assert-03.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"If":{"body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-03.k","line":2,"column":11,"end_line":2,"end_column":15},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"Error messgae\"","value":"Error messgae"}},"filename":"assert-03.k","line":2,"column":17,"end_line":2,"end_column":32}}},"filename":"assert-03.k","line":2,"column":4,"end_line":2,"end_column":32},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-03.k","line":3,"column":11,"end_line":3,"end_column":12},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-03.k","line":3,"column":16,"end_line":3,"end_column":17}]}},"filename":"assert-03.k","line":3,"column":11,"end_line":3,"end_column":17},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"\"","value":""}},"filename":"assert-03.k","line":3,"column":19,"end_line":3,"end_column":21}}},"filename":"assert-03.k","line":3,"column":4,"end_line":3,"end_column":21},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":6}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-03.k","line":4,"column":9,"end_line":4,"end_column":20},"ty":null}},"filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":13},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-03.k","line":5,"column":17,"end_line":5,"end_column":28}]}},"filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":28},"if_cond":null,"msg":null}},"filename":"assert-03.k","line":5,"column":4,"end_line":5,"end_column":28}],"cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-03.k","line":1,"column":3,"end_line":1,"end_column":7},"orelse":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-03.k","line":7,"column":11,"end_line":7,"end_column":16},"if_cond":null,"msg":null}},"filename":"assert-03.k","line":7,"column":4,"end_line":7,"end_column":16}]}},"filename":"assert-03.k","line":1,"column":0,"end_line":8,"end_column":1}],"comments":[]} +{ + "filename": "assert-03.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-03.k", + "line": 2, + "column": 11, + "end_line": 2, + "end_column": 15 + }, + "if_cond": null, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"Error messgae\"", + "value": "Error messgae" + } + }, + "filename": "assert-03.k", + "line": 2, + "column": 17, + "end_line": 2, + "end_column": 32 + } + } + }, + "filename": "assert-03.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 32 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-03.k", + "line": 3, + "column": 11, + "end_line": 3, + "end_column": 12 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-03.k", + "line": 3, + "column": 16, + "end_line": 3, + "end_column": 17 + } + ] + } + }, + "filename": "assert-03.k", + "line": 3, + "column": 11, + "end_line": 3, + "end_column": 17 + }, + "if_cond": null, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"\"", + "value": "" + } + }, + "filename": "assert-03.k", + "line": 3, + "column": 19, + "end_line": 3, + "end_column": 21 + } + } + }, + "filename": "assert-03.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 21 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_x", + "filename": "assert-03.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assert-03.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 6 + } + ], + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-03.k", + "line": 4, + "column": 9, + "end_line": 4, + "end_column": 20 + }, + "ty": null + } + }, + "filename": "assert-03.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 20 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-03.k", + "line": 5, + "column": 11, + "end_line": 5, + "end_column": 13 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-03.k", + "line": 5, + "column": 11, + "end_line": 5, + "end_column": 13 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-03.k", + "line": 5, + "column": 17, + "end_line": 5, + "end_column": 28 + } + ] + } + }, + "filename": "assert-03.k", + "line": 5, + "column": 11, + "end_line": 5, + "end_column": 28 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-03.k", + "line": 5, + "column": 4, + "end_line": 5, + "end_column": 28 + } + ], + "cond": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-03.k", + "line": 1, + "column": 3, + "end_line": 1, + "end_column": 7 + }, + "orelse": [ + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "False" + } + }, + "filename": "assert-03.k", + "line": 7, + "column": 11, + "end_line": 7, + "end_column": 16 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-03.k", + "line": 7, + "column": 4, + "end_line": 7, + "end_column": 16 + } + ] + } + }, + "filename": "assert-03.k", + "line": 1, + "column": 0, + "end_line": 8, + "end_column": 1 + } + ], + "comments": [] +} 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 e3f2e9054..2e912c805 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 @@ -3,4 +3,274 @@ source: parser/src/tests/file.rs assertion_line: 6 expression: "crate::tests::parsing_file_string(\"testdata/assert-if-0.k\")" --- -{"filename":"assert-if-0.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-0.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-if-0.k","line":1,"column":0,"end_line":1,"end_column":11},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-0.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-0.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-if-0.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-0.k","line":2,"column":17,"end_line":2,"end_column":21},"msg":null}},"filename":"assert-if-0.k","line":2,"column":0,"end_line":2,"end_column":21},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-0.k","line":3,"column":5,"end_line":3,"end_column":16},"ty":null}},"filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-0.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-0.k","line":4,"column":28,"end_line":4,"end_column":30}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-0.k","line":4,"column":28,"end_line":4,"end_column":30},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-0.k","line":4,"column":32,"end_line":4,"end_column":59}}},"filename":"assert-if-0.k","line":4,"column":0,"end_line":4,"end_column":59}],"comments":[]} +{ + "filename": "assert-if-0.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-if-0.k", + "line": 1, + "column": 7, + "end_line": 1, + "end_column": 11 + }, + "if_cond": null, + "msg": null + } + }, + "filename": "assert-if-0.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 11 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-if-0.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 8 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-if-0.k", + "line": 2, + "column": 12, + "end_line": 2, + "end_column": 13 + } + ] + } + }, + "filename": "assert-if-0.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 13 + }, + "if_cond": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-if-0.k", + "line": 2, + "column": 17, + "end_line": 2, + "end_column": 21 + }, + "msg": null + } + }, + "filename": "assert-if-0.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 21 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_x", + "filename": "assert-if-0.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 2 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assert-if-0.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 2 + } + ], + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-if-0.k", + "line": 3, + "column": 5, + "end_line": 3, + "end_column": 16 + }, + "ty": null + } + }, + "filename": "assert-if-0.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 16 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-if-0.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-if-0.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 9 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-if-0.k", + "line": 4, + "column": 13, + "end_line": 4, + "end_column": 24 + } + ] + } + }, + "filename": "assert-if-0.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 24 + }, + "if_cond": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-if-0.k", + "line": 4, + "column": 28, + "end_line": 4, + "end_column": 30 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-if-0.k", + "line": 4, + "column": 28, + "end_line": 4, + "end_column": 30 + }, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"_x need to be 'good case'\"", + "value": "_x need to be 'good case'" + } + }, + "filename": "assert-if-0.k", + "line": 4, + "column": 32, + "end_line": 4, + "end_column": 59 + } + } + }, + "filename": "assert-if-0.k", + "line": 4, + "column": 0, + "end_line": 4, + "end_column": 59 + } + ], + "comments": [] +} 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 84ea08c69..6151e0d55 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 @@ -3,4 +3,299 @@ source: parser/src/tests/file.rs assertion_line: 7 expression: "crate::tests::parsing_file_string(\"testdata/assert-if-1.k\")" --- -{"filename":"assert-if-1.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-1.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-1.k","line":1,"column":15,"end_line":1,"end_column":20},"msg":null}},"filename":"assert-if-1.k","line":1,"column":0,"end_line":1,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-1.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-1.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-if-1.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-1.k","line":2,"column":17,"end_line":2,"end_column":22},"msg":null}},"filename":"assert-if-1.k","line":2,"column":0,"end_line":2,"end_column":22},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-1.k","line":3,"column":5,"end_line":3,"end_column":16},"ty":null}},"filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-1.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":{"node":{"Unary":{"op":"Not","operand":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-1.k","line":4,"column":32,"end_line":4,"end_column":34}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-1.k","line":4,"column":32,"end_line":4,"end_column":34}}},"filename":"assert-if-1.k","line":4,"column":28,"end_line":4,"end_column":34},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-1.k","line":4,"column":36,"end_line":4,"end_column":63}}},"filename":"assert-if-1.k","line":4,"column":0,"end_line":4,"end_column":63}],"comments":[]} +{ + "filename": "assert-if-1.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-if-1.k", + "line": 1, + "column": 7, + "end_line": 1, + "end_column": 11 + }, + "if_cond": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "False" + } + }, + "filename": "assert-if-1.k", + "line": 1, + "column": 15, + "end_line": 1, + "end_column": 20 + }, + "msg": null + } + }, + "filename": "assert-if-1.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 20 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-if-1.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 8 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-if-1.k", + "line": 2, + "column": 12, + "end_line": 2, + "end_column": 13 + } + ] + } + }, + "filename": "assert-if-1.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 13 + }, + "if_cond": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "False" + } + }, + "filename": "assert-if-1.k", + "line": 2, + "column": 17, + "end_line": 2, + "end_column": 22 + }, + "msg": null + } + }, + "filename": "assert-if-1.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 22 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_x", + "filename": "assert-if-1.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 2 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assert-if-1.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 2 + } + ], + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-if-1.k", + "line": 3, + "column": 5, + "end_line": 3, + "end_column": 16 + }, + "ty": null + } + }, + "filename": "assert-if-1.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 16 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-if-1.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 9 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-if-1.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 9 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-if-1.k", + "line": 4, + "column": 13, + "end_line": 4, + "end_column": 24 + } + ] + } + }, + "filename": "assert-if-1.k", + "line": 4, + "column": 7, + "end_line": 4, + "end_column": 24 + }, + "if_cond": { + "node": { + "type": "Unary", + "data": { + "op": "Not", + "operand": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-if-1.k", + "line": 4, + "column": 32, + "end_line": 4, + "end_column": 34 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-if-1.k", + "line": 4, + "column": 32, + "end_line": 4, + "end_column": 34 + } + } + }, + "filename": "assert-if-1.k", + "line": 4, + "column": 28, + "end_line": 4, + "end_column": 34 + }, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"_x need to be 'good case'\"", + "value": "_x need to be 'good case'" + } + }, + "filename": "assert-if-1.k", + "line": 4, + "column": 36, + "end_line": 4, + "end_column": 63 + } + } + }, + "filename": "assert-if-1.k", + "line": 4, + "column": 0, + "end_line": 4, + "end_column": 63 + } + ], + "comments": [] +} 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 c1394a9cb..62daddc4d 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 @@ -3,4 +3,415 @@ source: parser/src/tests/file.rs assertion_line: 8 expression: "crate::tests::parsing_file_string(\"testdata/assert-if-2.k\")" --- -{"filename":"assert-if-2.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Schema":{"doc":null,"name":{"node":"Data","filename":"assert-if-2.k","line":1,"column":7,"end_line":1,"end_column":11},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-2.k","line":2,"column":11,"end_line":2,"end_column":15},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-2.k","line":2,"column":19,"end_line":2,"end_column":24},"msg":null}},"filename":"assert-if-2.k","line":2,"column":4,"end_line":2,"end_column":24},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-2.k","line":3,"column":11,"end_line":3,"end_column":12},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-2.k","line":3,"column":16,"end_line":3,"end_column":17}]}},"filename":"assert-if-2.k","line":3,"column":11,"end_line":3,"end_column":17},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-2.k","line":3,"column":21,"end_line":3,"end_column":26},"msg":null}},"filename":"assert-if-2.k","line":3,"column":4,"end_line":3,"end_column":26},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":6}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-2.k","line":4,"column":9,"end_line":4,"end_column":20},"ty":null}},"filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":13},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-2.k","line":5,"column":17,"end_line":5,"end_column":28}]}},"filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":28},"if_cond":{"node":{"Unary":{"op":"Not","operand":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-2.k","line":5,"column":36,"end_line":5,"end_column":38}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-2.k","line":5,"column":36,"end_line":5,"end_column":38}}},"filename":"assert-if-2.k","line":5,"column":32,"end_line":5,"end_column":38},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-2.k","line":5,"column":40,"end_line":5,"end_column":67}}},"filename":"assert-if-2.k","line":5,"column":4,"end_line":5,"end_column":67}],"decorators":[],"checks":[],"index_signature":null}},"filename":"assert-if-2.k","line":1,"column":0,"end_line":7,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"data","filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":4}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":4}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Data","filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":11}],"pkgpath":"","ctx":"Load"},"filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":11},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[]}},"filename":"assert-if-2.k","line":7,"column":12,"end_line":7,"end_column":14}}},"filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":14},"ty":null}},"filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":14}],"comments":[]} +{ + "filename": "assert-if-2.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Schema", + "data": { + "doc": null, + "name": { + "node": "Data", + "filename": "assert-if-2.k", + "line": 1, + "column": 7, + "end_line": 1, + "end_column": 11 + }, + "parent_name": null, + "for_host_name": null, + "is_mixin": false, + "is_protocol": false, + "args": null, + "mixins": [], + "body": [ + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "assert-if-2.k", + "line": 2, + "column": 11, + "end_line": 2, + "end_column": 15 + }, + "if_cond": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "False" + } + }, + "filename": "assert-if-2.k", + "line": 2, + "column": 19, + "end_line": 2, + "end_column": 24 + }, + "msg": null + } + }, + "filename": "assert-if-2.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 24 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-if-2.k", + "line": 3, + "column": 11, + "end_line": 3, + "end_column": 12 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assert-if-2.k", + "line": 3, + "column": 16, + "end_line": 3, + "end_column": 17 + } + ] + } + }, + "filename": "assert-if-2.k", + "line": 3, + "column": 11, + "end_line": 3, + "end_column": 17 + }, + "if_cond": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "False" + } + }, + "filename": "assert-if-2.k", + "line": 3, + "column": 21, + "end_line": 3, + "end_column": 26 + }, + "msg": null + } + }, + "filename": "assert-if-2.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 26 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_x", + "filename": "assert-if-2.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assert-if-2.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 6 + } + ], + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-if-2.k", + "line": 4, + "column": 9, + "end_line": 4, + "end_column": 20 + }, + "ty": null + } + }, + "filename": "assert-if-2.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 20 + }, + { + "node": { + "type": "Assert", + "data": { + "test": { + "node": { + "type": "Compare", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-if-2.k", + "line": 5, + "column": 11, + "end_line": 5, + "end_column": 13 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-if-2.k", + "line": 5, + "column": 11, + "end_line": 5, + "end_column": 13 + }, + "ops": [ + "Eq" + ], + "comparators": [ + { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"good case\"", + "value": "good case" + } + }, + "filename": "assert-if-2.k", + "line": 5, + "column": 17, + "end_line": 5, + "end_column": 28 + } + ] + } + }, + "filename": "assert-if-2.k", + "line": 5, + "column": 11, + "end_line": 5, + "end_column": 28 + }, + "if_cond": { + "node": { + "type": "Unary", + "data": { + "op": "Not", + "operand": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_x", + "filename": "assert-if-2.k", + "line": 5, + "column": 36, + "end_line": 5, + "end_column": 38 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "assert-if-2.k", + "line": 5, + "column": 36, + "end_line": 5, + "end_column": 38 + } + } + }, + "filename": "assert-if-2.k", + "line": 5, + "column": 32, + "end_line": 5, + "end_column": 38 + }, + "msg": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"_x need to be 'good case'\"", + "value": "_x need to be 'good case'" + } + }, + "filename": "assert-if-2.k", + "line": 5, + "column": 40, + "end_line": 5, + "end_column": 67 + } + } + }, + "filename": "assert-if-2.k", + "line": 5, + "column": 4, + "end_line": 5, + "end_column": 67 + } + ], + "decorators": [], + "checks": [], + "index_signature": null + } + }, + "filename": "assert-if-2.k", + "line": 1, + "column": 0, + "end_line": 7, + "end_column": 0 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "data", + "filename": "assert-if-2.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 4 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assert-if-2.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 4 + } + ], + "value": { + "node": { + "type": "Schema", + "data": { + "name": { + "node": { + "names": [ + { + "node": "Data", + "filename": "assert-if-2.k", + "line": 7, + "column": 7, + "end_line": 7, + "end_column": 11 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "assert-if-2.k", + "line": 7, + "column": 7, + "end_line": 7, + "end_column": 11 + }, + "args": [], + "kwargs": [], + "config": { + "node": { + "type": "Config", + "data": { + "items": [] + } + }, + "filename": "assert-if-2.k", + "line": 7, + "column": 12, + "end_line": 7, + "end_column": 14 + } + } + }, + "filename": "assert-if-2.k", + "line": 7, + "column": 7, + "end_line": 7, + "end_column": 14 + }, + "ty": null + } + }, + "filename": "assert-if-2.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 14 + } + ], + "comments": [] +} 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 86eebd97d..a6c13090b 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 @@ -3,4 +3,270 @@ source: parser/src/tests/file.rs assertion_line: 9 expression: "crate::tests::parsing_file_string(\"testdata/assign-01.k\")" --- -{"filename":"assign-01.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assign-01.k","line":1,"column":2,"end_line":1,"end_column":3},"ty":null}},"filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":3},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":1}],"value":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assign-01.k","line":2,"column":4,"end_line":2,"end_column":5},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":2,"column":8,"end_line":2,"end_column":9}}},"filename":"assign-01.k","line":2,"column":4,"end_line":2,"end_column":9},"ty":null}},"filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":9},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"c","filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":3,"column":4,"end_line":3,"end_column":5},"op":{"Bin":"Add"},"right":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":3,"column":8,"end_line":3,"end_column":9},"op":{"Bin":"Mul"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"assign-01.k","line":3,"column":10,"end_line":3,"end_column":11}}},"filename":"assign-01.k","line":3,"column":8,"end_line":3,"end_column":11}}},"filename":"assign-01.k","line":3,"column":4,"end_line":3,"end_column":11},"ty":null}},"filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":11}],"comments":[]} +{ + "filename": "assign-01.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "assign-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assign-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assign-01.k", + "line": 1, + "column": 2, + "end_line": 1, + "end_column": 3 + }, + "ty": null + } + }, + "filename": "assign-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 3 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "b", + "filename": "assign-01.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assign-01.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "Binary", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "assign-01.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 5 + }, + "op": { + "type": "Bin", + "data": "Add" + }, + "right": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "assign-01.k", + "line": 2, + "column": 8, + "end_line": 2, + "end_column": 9 + } + } + }, + "filename": "assign-01.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 9 + }, + "ty": null + } + }, + "filename": "assign-01.k", + "line": 2, + "column": 0, + "end_line": 2, + "end_column": 9 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "c", + "filename": "assign-01.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "assign-01.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "Binary", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "assign-01.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 5 + }, + "op": { + "type": "Bin", + "data": "Add" + }, + "right": { + "node": { + "type": "Binary", + "data": { + "left": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "assign-01.k", + "line": 3, + "column": 8, + "end_line": 3, + "end_column": 9 + }, + "op": { + "type": "Bin", + "data": "Mul" + }, + "right": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 3 + } + } + }, + "filename": "assign-01.k", + "line": 3, + "column": 10, + "end_line": 3, + "end_column": 11 + } + } + }, + "filename": "assign-01.k", + "line": 3, + "column": 8, + "end_line": 3, + "end_column": 11 + } + } + }, + "filename": "assign-01.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 11 + }, + "ty": null + } + }, + "filename": "assign-01.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 11 + } + ], + "comments": [] +} 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 76962bf05..ea80bf9d6 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 @@ -3,4 +3,61 @@ source: parser/src/tests/file.rs assertion_line: 10 expression: "crate::tests::parsing_file_string(\"testdata/config_expr-01.k\")" --- -{"filename":"config_expr-01.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-01.k","line":1,"column":0,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-01.k","line":1,"column":0,"end_line":1,"end_column":6}],"value":{"node":{"Config":{"items":[]}},"filename":"config_expr-01.k","line":1,"column":9,"end_line":2,"end_column":1},"ty":null}},"filename":"config_expr-01.k","line":1,"column":0,"end_line":2,"end_column":1}],"comments":[]} +{ + "filename": "config_expr-01.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "config", + "filename": "config_expr-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "config_expr-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 6 + } + ], + "value": { + "node": { + "type": "Config", + "data": { + "items": [] + } + }, + "filename": "config_expr-01.k", + "line": 1, + "column": 9, + "end_line": 2, + "end_column": 1 + }, + "ty": null + } + }, + "filename": "config_expr-01.k", + "line": 1, + "column": 0, + "end_line": 2, + "end_column": 1 + } + ], + "comments": [] +} 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 5c560d1fc..ad1df6d7b 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 @@ -3,4 +3,166 @@ source: parser/src/tests/file.rs assertion_line: 11 expression: "crate::tests::parsing_file_string(\"testdata/config_expr-02.k\")" --- -{"filename":"config_expr-02.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-02.k","line":1,"column":0,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-02.k","line":1,"column":0,"end_line":1,"end_column":6}],"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"k1","filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":6},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":111}}},"filename":"config_expr-02.k","line":2,"column":9,"end_line":2,"end_column":12},"operation":"Override","insert_index":-1},"filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":12},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"k2","filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":6},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":222}}},"filename":"config_expr-02.k","line":3,"column":9,"end_line":3,"end_column":12},"operation":"Override","insert_index":-1},"filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":12}]}},"filename":"config_expr-02.k","line":1,"column":9,"end_line":4,"end_column":1},"ty":null}},"filename":"config_expr-02.k","line":1,"column":0,"end_line":4,"end_column":1}],"comments":[]} +{ + "filename": "config_expr-02.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "config", + "filename": "config_expr-02.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "config_expr-02.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 6 + } + ], + "value": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "k1", + "filename": "config_expr-02.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-02.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 6 + }, + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 111 + } + } + }, + "filename": "config_expr-02.k", + "line": 2, + "column": 9, + "end_line": 2, + "end_column": 12 + }, + "operation": "Override", + "insert_index": -1 + }, + "filename": "config_expr-02.k", + "line": 2, + "column": 4, + "end_line": 2, + "end_column": 12 + }, + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "k2", + "filename": "config_expr-02.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-02.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 6 + }, + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 222 + } + } + }, + "filename": "config_expr-02.k", + "line": 3, + "column": 9, + "end_line": 3, + "end_column": 12 + }, + "operation": "Override", + "insert_index": -1 + }, + "filename": "config_expr-02.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 12 + } + ] + } + }, + "filename": "config_expr-02.k", + "line": 1, + "column": 9, + "end_line": 4, + "end_column": 1 + }, + "ty": null + } + }, + "filename": "config_expr-02.k", + "line": 1, + "column": 0, + "end_line": 4, + "end_column": 1 + } + ], + "comments": [] +} 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 d9e5b1cad..b0662e8c1 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 @@ -3,4 +3,499 @@ source: parser/src/tests/file.rs assertion_line: 12 expression: "crate::tests::parsing_file_string(\"testdata/config_expr-03.k\")" --- -{"filename":"config_expr-03.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-03.k","line":3,"column":0,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-03.k","line":3,"column":0,"end_line":3,"end_column":6}],"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-03.k","line":4,"column":4,"end_line":4,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":4,"column":4,"end_line":4,"end_column":8},"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-03.k","line":5,"column":8,"end_line":5,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":5,"column":8,"end_line":5,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_1\"","value":"ENV_1"}},"filename":"config_expr-03.k","line":6,"column":19,"end_line":6,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"1\"","value":"1"}},"filename":"config_expr-03.k","line":6,"column":35,"end_line":6,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":38}]}},"filename":"config_expr-03.k","line":6,"column":12,"end_line":6,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-03.k","line":5,"column":13,"end_line":7,"end_column":9},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":5,"column":8,"end_line":7,"end_column":9}]}},"filename":"config_expr-03.k","line":4,"column":10,"end_line":8,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":4,"column":4,"end_line":8,"end_column":5},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-03.k","line":9,"column":4,"end_line":9,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":9,"column":4,"end_line":9,"end_column":8},"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-03.k","line":10,"column":8,"end_line":10,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":10,"column":8,"end_line":10,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_2\"","value":"ENV_2"}},"filename":"config_expr-03.k","line":11,"column":19,"end_line":11,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"2\"","value":"2"}},"filename":"config_expr-03.k","line":11,"column":35,"end_line":11,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":38}]}},"filename":"config_expr-03.k","line":11,"column":12,"end_line":11,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-03.k","line":10,"column":15,"end_line":12,"end_column":9},"operation":"Insert","insert_index":-1},"filename":"config_expr-03.k","line":10,"column":8,"end_line":12,"end_column":9}]}},"filename":"config_expr-03.k","line":9,"column":10,"end_line":13,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":9,"column":4,"end_line":13,"end_column":5}]}},"filename":"config_expr-03.k","line":3,"column":9,"end_line":14,"end_column":1},"ty":null}},"filename":"config_expr-03.k","line":3,"column":0,"end_line":14,"end_column":1}],"comments":[{"node":{"text":"# test/grammar/attr_operator/config_inside/insert/dict_0/main.k"},"filename":"config_expr-03.k","line":1,"column":0,"end_line":1,"end_column":63}]} +{ + "filename": "config_expr-03.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "config", + "filename": "config_expr-03.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "config_expr-03.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 6 + } + ], + "value": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "main", + "filename": "config_expr-03.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 8 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 8 + }, + "value": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "env", + "filename": "config_expr-03.k", + "line": 5, + "column": 8, + "end_line": 5, + "end_column": 11 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 5, + "column": 8, + "end_line": 5, + "end_column": 11 + }, + "value": { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "name", + "filename": "config_expr-03.k", + "line": 6, + "column": 13, + "end_line": 6, + "end_column": 17 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 6, + "column": 13, + "end_line": 6, + "end_column": 17 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"ENV_1\"", + "value": "ENV_1" + } + }, + "filename": "config_expr-03.k", + "line": 6, + "column": 19, + "end_line": 6, + "end_column": 26 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 6, + "column": 13, + "end_line": 6, + "end_column": 26 + }, + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "value", + "filename": "config_expr-03.k", + "line": 6, + "column": 28, + "end_line": 6, + "end_column": 33 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 6, + "column": 28, + "end_line": 6, + "end_column": 33 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"1\"", + "value": "1" + } + }, + "filename": "config_expr-03.k", + "line": 6, + "column": 35, + "end_line": 6, + "end_column": 38 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 6, + "column": 28, + "end_line": 6, + "end_column": 38 + } + ] + } + }, + "filename": "config_expr-03.k", + "line": 6, + "column": 12, + "end_line": 6, + "end_column": 39 + } + ], + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 5, + "column": 13, + "end_line": 7, + "end_column": 9 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 5, + "column": 8, + "end_line": 7, + "end_column": 9 + } + ] + } + }, + "filename": "config_expr-03.k", + "line": 4, + "column": 10, + "end_line": 8, + "end_column": 5 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 4, + "column": 4, + "end_line": 8, + "end_column": 5 + }, + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "main", + "filename": "config_expr-03.k", + "line": 9, + "column": 4, + "end_line": 9, + "end_column": 8 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 9, + "column": 4, + "end_line": 9, + "end_column": 8 + }, + "value": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "env", + "filename": "config_expr-03.k", + "line": 10, + "column": 8, + "end_line": 10, + "end_column": 11 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 10, + "column": 8, + "end_line": 10, + "end_column": 11 + }, + "value": { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "name", + "filename": "config_expr-03.k", + "line": 11, + "column": 13, + "end_line": 11, + "end_column": 17 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 11, + "column": 13, + "end_line": 11, + "end_column": 17 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"ENV_2\"", + "value": "ENV_2" + } + }, + "filename": "config_expr-03.k", + "line": 11, + "column": 19, + "end_line": 11, + "end_column": 26 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 11, + "column": 13, + "end_line": 11, + "end_column": 26 + }, + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "value", + "filename": "config_expr-03.k", + "line": 11, + "column": 28, + "end_line": 11, + "end_column": 33 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 11, + "column": 28, + "end_line": 11, + "end_column": 33 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"2\"", + "value": "2" + } + }, + "filename": "config_expr-03.k", + "line": 11, + "column": 35, + "end_line": 11, + "end_column": 38 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 11, + "column": 28, + "end_line": 11, + "end_column": 38 + } + ] + } + }, + "filename": "config_expr-03.k", + "line": 11, + "column": 12, + "end_line": 11, + "end_column": 39 + } + ], + "ctx": "Load" + } + }, + "filename": "config_expr-03.k", + "line": 10, + "column": 15, + "end_line": 12, + "end_column": 9 + }, + "operation": "Insert", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 10, + "column": 8, + "end_line": 12, + "end_column": 9 + } + ] + } + }, + "filename": "config_expr-03.k", + "line": 9, + "column": 10, + "end_line": 13, + "end_column": 5 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-03.k", + "line": 9, + "column": 4, + "end_line": 13, + "end_column": 5 + } + ] + } + }, + "filename": "config_expr-03.k", + "line": 3, + "column": 9, + "end_line": 14, + "end_column": 1 + }, + "ty": null + } + }, + "filename": "config_expr-03.k", + "line": 3, + "column": 0, + "end_line": 14, + "end_column": 1 + } + ], + "comments": [ + { + "node": { + "text": "# test/grammar/attr_operator/config_inside/insert/dict_0/main.k" + }, + "filename": "config_expr-03.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 63 + } + ] +} 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 ec599ac51..0b1ea1383 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 @@ -3,4 +3,942 @@ source: parser/src/tests/file.rs assertion_line: 13 expression: "crate::tests::parsing_file_string(\"testdata/config_expr-04.k\")" --- -{"filename":"config_expr-04.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Schema":{"doc":null,"name":{"node":"Env","filename":"config_expr-04.k","line":3,"column":7,"end_line":3,"end_column":10},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"name","filename":"config_expr-04.k","line":4,"column":4,"end_line":4,"end_column":8},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"config_expr-04.k","line":4,"column":10,"end_line":4,"end_column":13}}},"filename":"config_expr-04.k","line":4,"column":4,"end_line":4,"end_column":13},{"node":{"SchemaAttr":{"doc":"","name":{"node":"value","filename":"config_expr-04.k","line":5,"column":4,"end_line":5,"end_column":9},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"config_expr-04.k","line":5,"column":11,"end_line":5,"end_column":14}}},"filename":"config_expr-04.k","line":5,"column":4,"end_line":5,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":3,"column":0,"end_line":7,"end_column":0},{"node":{"Schema":{"doc":null,"name":{"node":"Main","filename":"config_expr-04.k","line":7,"column":7,"end_line":7,"end_column":11},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"env","filename":"config_expr-04.k","line":8,"column":4,"end_line":8,"end_column":7},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"List":{"inner_type":{"node":{"Named":{"names":[{"node":"Env","filename":"config_expr-04.k","line":8,"column":10,"end_line":8,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":8,"column":10,"end_line":8,"end_column":13}}},"filename":"config_expr-04.k","line":8,"column":9,"end_line":8,"end_column":14}}},"filename":"config_expr-04.k","line":8,"column":4,"end_line":8,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":7,"column":0,"end_line":10,"end_column":0},{"node":{"Schema":{"doc":null,"name":{"node":"Config","filename":"config_expr-04.k","line":10,"column":7,"end_line":10,"end_column":13},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"main","filename":"config_expr-04.k","line":11,"column":4,"end_line":11,"end_column":8},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Named":{"names":[{"node":"Main","filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14}}},"filename":"config_expr-04.k","line":11,"column":4,"end_line":11,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":10,"column":0,"end_line":13,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_main","filename":"config_expr-04.k","line":13,"column":0,"end_line":13,"end_column":5}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-04.k","line":13,"column":0,"end_line":13,"end_column":5}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Main","filename":"config_expr-04.k","line":13,"column":8,"end_line":13,"end_column":12}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":13,"column":8,"end_line":13,"end_column":12},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-04.k","line":14,"column":4,"end_line":14,"end_column":7}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":14,"column":4,"end_line":14,"end_column":7},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":13},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_1\"","value":"ENV_1"}},"filename":"config_expr-04.k","line":15,"column":15,"end_line":15,"end_column":22},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":22},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":29}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":29},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"1\"","value":"1"}},"filename":"config_expr-04.k","line":15,"column":31,"end_line":15,"end_column":34},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":34}]}},"filename":"config_expr-04.k","line":15,"column":8,"end_line":15,"end_column":35}],"ctx":"Load"}},"filename":"config_expr-04.k","line":14,"column":9,"end_line":16,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":14,"column":4,"end_line":16,"end_column":5}]}},"filename":"config_expr-04.k","line":13,"column":13,"end_line":17,"end_column":1}}},"filename":"config_expr-04.k","line":13,"column":8,"end_line":17,"end_column":1},"ty":null}},"filename":"config_expr-04.k","line":13,"column":0,"end_line":17,"end_column":1},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-04.k","line":19,"column":0,"end_line":19,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-04.k","line":19,"column":0,"end_line":19,"end_column":6}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Config","filename":"config_expr-04.k","line":19,"column":9,"end_line":19,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":19,"column":9,"end_line":19,"end_column":15},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":8},"value":{"node":{"Identifier":{"names":[{"node":"_main","filename":"config_expr-04.k","line":20,"column":10,"end_line":20,"end_column":15}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":20,"column":10,"end_line":20,"end_column":15},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":15},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-04.k","line":21,"column":4,"end_line":21,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":21,"column":4,"end_line":21,"end_column":8},"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Main","filename":"config_expr-04.k","line":21,"column":10,"end_line":21,"end_column":14}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":21,"column":10,"end_line":21,"end_column":14},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-04.k","line":22,"column":8,"end_line":22,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":22,"column":8,"end_line":22,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_2\"","value":"ENV_2"}},"filename":"config_expr-04.k","line":23,"column":19,"end_line":23,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"2\"","value":"2"}},"filename":"config_expr-04.k","line":23,"column":35,"end_line":23,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":38}]}},"filename":"config_expr-04.k","line":23,"column":12,"end_line":23,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-04.k","line":22,"column":15,"end_line":24,"end_column":9},"operation":"Insert","insert_index":-1},"filename":"config_expr-04.k","line":22,"column":8,"end_line":24,"end_column":9}]}},"filename":"config_expr-04.k","line":21,"column":15,"end_line":25,"end_column":5}}},"filename":"config_expr-04.k","line":21,"column":10,"end_line":25,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":21,"column":4,"end_line":25,"end_column":5}]}},"filename":"config_expr-04.k","line":19,"column":16,"end_line":26,"end_column":1}}},"filename":"config_expr-04.k","line":19,"column":9,"end_line":26,"end_column":1},"ty":null}},"filename":"config_expr-04.k","line":19,"column":0,"end_line":26,"end_column":1}],"comments":[{"node":{"text":"# test/grammar/attr_operator/config_inside/insert/schema_0/main.k"},"filename":"config_expr-04.k","line":1,"column":0,"end_line":1,"end_column":65}]} +{ + "filename": "config_expr-04.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Schema", + "data": { + "doc": null, + "name": { + "node": "Env", + "filename": "config_expr-04.k", + "line": 3, + "column": 7, + "end_line": 3, + "end_column": 10 + }, + "parent_name": null, + "for_host_name": null, + "is_mixin": false, + "is_protocol": false, + "args": null, + "mixins": [], + "body": [ + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "name", + "filename": "config_expr-04.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 8 + }, + "op": null, + "value": null, + "is_optional": false, + "decorators": [], + "ty": { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "config_expr-04.k", + "line": 4, + "column": 10, + "end_line": 4, + "end_column": 13 + } + } + }, + "filename": "config_expr-04.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 13 + }, + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "value", + "filename": "config_expr-04.k", + "line": 5, + "column": 4, + "end_line": 5, + "end_column": 9 + }, + "op": null, + "value": null, + "is_optional": false, + "decorators": [], + "ty": { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "config_expr-04.k", + "line": 5, + "column": 11, + "end_line": 5, + "end_column": 14 + } + } + }, + "filename": "config_expr-04.k", + "line": 5, + "column": 4, + "end_line": 5, + "end_column": 14 + } + ], + "decorators": [], + "checks": [], + "index_signature": null + } + }, + "filename": "config_expr-04.k", + "line": 3, + "column": 0, + "end_line": 7, + "end_column": 0 + }, + { + "node": { + "type": "Schema", + "data": { + "doc": null, + "name": { + "node": "Main", + "filename": "config_expr-04.k", + "line": 7, + "column": 7, + "end_line": 7, + "end_column": 11 + }, + "parent_name": null, + "for_host_name": null, + "is_mixin": false, + "is_protocol": false, + "args": null, + "mixins": [], + "body": [ + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "env", + "filename": "config_expr-04.k", + "line": 8, + "column": 4, + "end_line": 8, + "end_column": 7 + }, + "op": null, + "value": null, + "is_optional": false, + "decorators": [], + "ty": { + "node": { + "type": "List", + "data": { + "inner_type": { + "node": { + "type": "Named", + "data": { + "names": [ + { + "node": "Env", + "filename": "config_expr-04.k", + "line": 8, + "column": 10, + "end_line": 8, + "end_column": 13 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 8, + "column": 10, + "end_line": 8, + "end_column": 13 + } + } + }, + "filename": "config_expr-04.k", + "line": 8, + "column": 9, + "end_line": 8, + "end_column": 14 + } + } + }, + "filename": "config_expr-04.k", + "line": 8, + "column": 4, + "end_line": 8, + "end_column": 14 + } + ], + "decorators": [], + "checks": [], + "index_signature": null + } + }, + "filename": "config_expr-04.k", + "line": 7, + "column": 0, + "end_line": 10, + "end_column": 0 + }, + { + "node": { + "type": "Schema", + "data": { + "doc": null, + "name": { + "node": "Config", + "filename": "config_expr-04.k", + "line": 10, + "column": 7, + "end_line": 10, + "end_column": 13 + }, + "parent_name": null, + "for_host_name": null, + "is_mixin": false, + "is_protocol": false, + "args": null, + "mixins": [], + "body": [ + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "main", + "filename": "config_expr-04.k", + "line": 11, + "column": 4, + "end_line": 11, + "end_column": 8 + }, + "op": null, + "value": null, + "is_optional": false, + "decorators": [], + "ty": { + "node": { + "type": "Named", + "data": { + "names": [ + { + "node": "Main", + "filename": "config_expr-04.k", + "line": 11, + "column": 10, + "end_line": 11, + "end_column": 14 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 11, + "column": 10, + "end_line": 11, + "end_column": 14 + } + } + }, + "filename": "config_expr-04.k", + "line": 11, + "column": 4, + "end_line": 11, + "end_column": 14 + } + ], + "decorators": [], + "checks": [], + "index_signature": null + } + }, + "filename": "config_expr-04.k", + "line": 10, + "column": 0, + "end_line": 13, + "end_column": 0 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "_main", + "filename": "config_expr-04.k", + "line": 13, + "column": 0, + "end_line": 13, + "end_column": 5 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "config_expr-04.k", + "line": 13, + "column": 0, + "end_line": 13, + "end_column": 5 + } + ], + "value": { + "node": { + "type": "Schema", + "data": { + "name": { + "node": { + "names": [ + { + "node": "Main", + "filename": "config_expr-04.k", + "line": 13, + "column": 8, + "end_line": 13, + "end_column": 12 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "config_expr-04.k", + "line": 13, + "column": 8, + "end_line": 13, + "end_column": 12 + }, + "args": [], + "kwargs": [], + "config": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "env", + "filename": "config_expr-04.k", + "line": 14, + "column": 4, + "end_line": 14, + "end_column": 7 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 14, + "column": 4, + "end_line": 14, + "end_column": 7 + }, + "value": { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "name", + "filename": "config_expr-04.k", + "line": 15, + "column": 9, + "end_line": 15, + "end_column": 13 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 15, + "column": 9, + "end_line": 15, + "end_column": 13 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"ENV_1\"", + "value": "ENV_1" + } + }, + "filename": "config_expr-04.k", + "line": 15, + "column": 15, + "end_line": 15, + "end_column": 22 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 15, + "column": 9, + "end_line": 15, + "end_column": 22 + }, + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "value", + "filename": "config_expr-04.k", + "line": 15, + "column": 24, + "end_line": 15, + "end_column": 29 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 15, + "column": 24, + "end_line": 15, + "end_column": 29 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"1\"", + "value": "1" + } + }, + "filename": "config_expr-04.k", + "line": 15, + "column": 31, + "end_line": 15, + "end_column": 34 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 15, + "column": 24, + "end_line": 15, + "end_column": 34 + } + ] + } + }, + "filename": "config_expr-04.k", + "line": 15, + "column": 8, + "end_line": 15, + "end_column": 35 + } + ], + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 14, + "column": 9, + "end_line": 16, + "end_column": 5 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 14, + "column": 4, + "end_line": 16, + "end_column": 5 + } + ] + } + }, + "filename": "config_expr-04.k", + "line": 13, + "column": 13, + "end_line": 17, + "end_column": 1 + } + } + }, + "filename": "config_expr-04.k", + "line": 13, + "column": 8, + "end_line": 17, + "end_column": 1 + }, + "ty": null + } + }, + "filename": "config_expr-04.k", + "line": 13, + "column": 0, + "end_line": 17, + "end_column": 1 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "config", + "filename": "config_expr-04.k", + "line": 19, + "column": 0, + "end_line": 19, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "config_expr-04.k", + "line": 19, + "column": 0, + "end_line": 19, + "end_column": 6 + } + ], + "value": { + "node": { + "type": "Schema", + "data": { + "name": { + "node": { + "names": [ + { + "node": "Config", + "filename": "config_expr-04.k", + "line": 19, + "column": 9, + "end_line": 19, + "end_column": 15 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "config_expr-04.k", + "line": 19, + "column": 9, + "end_line": 19, + "end_column": 15 + }, + "args": [], + "kwargs": [], + "config": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "main", + "filename": "config_expr-04.k", + "line": 20, + "column": 4, + "end_line": 20, + "end_column": 8 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 20, + "column": 4, + "end_line": 20, + "end_column": 8 + }, + "value": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "_main", + "filename": "config_expr-04.k", + "line": 20, + "column": 10, + "end_line": 20, + "end_column": 15 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 20, + "column": 10, + "end_line": 20, + "end_column": 15 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 20, + "column": 4, + "end_line": 20, + "end_column": 15 + }, + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "main", + "filename": "config_expr-04.k", + "line": 21, + "column": 4, + "end_line": 21, + "end_column": 8 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 21, + "column": 4, + "end_line": 21, + "end_column": 8 + }, + "value": { + "node": { + "type": "Schema", + "data": { + "name": { + "node": { + "names": [ + { + "node": "Main", + "filename": "config_expr-04.k", + "line": 21, + "column": 10, + "end_line": 21, + "end_column": 14 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "config_expr-04.k", + "line": 21, + "column": 10, + "end_line": 21, + "end_column": 14 + }, + "args": [], + "kwargs": [], + "config": { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "env", + "filename": "config_expr-04.k", + "line": 22, + "column": 8, + "end_line": 22, + "end_column": 11 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 22, + "column": 8, + "end_line": 22, + "end_column": 11 + }, + "value": { + "node": { + "type": "List", + "data": { + "elts": [ + { + "node": { + "type": "Config", + "data": { + "items": [ + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "name", + "filename": "config_expr-04.k", + "line": 23, + "column": 13, + "end_line": 23, + "end_column": 17 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 23, + "column": 13, + "end_line": 23, + "end_column": 17 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"ENV_2\"", + "value": "ENV_2" + } + }, + "filename": "config_expr-04.k", + "line": 23, + "column": 19, + "end_line": 23, + "end_column": 26 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 23, + "column": 13, + "end_line": 23, + "end_column": 26 + }, + { + "node": { + "key": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "value", + "filename": "config_expr-04.k", + "line": 23, + "column": 28, + "end_line": 23, + "end_column": 33 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 23, + "column": 28, + "end_line": 23, + "end_column": 33 + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"2\"", + "value": "2" + } + }, + "filename": "config_expr-04.k", + "line": 23, + "column": 35, + "end_line": 23, + "end_column": 38 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 23, + "column": 28, + "end_line": 23, + "end_column": 38 + } + ] + } + }, + "filename": "config_expr-04.k", + "line": 23, + "column": 12, + "end_line": 23, + "end_column": 39 + } + ], + "ctx": "Load" + } + }, + "filename": "config_expr-04.k", + "line": 22, + "column": 15, + "end_line": 24, + "end_column": 9 + }, + "operation": "Insert", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 22, + "column": 8, + "end_line": 24, + "end_column": 9 + } + ] + } + }, + "filename": "config_expr-04.k", + "line": 21, + "column": 15, + "end_line": 25, + "end_column": 5 + } + } + }, + "filename": "config_expr-04.k", + "line": 21, + "column": 10, + "end_line": 25, + "end_column": 5 + }, + "operation": "Union", + "insert_index": -1 + }, + "filename": "config_expr-04.k", + "line": 21, + "column": 4, + "end_line": 25, + "end_column": 5 + } + ] + } + }, + "filename": "config_expr-04.k", + "line": 19, + "column": 16, + "end_line": 26, + "end_column": 1 + } + } + }, + "filename": "config_expr-04.k", + "line": 19, + "column": 9, + "end_line": 26, + "end_column": 1 + }, + "ty": null + } + }, + "filename": "config_expr-04.k", + "line": 19, + "column": 0, + "end_line": 26, + "end_column": 1 + } + ], + "comments": [ + { + "node": { + "text": "# test/grammar/attr_operator/config_inside/insert/schema_0/main.k" + }, + "filename": "config_expr-04.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 65 + } + ] +} 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 56997a478..2b2126843 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 @@ -3,4 +3,181 @@ source: parser/src/tests/file.rs assertion_line: 19 expression: "crate::tests::parsing_file_string(\"testdata/hello_win.k\")" --- -{"filename":"hello_win.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Schema":{"doc":null,"name":{"node":"Person","filename":"hello_win.k","line":2,"column":7,"end_line":2,"end_column":13},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"name","filename":"hello_win.k","line":3,"column":4,"end_line":3,"end_column":8},"op":{"Aug":"Assign"},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"kcl\"","value":"kcl"}},"filename":"hello_win.k","line":3,"column":16,"end_line":3,"end_column":21},"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello_win.k","line":3,"column":10,"end_line":3,"end_column":13}}},"filename":"hello_win.k","line":3,"column":4,"end_line":3,"end_column":21}],"decorators":[],"checks":[],"index_signature":null}},"filename":"hello_win.k","line":2,"column":0,"end_line":5,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"x0","filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":2}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Person","filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":11}],"pkgpath":"","ctx":"Load"},"filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":11},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[]}},"filename":"hello_win.k","line":5,"column":12,"end_line":5,"end_column":14}}},"filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":14},"ty":null}},"filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":14}],"comments":[]} +{ + "filename": "hello_win.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Schema", + "data": { + "doc": null, + "name": { + "node": "Person", + "filename": "hello_win.k", + "line": 2, + "column": 7, + "end_line": 2, + "end_column": 13 + }, + "parent_name": null, + "for_host_name": null, + "is_mixin": false, + "is_protocol": false, + "args": null, + "mixins": [], + "body": [ + { + "node": { + "type": "SchemaAttr", + "data": { + "doc": "", + "name": { + "node": "name", + "filename": "hello_win.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 8 + }, + "op": { + "type": "Aug", + "data": "Assign" + }, + "value": { + "node": { + "type": "StringLit", + "data": { + "is_long_string": false, + "raw_value": "\"kcl\"", + "value": "kcl" + } + }, + "filename": "hello_win.k", + "line": 3, + "column": 16, + "end_line": 3, + "end_column": 21 + }, + "is_optional": false, + "decorators": [], + "ty": { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "hello_win.k", + "line": 3, + "column": 10, + "end_line": 3, + "end_column": 13 + } + } + }, + "filename": "hello_win.k", + "line": 3, + "column": 4, + "end_line": 3, + "end_column": 21 + } + ], + "decorators": [], + "checks": [], + "index_signature": null + } + }, + "filename": "hello_win.k", + "line": 2, + "column": 0, + "end_line": 5, + "end_column": 0 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "x0", + "filename": "hello_win.k", + "line": 5, + "column": 0, + "end_line": 5, + "end_column": 2 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "hello_win.k", + "line": 5, + "column": 0, + "end_line": 5, + "end_column": 2 + } + ], + "value": { + "node": { + "type": "Schema", + "data": { + "name": { + "node": { + "names": [ + { + "node": "Person", + "filename": "hello_win.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 11 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "hello_win.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 11 + }, + "args": [], + "kwargs": [], + "config": { + "node": { + "type": "Config", + "data": { + "items": [] + } + }, + "filename": "hello_win.k", + "line": 5, + "column": 12, + "end_line": 5, + "end_column": 14 + } + } + }, + "filename": "hello_win.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 14 + }, + "ty": null + } + }, + "filename": "hello_win.k", + "line": 5, + "column": 0, + "end_line": 5, + "end_column": 14 + } + ], + "comments": [] +} 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 d448725c1..25f90232a 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 @@ -3,4 +3,157 @@ source: parser/src/tests/file.rs assertion_line: 15 expression: "crate::tests::parsing_file_string(\"testdata/if-01.k\")" --- -{"filename":"if-01.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-01.k","line":1,"column":4,"end_line":1,"end_column":5},"ty":null}},"filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":5},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"bbb","filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"if-01.k","line":4,"column":10,"end_line":4,"end_column":11},"ty":null}},"filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":11}],"cond":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-01.k","line":3,"column":3,"end_line":3,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"if-01.k","line":3,"column":3,"end_line":3,"end_column":4},"orelse":[]}},"filename":"if-01.k","line":3,"column":0,"end_line":4,"end_column":12}],"comments":[]} +{ + "filename": "if-01.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "if-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "if-01.k", + "line": 1, + "column": 4, + "end_line": 1, + "end_column": 5 + }, + "ty": null + } + }, + "filename": "if-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 5 + }, + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "bbb", + "filename": "if-01.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 7 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-01.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 7 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "if-01.k", + "line": 4, + "column": 10, + "end_line": 4, + "end_column": 11 + }, + "ty": null + } + }, + "filename": "if-01.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 11 + } + ], + "cond": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "if-01.k", + "line": 3, + "column": 3, + "end_line": 3, + "end_column": 4 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "if-01.k", + "line": 3, + "column": 3, + "end_line": 3, + "end_column": 4 + }, + "orelse": [] + } + }, + "filename": "if-01.k", + "line": 3, + "column": 0, + "end_line": 4, + "end_column": 12 + } + ], + "comments": [] +} 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 3c8c8a177..3d56a202a 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 @@ -3,4 +3,516 @@ source: parser/src/tests/file.rs assertion_line: 16 expression: "crate::tests::parsing_file_string(\"testdata/if-02.k\")" --- -{"filename":"if-02.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-02.k","line":1,"column":4,"end_line":1,"end_column":5},"ty":null}},"filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":5},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"bbb","filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"if-02.k","line":4,"column":10,"end_line":4,"end_column":11},"ty":null}},"filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":11}],"cond":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":3,"column":3,"end_line":3,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":3,"column":3,"end_line":3,"end_column":4},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"ccc","filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"if-02.k","line":6,"column":10,"end_line":6,"end_column":11},"ty":null}},"filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":11}],"cond":{"node":{"Binary":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":6},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"if-02.k","line":5,"column":9,"end_line":5,"end_column":11}}},"filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":11},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"ddd","filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":4}}},"filename":"if-02.k","line":8,"column":10,"end_line":8,"end_column":11},"ty":null}},"filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":11}],"cond":{"node":{"Binary":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":6},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":100}}},"filename":"if-02.k","line":7,"column":9,"end_line":7,"end_column":12}}},"filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":12},"orelse":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"eee","filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":5}}},"filename":"if-02.k","line":10,"column":10,"end_line":10,"end_column":11},"ty":null}},"filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":11},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"fff","filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":6}}},"filename":"if-02.k","line":11,"column":10,"end_line":11,"end_column":11},"ty":null}},"filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":7,"column":0,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":5,"column":0,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":3,"column":0,"end_line":11,"end_column":12}],"comments":[]} +{ + "filename": "if-02.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "if-02.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-02.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 1 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "if-02.k", + "line": 1, + "column": 4, + "end_line": 1, + "end_column": 5 + }, + "ty": null + } + }, + "filename": "if-02.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 5 + }, + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "bbb", + "filename": "if-02.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 7 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-02.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 7 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 2 + } + } + }, + "filename": "if-02.k", + "line": 4, + "column": 10, + "end_line": 4, + "end_column": 11 + }, + "ty": null + } + }, + "filename": "if-02.k", + "line": 4, + "column": 4, + "end_line": 4, + "end_column": 11 + } + ], + "cond": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "if-02.k", + "line": 3, + "column": 3, + "end_line": 3, + "end_column": 4 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "if-02.k", + "line": 3, + "column": 3, + "end_line": 3, + "end_column": 4 + }, + "orelse": [ + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "ccc", + "filename": "if-02.k", + "line": 6, + "column": 4, + "end_line": 6, + "end_column": 7 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-02.k", + "line": 6, + "column": 4, + "end_line": 6, + "end_column": 7 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 3 + } + } + }, + "filename": "if-02.k", + "line": 6, + "column": 10, + "end_line": 6, + "end_column": 11 + }, + "ty": null + } + }, + "filename": "if-02.k", + "line": 6, + "column": 4, + "end_line": 6, + "end_column": 11 + } + ], + "cond": { + "node": { + "type": "Binary", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "if-02.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "if-02.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 6 + }, + "op": { + "type": "Bin", + "data": "Add" + }, + "right": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 10 + } + } + }, + "filename": "if-02.k", + "line": 5, + "column": 9, + "end_line": 5, + "end_column": 11 + } + } + }, + "filename": "if-02.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 11 + }, + "orelse": [ + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "ddd", + "filename": "if-02.k", + "line": 8, + "column": 4, + "end_line": 8, + "end_column": 7 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-02.k", + "line": 8, + "column": 4, + "end_line": 8, + "end_column": 7 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 4 + } + } + }, + "filename": "if-02.k", + "line": 8, + "column": 10, + "end_line": 8, + "end_column": 11 + }, + "ty": null + } + }, + "filename": "if-02.k", + "line": 8, + "column": 4, + "end_line": 8, + "end_column": 11 + } + ], + "cond": { + "node": { + "type": "Binary", + "data": { + "left": { + "node": { + "type": "Identifier", + "data": { + "names": [ + { + "node": "a", + "filename": "if-02.k", + "line": 7, + "column": 5, + "end_line": 7, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + } + }, + "filename": "if-02.k", + "line": 7, + "column": 5, + "end_line": 7, + "end_column": 6 + }, + "op": { + "type": "Bin", + "data": "Add" + }, + "right": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 100 + } + } + }, + "filename": "if-02.k", + "line": 7, + "column": 9, + "end_line": 7, + "end_column": 12 + } + } + }, + "filename": "if-02.k", + "line": 7, + "column": 5, + "end_line": 7, + "end_column": 12 + }, + "orelse": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "eee", + "filename": "if-02.k", + "line": 10, + "column": 4, + "end_line": 10, + "end_column": 7 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-02.k", + "line": 10, + "column": 4, + "end_line": 10, + "end_column": 7 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 5 + } + } + }, + "filename": "if-02.k", + "line": 10, + "column": 10, + "end_line": 10, + "end_column": 11 + }, + "ty": null + } + }, + "filename": "if-02.k", + "line": 10, + "column": 4, + "end_line": 10, + "end_column": 11 + }, + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "fff", + "filename": "if-02.k", + "line": 11, + "column": 4, + "end_line": 11, + "end_column": 7 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-02.k", + "line": 11, + "column": 4, + "end_line": 11, + "end_column": 7 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 6 + } + } + }, + "filename": "if-02.k", + "line": 11, + "column": 10, + "end_line": 11, + "end_column": 11 + }, + "ty": null + } + }, + "filename": "if-02.k", + "line": 11, + "column": 4, + "end_line": 11, + "end_column": 11 + } + ] + } + }, + "filename": "if-02.k", + "line": 7, + "column": 0, + "end_line": 11, + "end_column": 11 + } + ] + } + }, + "filename": "if-02.k", + "line": 5, + "column": 0, + "end_line": 11, + "end_column": 11 + } + ] + } + }, + "filename": "if-02.k", + "line": 3, + "column": 0, + "end_line": 11, + "end_column": 12 + } + ], + "comments": [] +} 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 61202ff59..fee335be0 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 @@ -3,4 +3,93 @@ source: parser/src/tests/file.rs assertion_line: 17 expression: "crate::tests::parsing_file_string(\"testdata/if-03.k\")" --- -{"filename":"if-03.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":10}],"pkgpath":"","ctx":"Store"},"filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":10}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-03.k","line":1,"column":13,"end_line":1,"end_column":14},"ty":null}},"filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":14}],"cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"if-03.k","line":1,"column":3,"end_line":1,"end_column":7},"orelse":[]}},"filename":"if-03.k","line":1,"column":0,"end_line":1,"end_column":15}],"comments":[]} +{ + "filename": "if-03.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "If", + "data": { + "body": [ + { + "node": { + "type": "Assign", + "data": { + "targets": [ + { + "node": { + "names": [ + { + "node": "a", + "filename": "if-03.k", + "line": 1, + "column": 9, + "end_line": 1, + "end_column": 10 + } + ], + "pkgpath": "", + "ctx": "Store" + }, + "filename": "if-03.k", + "line": 1, + "column": 9, + "end_line": 1, + "end_column": 10 + } + ], + "value": { + "node": { + "type": "NumberLit", + "data": { + "binary_suffix": null, + "value": { + "type": "Int", + "data": 1 + } + } + }, + "filename": "if-03.k", + "line": 1, + "column": 13, + "end_line": 1, + "end_column": 14 + }, + "ty": null + } + }, + "filename": "if-03.k", + "line": 1, + "column": 9, + "end_line": 1, + "end_column": 14 + } + ], + "cond": { + "node": { + "type": "NameConstantLit", + "data": { + "value": "True" + } + }, + "filename": "if-03.k", + "line": 1, + "column": 3, + "end_line": 1, + "end_column": 7 + }, + "orelse": [] + } + }, + "filename": "if-03.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 15 + } + ], + "comments": [] +} 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 6697c392f..1eee5ccce 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 @@ -1,5 +1,117 @@ --- source: parser/src/tests/file.rs +assertion_line: 14 expression: "crate::tests::parsing_file_string(\"testdata/import-01.k\")" --- -{"filename":"import-01.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"Import":{"path":{"node":"a1","filename":"import-01.k","line":1,"column":7,"end_line":1,"end_column":9},"rawpath":"a1","name":"a1","asname":null,"pkg_name":""}},"filename":"import-01.k","line":1,"column":0,"end_line":1,"end_column":9},{"node":{"Import":{"path":{"node":"a2","filename":"import-01.k","line":3,"column":7,"end_line":3,"end_column":9},"rawpath":"a2","name":"a2_pkg","asname":{"node":"a2_pkg","filename":"import-01.k","line":3,"column":13,"end_line":3,"end_column":19},"pkg_name":""}},"filename":"import-01.k","line":3,"column":0,"end_line":3,"end_column":19},{"node":{"Import":{"path":{"node":"subpkg.b1.c1","filename":"import-01.k","line":5,"column":7,"end_line":5,"end_column":19},"rawpath":"subpkg.b1.c1","name":"c1","asname":null,"pkg_name":""}},"filename":"import-01.k","line":5,"column":0,"end_line":5,"end_column":19},{"node":{"Import":{"path":{"node":".a3","filename":"import-01.k","line":7,"column":7,"end_line":7,"end_column":10},"rawpath":".a3","name":"a3","asname":null,"pkg_name":""}},"filename":"import-01.k","line":7,"column":0,"end_line":7,"end_column":10}],"comments":[]} +{ + "filename": "import-01.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "Import", + "data": { + "path": { + "node": "a1", + "filename": "import-01.k", + "line": 1, + "column": 7, + "end_line": 1, + "end_column": 9 + }, + "rawpath": "a1", + "name": "a1", + "asname": null, + "pkg_name": "__main__" + } + }, + "filename": "import-01.k", + "line": 1, + "column": 0, + "end_line": 1, + "end_column": 9 + }, + { + "node": { + "type": "Import", + "data": { + "path": { + "node": "a2", + "filename": "import-01.k", + "line": 3, + "column": 7, + "end_line": 3, + "end_column": 9 + }, + "rawpath": "a2", + "name": "a2_pkg", + "asname": { + "node": "a2_pkg", + "filename": "import-01.k", + "line": 3, + "column": 13, + "end_line": 3, + "end_column": 19 + }, + "pkg_name": "__main__" + } + }, + "filename": "import-01.k", + "line": 3, + "column": 0, + "end_line": 3, + "end_column": 19 + }, + { + "node": { + "type": "Import", + "data": { + "path": { + "node": "subpkg.b1.c1", + "filename": "import-01.k", + "line": 5, + "column": 7, + "end_line": 5, + "end_column": 19 + }, + "rawpath": "subpkg.b1.c1", + "name": "c1", + "asname": null, + "pkg_name": "__main__" + } + }, + "filename": "import-01.k", + "line": 5, + "column": 0, + "end_line": 5, + "end_column": 19 + }, + { + "node": { + "type": "Import", + "data": { + "path": { + "node": "a3", + "filename": "import-01.k", + "line": 7, + "column": 7, + "end_line": 7, + "end_column": 10 + }, + "rawpath": ".a3", + "name": "a3", + "asname": null, + "pkg_name": "__main__" + } + }, + "filename": "import-01.k", + "line": 7, + "column": 0, + "end_line": 7, + "end_column": 10 + } + ], + "comments": [] +} 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 ea395e4a3..c7b898af3 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 @@ -1,5 +1,561 @@ --- source: parser/src/tests/file.rs +assertion_line: 18 expression: "crate::tests::parsing_file_string(\"testdata/type-01.k\")" --- -{"filename":"type-01.k","pkg":"__main__","doc":null,"name":"__main__","body":[{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"a","filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":6},"type_value":{"node":"any","filename":"type-01.k","line":1,"column":9,"end_line":1,"end_column":12},"ty":{"node":"Any","filename":"type-01.k","line":1,"column":9,"end_line":1,"end_column":12}}},"filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"b","filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":6},"type_value":{"node":"bool","filename":"type-01.k","line":3,"column":9,"end_line":3,"end_column":13},"ty":{"node":{"Basic":"Bool"},"filename":"type-01.k","line":3,"column":9,"end_line":3,"end_column":13}}},"filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":13},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"c","filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":6},"type_value":{"node":"int","filename":"type-01.k","line":4,"column":9,"end_line":4,"end_column":12},"ty":{"node":{"Basic":"Int"},"filename":"type-01.k","line":4,"column":9,"end_line":4,"end_column":12}}},"filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"d","filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":6},"type_value":{"node":"float","filename":"type-01.k","line":5,"column":9,"end_line":5,"end_column":14},"ty":{"node":{"Basic":"Float"},"filename":"type-01.k","line":5,"column":9,"end_line":5,"end_column":14}}},"filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":14},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"e","filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":6},"type_value":{"node":"str","filename":"type-01.k","line":6,"column":9,"end_line":6,"end_column":12},"ty":{"node":{"Basic":"Str"},"filename":"type-01.k","line":6,"column":9,"end_line":6,"end_column":12}}},"filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list1","filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":15},"type_value":{"node":"[]","filename":"type-01.k","line":8,"column":18,"end_line":8,"end_column":20},"ty":{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":8,"column":18,"end_line":8,"end_column":20}}},"filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":20},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list2","filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":15},"type_value":{"node":"[[]]","filename":"type-01.k","line":9,"column":18,"end_line":9,"end_column":22},"ty":{"node":{"List":{"inner_type":{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":9,"column":19,"end_line":9,"end_column":21}}},"filename":"type-01.k","line":9,"column":18,"end_line":9,"end_column":22}}},"filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":22},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list3","filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":15},"type_value":{"node":"[int]","filename":"type-01.k","line":10,"column":18,"end_line":10,"end_column":23},"ty":{"node":{"List":{"inner_type":{"node":{"Basic":"Int"},"filename":"type-01.k","line":10,"column":19,"end_line":10,"end_column":22}}},"filename":"type-01.k","line":10,"column":18,"end_line":10,"end_column":23}}},"filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":23},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"b","filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":6},"type_value":{"node":"int | str | [] | {:}","filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":29},"ty":{"node":{"Union":{"type_elements":[{"node":{"Basic":"Int"},"filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":12},{"node":{"Basic":"Str"},"filename":"type-01.k","line":12,"column":15,"end_line":12,"end_column":18},{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":12,"column":21,"end_line":12,"end_column":23},{"node":{"Dict":{"key_type":null,"value_type":null}},"filename":"type-01.k","line":12,"column":26,"end_line":12,"end_column":29}]}},"filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":29}}},"filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":29}],"comments":[]} +{ + "filename": "type-01.k", + "pkg": "__main__", + "doc": null, + "name": "__main__", + "body": [ + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "a", + "filename": "type-01.k", + "line": 1, + "column": 5, + "end_line": 1, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 1, + "column": 5, + "end_line": 1, + "end_column": 6 + }, + "type_value": { + "node": "any", + "filename": "type-01.k", + "line": 1, + "column": 9, + "end_line": 1, + "end_column": 12 + }, + "ty": { + "node": { + "type": "Any" + }, + "filename": "type-01.k", + "line": 1, + "column": 9, + "end_line": 1, + "end_column": 12 + } + } + }, + "filename": "type-01.k", + "line": 1, + "column": 5, + "end_line": 1, + "end_column": 12 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "b", + "filename": "type-01.k", + "line": 3, + "column": 5, + "end_line": 3, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 3, + "column": 5, + "end_line": 3, + "end_column": 6 + }, + "type_value": { + "node": "bool", + "filename": "type-01.k", + "line": 3, + "column": 9, + "end_line": 3, + "end_column": 13 + }, + "ty": { + "node": { + "type": "Basic", + "data": "Bool" + }, + "filename": "type-01.k", + "line": 3, + "column": 9, + "end_line": 3, + "end_column": 13 + } + } + }, + "filename": "type-01.k", + "line": 3, + "column": 5, + "end_line": 3, + "end_column": 13 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "c", + "filename": "type-01.k", + "line": 4, + "column": 5, + "end_line": 4, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 4, + "column": 5, + "end_line": 4, + "end_column": 6 + }, + "type_value": { + "node": "int", + "filename": "type-01.k", + "line": 4, + "column": 9, + "end_line": 4, + "end_column": 12 + }, + "ty": { + "node": { + "type": "Basic", + "data": "Int" + }, + "filename": "type-01.k", + "line": 4, + "column": 9, + "end_line": 4, + "end_column": 12 + } + } + }, + "filename": "type-01.k", + "line": 4, + "column": 5, + "end_line": 4, + "end_column": 12 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "d", + "filename": "type-01.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 6 + }, + "type_value": { + "node": "float", + "filename": "type-01.k", + "line": 5, + "column": 9, + "end_line": 5, + "end_column": 14 + }, + "ty": { + "node": { + "type": "Basic", + "data": "Float" + }, + "filename": "type-01.k", + "line": 5, + "column": 9, + "end_line": 5, + "end_column": 14 + } + } + }, + "filename": "type-01.k", + "line": 5, + "column": 5, + "end_line": 5, + "end_column": 14 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "e", + "filename": "type-01.k", + "line": 6, + "column": 5, + "end_line": 6, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 6, + "column": 5, + "end_line": 6, + "end_column": 6 + }, + "type_value": { + "node": "str", + "filename": "type-01.k", + "line": 6, + "column": 9, + "end_line": 6, + "end_column": 12 + }, + "ty": { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "type-01.k", + "line": 6, + "column": 9, + "end_line": 6, + "end_column": 12 + } + } + }, + "filename": "type-01.k", + "line": 6, + "column": 5, + "end_line": 6, + "end_column": 12 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "type_list1", + "filename": "type-01.k", + "line": 8, + "column": 5, + "end_line": 8, + "end_column": 15 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 8, + "column": 5, + "end_line": 8, + "end_column": 15 + }, + "type_value": { + "node": "[]", + "filename": "type-01.k", + "line": 8, + "column": 18, + "end_line": 8, + "end_column": 20 + }, + "ty": { + "node": { + "type": "List", + "data": { + "inner_type": null + } + }, + "filename": "type-01.k", + "line": 8, + "column": 18, + "end_line": 8, + "end_column": 20 + } + } + }, + "filename": "type-01.k", + "line": 8, + "column": 5, + "end_line": 8, + "end_column": 20 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "type_list2", + "filename": "type-01.k", + "line": 9, + "column": 5, + "end_line": 9, + "end_column": 15 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 9, + "column": 5, + "end_line": 9, + "end_column": 15 + }, + "type_value": { + "node": "[[]]", + "filename": "type-01.k", + "line": 9, + "column": 18, + "end_line": 9, + "end_column": 22 + }, + "ty": { + "node": { + "type": "List", + "data": { + "inner_type": { + "node": { + "type": "List", + "data": { + "inner_type": null + } + }, + "filename": "type-01.k", + "line": 9, + "column": 19, + "end_line": 9, + "end_column": 21 + } + } + }, + "filename": "type-01.k", + "line": 9, + "column": 18, + "end_line": 9, + "end_column": 22 + } + } + }, + "filename": "type-01.k", + "line": 9, + "column": 5, + "end_line": 9, + "end_column": 22 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "type_list3", + "filename": "type-01.k", + "line": 10, + "column": 5, + "end_line": 10, + "end_column": 15 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 10, + "column": 5, + "end_line": 10, + "end_column": 15 + }, + "type_value": { + "node": "[int]", + "filename": "type-01.k", + "line": 10, + "column": 18, + "end_line": 10, + "end_column": 23 + }, + "ty": { + "node": { + "type": "List", + "data": { + "inner_type": { + "node": { + "type": "Basic", + "data": "Int" + }, + "filename": "type-01.k", + "line": 10, + "column": 19, + "end_line": 10, + "end_column": 22 + } + } + }, + "filename": "type-01.k", + "line": 10, + "column": 18, + "end_line": 10, + "end_column": 23 + } + } + }, + "filename": "type-01.k", + "line": 10, + "column": 5, + "end_line": 10, + "end_column": 23 + }, + { + "node": { + "type": "TypeAlias", + "data": { + "type_name": { + "node": { + "names": [ + { + "node": "b", + "filename": "type-01.k", + "line": 12, + "column": 5, + "end_line": 12, + "end_column": 6 + } + ], + "pkgpath": "", + "ctx": "Load" + }, + "filename": "type-01.k", + "line": 12, + "column": 5, + "end_line": 12, + "end_column": 6 + }, + "type_value": { + "node": "int | str | [] | {:}", + "filename": "type-01.k", + "line": 12, + "column": 9, + "end_line": 12, + "end_column": 29 + }, + "ty": { + "node": { + "type": "Union", + "data": { + "type_elements": [ + { + "node": { + "type": "Basic", + "data": "Int" + }, + "filename": "type-01.k", + "line": 12, + "column": 9, + "end_line": 12, + "end_column": 12 + }, + { + "node": { + "type": "Basic", + "data": "Str" + }, + "filename": "type-01.k", + "line": 12, + "column": 15, + "end_line": 12, + "end_column": 18 + }, + { + "node": { + "type": "List", + "data": { + "inner_type": null + } + }, + "filename": "type-01.k", + "line": 12, + "column": 21, + "end_line": 12, + "end_column": 23 + }, + { + "node": { + "type": "Dict", + "data": { + "key_type": null, + "value_type": null + } + }, + "filename": "type-01.k", + "line": 12, + "column": 26, + "end_line": 12, + "end_column": 29 + } + ] + } + }, + "filename": "type-01.k", + "line": 12, + "column": 9, + "end_line": 12, + "end_column": 29 + } + } + }, + "filename": "type-01.k", + "line": 12, + "column": 5, + "end_line": 12, + "end_column": 29 + } + ], + "comments": [] +} diff --git a/kclvm/query/src/lib.rs b/kclvm/query/src/lib.rs index 31dabd359..17d425541 100644 --- a/kclvm/query/src/lib.rs +++ b/kclvm/query/src/lib.rs @@ -84,7 +84,7 @@ pub fn override_file(file: &str, specs: &[String], import_paths: &[String]) -> R .collect::>(); // Parse file to AST module. let mut module = match parse_file(file, None) { - Ok(module) => module, + Ok(module) => module.module, Err(msg) => return Err(anyhow!("{}", msg)), }; let mut result = false; diff --git a/kclvm/query/src/override.rs b/kclvm/query/src/override.rs index 1c3b36011..d975c780d 100644 --- a/kclvm/query/src/override.rs +++ b/kclvm/query/src/override.rs @@ -6,6 +6,7 @@ use compiler_base_macros::bug; use kclvm_ast::config::try_get_config_expr_mut; use kclvm_ast::path::get_key_path; use kclvm_ast::walker::MutSelfMutWalker; +use kclvm_ast::MAIN_PKG; use kclvm_ast::{ast, walk_if_mut}; use kclvm_ast_pretty::print_ast_module; use kclvm_parser::parse_expr; @@ -42,7 +43,7 @@ pub fn apply_overrides( ) -> Result<()> { for o in overrides { let pkgpath = if o.pkgpath.is_empty() { - &prog.main + MAIN_PKG } else { &o.pkgpath }; @@ -89,10 +90,10 @@ fn build_expr_from_string(value: &str) -> Option> { /// # Examples /// /// ```no_check -/// use kclvm_parser::parse_file; +/// use kclvm_parser::parse_file_force_errors; /// use kclvm_tools::query::apply_override_on_module; /// -/// let mut module = parse_file("", None).unwrap(); +/// let mut module = parse_file_force_errors("", None).unwrap(); /// let override_spec = parse_override_spec("config.id=1").unwrap(); /// let import_paths = vec!["path.to.pkg".to_string()]; /// let result = apply_override_on_module(&mut module, override_spec, &import_paths).unwrap(); diff --git a/kclvm/query/src/query.rs b/kclvm/query/src/query.rs index c9d05af60..c23983431 100644 --- a/kclvm/query/src/query.rs +++ b/kclvm/query/src/query.rs @@ -194,7 +194,7 @@ fn resolve_file(opts: &CompilationOptions) -> Result>> { opts.loader_opts.clone(), None, ) { - Ok(p) => p, + Ok(p) => p.program, Err(err) => { return Err(anyhow::anyhow!("{err}")); } diff --git a/kclvm/query/src/tests.rs b/kclvm/query/src/tests.rs index 9ef9eb224..42b674371 100644 --- a/kclvm/query/src/tests.rs +++ b/kclvm/query/src/tests.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use super::{r#override::apply_override_on_module, *}; use kclvm_ast::ast; -use kclvm_parser::parse_file; +use kclvm_parser::parse_file_force_errors; use pretty_assertions::assert_eq; const CARGO_FILE_PATH: &str = env!("CARGO_MANIFEST_DIR"); @@ -75,7 +75,7 @@ fn test_override_file_config() { cargo_file_path.push("src/test_data/config.k"); let abs_path = cargo_file_path.to_str().unwrap(); - let mut module = parse_file(abs_path, None).unwrap(); + let mut module = parse_file_force_errors(abs_path, None).unwrap(); for o in &overrides { apply_override_on_module(&mut module, o, &import_paths).unwrap(); } diff --git a/kclvm/runner/src/assembler.rs b/kclvm/runner/src/assembler.rs index 8891ecf6e..dddb2da74 100644 --- a/kclvm/runner/src/assembler.rs +++ b/kclvm/runner/src/assembler.rs @@ -290,7 +290,6 @@ impl KclvmAssembler { pkgs.insert(pkgpath.clone(), modules); let compile_prog = ast::Program { root: self.program.root.clone(), - main: self.program.main.clone(), pkgs, }; compile_progs.insert( diff --git a/kclvm/runner/src/lib.rs b/kclvm/runner/src/lib.rs index 73c698ddc..550928aac 100644 --- a/kclvm/runner/src/lib.rs +++ b/kclvm/runner/src/lib.rs @@ -75,9 +75,8 @@ pub fn exec_program(sess: Arc, args: &ExecProgramArgs) -> Result>(); - let mut program = load_program(sess.clone(), kcl_paths_str.as_slice(), Some(opts), None) - .map_err(|err| anyhow!(err))?; - + let mut program = + load_program(sess.clone(), kcl_paths_str.as_slice(), Some(opts), None)?.program; apply_overrides( &mut program, &args.overrides, @@ -154,7 +153,7 @@ pub fn exec_program(sess: Arc, args: &ExecProgramArgs) -> Result Result { let prog = Program { root: MAIN_PKG.to_string(), - main: MAIN_PKG.to_string(), pkgs, }; @@ -247,10 +245,11 @@ pub fn build_program>( let opts = args.get_load_program_options(); let kcl_paths = expand_files(args)?; let kcl_paths_str = kcl_paths.iter().map(|s| s.as_str()).collect::>(); - let mut program = load_program(sess.clone(), kcl_paths_str.as_slice(), Some(opts), None) - .map_err(|err| anyhow!(err))?; + let mut program = + load_program(sess.clone(), kcl_paths_str.as_slice(), Some(opts), None)?.program; // Resolve program. let scope = resolve_program(&mut program); + // Emit parse and resolve errors if exists. emit_compile_diag_to_string(sess, &scope, false)?; // Create a temp entry file and the temp dir will be delete automatically. let temp_dir = tempdir()?; diff --git a/kclvm/runner/src/runner.rs b/kclvm/runner/src/runner.rs index 49fb2a85b..3e57c059f 100644 --- a/kclvm/runner/src/runner.rs +++ b/kclvm/runner/src/runner.rs @@ -54,8 +54,6 @@ pub struct ExecProgramArgs { pub include_schema_type_path: bool, // Whether to compile only. pub compile_only: bool, - // Whether to compile diractroy recursively. - pub recursive: bool, // plugin_agent is the address of plugin. #[serde(skip)] pub plugin_agent: u64, @@ -152,10 +150,7 @@ impl ExecProgramArgs { vendor_dirs: vec![get_vendor_home()], package_maps: self.get_package_maps_from_external_pkg(), k_code_list: self.k_code_list.clone(), - cmd_args: self.args.clone(), - cmd_overrides: self.overrides.clone(), load_plugins: self.plugin_agent > 0, - recursive: self.recursive, ..Default::default() } } @@ -175,7 +170,6 @@ impl TryFrom for ExecProgramArgs { args.verbose = cli_configs.verbose.unwrap_or_default() as i32; args.debug = cli_configs.debug.unwrap_or_default() as i32; args.sort_keys = cli_configs.sort_keys.unwrap_or_default(); - args.recursive = cli_configs.recursive.unwrap_or_default(); args.include_schema_type_path = cli_configs.include_schema_type_path.unwrap_or_default(); for override_str in &cli_configs.overrides.unwrap_or_default() { diff --git a/kclvm/runner/src/test_datas/exec_prog_args/default.json b/kclvm/runner/src/test_datas/exec_prog_args/default.json index 1a0479dd3..edd40ba9c 100644 --- a/kclvm/runner/src/test_datas/exec_prog_args/default.json +++ b/kclvm/runner/src/test_datas/exec_prog_args/default.json @@ -1 +1 @@ -{"work_dir":null,"k_filename_list":[],"external_pkgs":[],"k_code_list":[],"args":[],"overrides":[],"path_selector":[],"disable_yaml_result":false,"print_override_ast":false,"strict_range_check":false,"disable_none":false,"verbose":0,"debug":0,"sort_keys":false,"include_schema_type_path":false,"compile_only":false,"recursive":false} \ No newline at end of file +{"work_dir":null,"k_filename_list":[],"external_pkgs":[],"k_code_list":[],"args":[],"overrides":[],"path_selector":[],"disable_yaml_result":false,"print_override_ast":false,"strict_range_check":false,"disable_none":false,"verbose":0,"debug":0,"sort_keys":false,"include_schema_type_path":false,"compile_only":false} \ No newline at end of file diff --git a/kclvm/runner/src/test_datas/settings_file/settings.json b/kclvm/runner/src/test_datas/settings_file/settings.json index ffabce64c..b9f01b4cb 100644 --- a/kclvm/runner/src/test_datas/settings_file/settings.json +++ b/kclvm/runner/src/test_datas/settings_file/settings.json @@ -1 +1 @@ -{"work_dir":null,"k_filename_list":["../main.k","./before/base.k","./main.k","./sub/sub.k"],"external_pkgs":[],"k_code_list":[],"args":[{"name":"app-name","value":"\"kclvm\""},{"name":"image","value":"\"kclvm:v0.0.1\""}],"overrides":[],"path_selector":[],"disable_yaml_result":false,"print_override_ast":false,"strict_range_check":false,"disable_none":false,"verbose":0,"debug":0,"sort_keys":false,"include_schema_type_path":false,"compile_only":false,"recursive":false} \ No newline at end of file +{"work_dir":null,"k_filename_list":["../main.k","./before/base.k","./main.k","./sub/sub.k"],"external_pkgs":[],"k_code_list":[],"args":[{"name":"app-name","value":"\"kclvm\""},{"name":"image","value":"\"kclvm:v0.0.1\""}],"overrides":[],"path_selector":[],"disable_yaml_result":false,"print_override_ast":false,"strict_range_check":false,"disable_none":false,"verbose":0,"debug":0,"sort_keys":false,"include_schema_type_path":false,"compile_only":false} \ No newline at end of file diff --git a/kclvm/runner/src/tests.rs b/kclvm/runner/src/tests.rs index bb58546ce..51b8c9e06 100644 --- a/kclvm/runner/src/tests.rs +++ b/kclvm/runner/src/tests.rs @@ -140,7 +140,7 @@ fn gen_full_path(rel_path: String) -> Result { /// Load test kcl file to ast.Program fn load_test_program(filename: String) -> Program { - let module = kclvm_parser::parse_file(&filename, None).unwrap(); + let module = kclvm_parser::parse_file_force_errors(&filename, None).unwrap(); construct_program(module) } @@ -154,20 +154,19 @@ fn parse_program(test_kcl_case_path: &str) -> Program { None, ) .unwrap() + .program } /// Construct ast.Program by ast.Module and default configuration. /// Default configuration: /// module.pkg = "__main__" /// Program.root = "__main__" -/// Program.main = "__main__" fn construct_program(mut module: Module) -> Program { module.pkg = MAIN_PKG_NAME.to_string(); let mut pkgs_ast = HashMap::new(); pkgs_ast.insert(MAIN_PKG_NAME.to_string(), vec![module]); Program { root: MAIN_PKG_NAME.to_string(), - main: MAIN_PKG_NAME.to_string(), pkgs: pkgs_ast, } } @@ -264,7 +263,9 @@ fn assemble_lib_for_test( let opts = args.get_load_program_options(); let sess = Arc::new(ParseSession::default()); // parse and resolve kcl - let mut program = load_program(sess, &files, Some(opts), None).unwrap(); + let mut program = load_program(sess, &files, Some(opts), None) + .unwrap() + .program; let scope = resolve_program(&mut program); @@ -506,29 +507,6 @@ fn clean_dir(path: String) { } } -fn test_compile_dir_recursive() { - let path = PathBuf::from("./src/test_datas/compile_recursive") - .canonicalize() - .unwrap(); - let mut args = ExecProgramArgs::default(); - args.k_filename_list.push(path.display().to_string()); - let mut opts: kclvm_parser::LoadProgramOptions = args.get_load_program_options(); - opts.recursive = true; - let sess = Arc::new(ParseSession::default()); - // Load AST program - let program = load_program( - sess.clone(), - &[&path.display().to_string()], - Some(opts), - None, - ) - .unwrap(); - // Resolve ATS, generate libs, link libs and execute. - let res = execute(sess, program, &args); - assert!(res.is_ok()); - assert_eq!(res.unwrap().json_result, "{\"k1\": \"Hello k1!\", \"k2\": \"Hello k2!\", \"The_first_kcl_program\": \"Hello World!\"}"); -} - #[test] fn test_exec() { clean_dir( @@ -561,9 +539,6 @@ fn test_exec() { test_exec_with_err_result(); println!("test_exec_with_err_result - PASS"); - test_compile_dir_recursive(); - println!("test_compile_dir_recursive - PASS"); - test_indent_error(); println!("test_indent_error - PASS"); @@ -594,7 +569,9 @@ fn exec(file: &str) -> Result { let opts = args.get_load_program_options(); let sess = Arc::new(ParseSession::default()); // Load AST program - let program = load_program(sess.clone(), &[file], Some(opts), None).unwrap(); + let program = load_program(sess.clone(), &[file], Some(opts), None) + .unwrap() + .program; // Resolve ATS, generate libs, link libs and execute. match execute(sess, program, &args) { Ok(result) => { diff --git a/kclvm/runtime/src/api/kclvm.rs b/kclvm/runtime/src/api/kclvm.rs index cf9f4261c..1cf186934 100644 --- a/kclvm/runtime/src/api/kclvm.rs +++ b/kclvm/runtime/src/api/kclvm.rs @@ -266,7 +266,6 @@ pub struct DecoratorValue { #[derive(PartialEq, Eq, Clone, Default, Debug)] pub struct FuncValue { - // TODO (refactor): SchemaFuncValue pub fn_ptr: u64, pub check_fn_ptr: u64, pub closure: ValueRef, @@ -275,11 +274,6 @@ pub struct FuncValue { pub is_external: bool, } -#[derive(PartialEq, Clone, Default, Debug)] -pub struct ErrorValue { - pub errors: Vec, -} - #[derive(PartialEq, Eq, Clone, Default, Debug)] pub struct OptionHelp { pub name: String, diff --git a/kclvm/sema/src/advanced_resolver/mod.rs b/kclvm/sema/src/advanced_resolver/mod.rs index 0c9b34e23..3ccaba695 100644 --- a/kclvm/sema/src/advanced_resolver/mod.rs +++ b/kclvm/sema/src/advanced_resolver/mod.rs @@ -287,7 +287,9 @@ mod tests { let path = "src/advanced_resolver/test_data/schema_symbols.k" .to_string() .replace("/", &std::path::MAIN_SEPARATOR.to_string()); - let mut program = load_program(sess.clone(), &[&path], None, None).unwrap(); + let mut program = load_program(sess.clone(), &[&path], None, None) + .unwrap() + .program; let gs = GlobalState::default(); let gs = Namer::find_symbols(&program, gs); @@ -1233,7 +1235,9 @@ mod tests { let path = "src/advanced_resolver/test_data/schema_symbols.k" .to_string() .replace("/", &std::path::MAIN_SEPARATOR.to_string()); - let mut program = load_program(sess.clone(), &[&path], None, None).unwrap(); + let mut program = load_program(sess.clone(), &[&path], None, None) + .unwrap() + .program; let gs = GlobalState::default(); let gs = Namer::find_symbols(&program, gs); let node_ty_map = resolver::resolve_program(&mut program).node_ty_map; @@ -1308,7 +1312,9 @@ mod tests { let path = "src/advanced_resolver/test_data/schema_symbols.k" .to_string() .replace("/", &std::path::MAIN_SEPARATOR.to_string()); - let mut program = load_program(sess.clone(), &[&path], None, None).unwrap(); + let mut program = load_program(sess.clone(), &[&path], None, None) + .unwrap() + .program; let gs = GlobalState::default(); let gs = Namer::find_symbols(&program, gs); let node_ty_map = resolver::resolve_program(&mut program).node_ty_map; diff --git a/kclvm/sema/src/core/global_state.rs b/kclvm/sema/src/core/global_state.rs index cf8e89371..c7fb9d3e2 100644 --- a/kclvm/sema/src/core/global_state.rs +++ b/kclvm/sema/src/core/global_state.rs @@ -15,7 +15,7 @@ pub struct GlobalState { symbols: KCLSymbolData, // store all allocated scopes scopes: ScopeData, - // store package infomation for name mapping + // store package information for name mapping packages: PackageDB, // store semantic information after analysis pub(crate) sema_db: SemanticDB, diff --git a/kclvm/sema/src/namer/mod.rs b/kclvm/sema/src/namer/mod.rs index d8364f098..e16f6c21e 100644 --- a/kclvm/sema/src/namer/mod.rs +++ b/kclvm/sema/src/namer/mod.rs @@ -272,7 +272,8 @@ mod tests { None, None, ) - .unwrap(); + .unwrap() + .program; let gs = GlobalState::default(); let gs = Namer::find_symbols(&program, gs); diff --git a/kclvm/sema/src/pre_process/multi_assign.rs b/kclvm/sema/src/pre_process/multi_assign.rs index 9b3e6faef..5425fa8ca 100644 --- a/kclvm/sema/src/pre_process/multi_assign.rs +++ b/kclvm/sema/src/pre_process/multi_assign.rs @@ -7,10 +7,10 @@ use kclvm_ast::{ast, walker::MutSelfMutWalker}; /// # Examples /// /// ``` -/// use kclvm_parser::parse_file; +/// use kclvm_parser::parse_file_force_errors; /// use kclvm_sema::pre_process::transform_multi_assign; /// -/// let mut module = parse_file("", Some("a = b = Config {}".to_string())).unwrap(); +/// let mut module = parse_file_force_errors("", Some("a = b = Config {}".to_string())).unwrap(); /// assert_eq!(module.body.len(), 1); /// transform_multi_assign(&mut module); /// assert_eq!(module.body.len(), 2); diff --git a/kclvm/sema/src/pre_process/tests.rs b/kclvm/sema/src/pre_process/tests.rs index 2af8fdb43..4d1a05bb7 100644 --- a/kclvm/sema/src/pre_process/tests.rs +++ b/kclvm/sema/src/pre_process/tests.rs @@ -3,12 +3,13 @@ use std::sync::Arc; use super::*; use indexmap::IndexMap; use kclvm_ast::path::get_attr_paths_from_config_expr; -use kclvm_parser::{load_program, parse_file, ParseSession}; +use kclvm_parser::{load_program, parse_file_force_errors, ParseSession}; #[test] fn test_fix_qualified_identifier() { let mut module = - parse_file("./src/pre_process/test_data/qualified_identifier.k", None).unwrap(); + parse_file_force_errors("./src/pre_process/test_data/qualified_identifier.k", None) + .unwrap(); fix_qualified_identifier(&mut module, &mut IndexMap::default()); if let ast::Stmt::Assign(assign_stmt) = &module.body[1].node { if let ast::Expr::Identifier(identifier) = &assign_stmt.value.node { @@ -23,7 +24,8 @@ fn test_fix_qualified_identifier() { #[test] fn test_fix_raw_identifier_prefix() { - let mut module = parse_file("./src/pre_process/test_data/raw_identifier.k", None).unwrap(); + let mut module = + parse_file_force_errors("./src/pre_process/test_data/raw_identifier.k", None).unwrap(); if let ast::Stmt::Assign(assign_stmt) = &module.body[0].node { assert_eq!(assign_stmt.targets[0].node.names[0].node, "$schema") } else { @@ -40,7 +42,8 @@ fn test_fix_raw_identifier_prefix() { #[test] fn test_transform_multi_assign() { let targets = ["a", "b", "c", "d"]; - let mut module = parse_file("./src/pre_process/test_data/multi_assign.k", None).unwrap(); + let mut module = + parse_file_force_errors("./src/pre_process/test_data/multi_assign.k", None).unwrap(); if let ast::Stmt::Assign(assign_stmt) = &module.body[1].node { assert_eq!(assign_stmt.targets.len(), targets.len()); for (i, target) in targets.iter().enumerate() { @@ -74,7 +77,8 @@ fn test_config_merge() { None, None, ) - .unwrap(); + .unwrap() + .program; merge_program(&mut program); let modules = program.pkgs.get_mut(kclvm_ast::MAIN_PKG).unwrap(); assert_eq!(modules.len(), 4); @@ -116,7 +120,8 @@ fn test_config_override() { None, None, ) - .unwrap(); + .unwrap() + .program; merge_program(&mut program); let modules = program.pkgs.get_mut(kclvm_ast::MAIN_PKG).unwrap(); assert_eq!(modules.len(), 1); @@ -160,7 +165,8 @@ fn test_skip_merge_program() { None, None, ) - .unwrap(); + .unwrap() + .program; // skip merge program and save raw config ast node // merge_program(&mut program); let modules = program.pkgs.get_mut(kclvm_ast::MAIN_PKG).unwrap(); diff --git a/kclvm/sema/src/resolver/tests.rs b/kclvm/sema/src/resolver/tests.rs index dfc141f61..4a8101a29 100644 --- a/kclvm/sema/src/resolver/tests.rs +++ b/kclvm/sema/src/resolver/tests.rs @@ -6,17 +6,39 @@ use crate::resolver::resolve_program; use crate::resolver::resolve_program_with_opts; use crate::resolver::scope::*; use crate::ty::{Type, TypeKind}; +use anyhow::Result; use kclvm_ast::ast; -use kclvm_ast::ast::CmdArgSpec; use kclvm_ast::pos::ContainsPos; use kclvm_error::*; +use kclvm_parser::load_program; +use kclvm_parser::parse_file_force_errors; use kclvm_parser::LoadProgramOptions; use kclvm_parser::ParseSession; -use kclvm_parser::{load_program, parse_program}; +use kclvm_utils::path::PathPrefix; +use std::collections::HashMap; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; +pub fn parse_program(filename: &str) -> Result { + let abspath = std::fs::canonicalize(std::path::PathBuf::from(filename)).unwrap(); + + let mut prog = ast::Program { + root: abspath.parent().unwrap().adjust_canonicalization(), + pkgs: HashMap::new(), + }; + + 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 + .insert(kclvm_ast::MAIN_PKG.to_string(), vec![module]); + + Ok(prog) +} + #[test] fn test_scope() { let mut scope = builtin_scope(); @@ -87,7 +109,8 @@ fn test_pkg_init_in_schema_resolve() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!( scope.pkgpaths(), @@ -151,7 +174,8 @@ fn test_resolve_program_redefine() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 2); @@ -190,7 +214,8 @@ fn test_resolve_program_cycle_reference_fail() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); let err_messages = [ "There is a circular import reference between module file1 and file2", @@ -216,7 +241,8 @@ fn test_record_used_module() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); let main_scope = scope .scope_map @@ -335,7 +361,8 @@ fn test_lint() { None, None, ) - .unwrap(); + .unwrap() + .program; let opts = Options::default(); pre_process_program(&mut program, &opts); let mut resolver = Resolver::new(&program, opts); @@ -480,7 +507,8 @@ fn test_pkg_scope() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.scope_map.len(), 2); @@ -530,7 +558,8 @@ fn test_system_package() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); let main_scope = scope .scope_map @@ -563,7 +592,8 @@ fn test_resolve_program_import_suggest() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 2); let diag = &scope.handler.diagnostics[0]; @@ -587,7 +617,8 @@ fn test_resolve_assignment_in_lambda() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); let main_scope = scope.scope_map.get("__main__").unwrap().clone(); assert_eq!(main_scope.borrow().children.len(), 1); @@ -606,7 +637,8 @@ fn test_resolve_function_with_default_values() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert!(!scope.handler.has_errors()); let main_scope = scope.main_scope().unwrap(); @@ -622,24 +654,15 @@ fn test_resolve_function_with_default_values() { #[test] fn test_assignment_type_annotation_check_in_lambda() { let sess = Arc::new(ParseSession::default()); - let mut opts = LoadProgramOptions::default(); - opts.cmd_args = vec![ - CmdArgSpec { - name: "params".to_string(), - value: "annotations: {a: b}".to_string(), - }, - CmdArgSpec { - name: "items".to_string(), - value: "metadata: {annotations:{c: d}}".to_string(), - }, - ]; + let opts = LoadProgramOptions::default(); let mut program = load_program( sess.clone(), &["./src/resolver/test_data/annotation_check_assignment.k"], Some(opts), None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 0); } @@ -653,7 +676,8 @@ fn test_resolve_lambda_assignment_diagnostic() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 1); let diag = &scope.handler.diagnostics[0]; @@ -674,7 +698,8 @@ fn test_ty_check_in_dict_assign_to_schema() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 1); let diag = &scope.handler.diagnostics[0]; @@ -696,7 +721,8 @@ fn test_pkg_not_found_suggestion() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 4); let diag = &scope.handler.diagnostics[1]; @@ -724,7 +750,8 @@ fn undef_lambda_param() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 1); @@ -762,7 +789,8 @@ fn test_schema_params_count() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); assert_eq!(scope.handler.diagnostics.len(), 1); let diag = &scope.handler.diagnostics[0]; @@ -786,7 +814,8 @@ fn test_set_ty_in_lambda() { None, None, ) - .unwrap(); + .unwrap() + .program; assert_eq!( resolve_program(&mut program) .main_scope() @@ -811,7 +840,8 @@ fn test_pkg_asname() { None, None, ) - .unwrap(); + .unwrap() + .program; let scope = resolve_program(&mut program); let diags = scope.handler.diagnostics; assert_eq!(diags.len(), 6); diff --git a/kclvm/spec/gpyrpc/gpyrpc.proto b/kclvm/spec/gpyrpc/gpyrpc.proto index 52379892d..902110824 100644 --- a/kclvm/spec/gpyrpc/gpyrpc.proto +++ b/kclvm/spec/gpyrpc/gpyrpc.proto @@ -6,11 +6,6 @@ syntax = "proto3"; package gpyrpc; -import "google/protobuf/any.proto"; -import "google/protobuf/descriptor.proto"; - -// ---------------------------------------------------------------------------- - // kcl main.k -E pkg_name=pkg_path message CmdExternalPkgSpec { string pkg_name = 1; @@ -32,29 +27,18 @@ message CmdOverrideSpec { } // ---------------------------------------------------------------------------- -// gpyrpc request/response/error types +// Error types // ---------------------------------------------------------------------------- -message RestResponse { - google.protobuf.Any result = 1; - string error = 2; - KclError kcl_err = 3; +message Error { + string level = 1; + string code = 2; + repeated Message messages = 3; } -message KclError { - string ewcode = 1; // See kclvm/kcl/error/kcl_err_msg.py - string name = 2; - string msg = 3; - repeated KclErrorInfo error_infos = 4; -} - -message KclErrorInfo { - string err_level = 1; - string arg_msg = 2; - string filename = 3; - string src_code = 4; - string line_no = 5; - string col_no = 6; +message Message { + string msg = 1; + Position pos = 2; } // ---------------------------------------------------------------------------- @@ -73,6 +57,9 @@ service KclvmService { rpc ExecProgram(ExecProgram_Args) returns(ExecProgram_Result); + rpc ParseFile(ParseFile_Args) returns(ParseFile_Result); + rpc ParseProgram(ParseProgram_Args) returns(ParseProgram_Result); + rpc FormatCode(FormatCode_Args) returns(FormatCode_Result); rpc FormatPath(FormatPath_Args) returns(FormatPath_Result); rpc LintPath(LintPath_Args) returns(LintPath_Result); @@ -106,21 +93,28 @@ message ListMethod_Result { repeated string method_name_list = 1; } -message ParseFile_AST_Args { - string filename = 1; - string source_code = 2; +message ParseFile_Args { + string path = 1; + string source = 2; + repeated CmdExternalPkgSpec external_pkgs = 3; // External packages path } -message ParseFile_AST_Result { - string ast_json = 1; // json value - KclError kcl_err = 2; + +message ParseFile_Result { + string ast_json = 1; // JSON string value + repeated string deps = 2; // file dependency paths + repeated Error errors = 3; // Parse errors } -message ParseProgram_AST_Args { - repeated string k_filename_list = 1; +message ParseProgram_Args { + repeated string paths = 1; + repeated string sources = 2; + repeated CmdExternalPkgSpec external_pkgs = 3; // External packages path } -message ParseProgram_AST_Result { - string ast_json = 1; // json value - KclError kcl_err = 2; + +message ParseProgram_Result { + string ast_json = 1; // JSON string value + repeated string paths = 2; // Return the files in the order they should be compiled + repeated Error errors = 3; // Parse errors } message ExecProgram_Args { @@ -159,9 +153,6 @@ message ExecProgram_Args { // Whether only compiling the program bool compile_only = 15; - // Compile the dir recursively - bool recursive = 16; - // -S --path_selector repeated string path_selector = 17; } diff --git a/kclvm/tools/Cargo.toml b/kclvm/tools/Cargo.toml index c002f14de..0fb9b3730 100644 --- a/kclvm/tools/Cargo.toml +++ b/kclvm/tools/Cargo.toml @@ -36,6 +36,7 @@ located_yaml = "0.2.1" [dev-dependencies] pretty_assertions = "1.2.1" criterion = "0.3" +insta = "1.8.0" [[bench]] name = "benchmark" diff --git a/kclvm/tools/src/LSP/src/rename.rs b/kclvm/tools/src/LSP/src/rename.rs index d8695a7f7..ec8ff847f 100644 --- a/kclvm/tools/src/LSP/src/rename.rs +++ b/kclvm/tools/src/LSP/src/rename.rs @@ -131,7 +131,7 @@ where let file_paths = package_path_to_file_path(pkg_path, vfs.clone()); - if let Ok((prog, gs)) = parse_files_with_vfs( + if let Ok((_, gs)) = parse_files_with_vfs( pkg_path.to_string(), file_paths, vfs.clone(), @@ -139,7 +139,7 @@ where ) { if let Some(symbol_ref) = gs .get_symbols() - .get_symbol_by_fully_qualified_name(&prog.main) + .get_symbol_by_fully_qualified_name(&kclvm_ast::MAIN_PKG) { let mut owner_ref = symbol_ref; let mut target = None; @@ -186,8 +186,7 @@ where let files: Vec<&str> = file_paths.iter().map(|s| s.as_str()).collect(); let sess: Arc = Arc::new(ParseSession::default()); - let mut program = load_program(sess.clone(), &files, Some(opt), None) - .map_err(|err| anyhow::anyhow!("Compile failed: {}", err))?; + let mut program = load_program(sess.clone(), &files, Some(opt), None)?.program; let prog_scope = resolve_program_with_opts( &mut program, diff --git a/kclvm/tools/src/LSP/src/util.rs b/kclvm/tools/src/LSP/src/util.rs index 38841f92d..990d95f7e 100644 --- a/kclvm/tools/src/LSP/src/util.rs +++ b/kclvm/tools/src/LSP/src/util.rs @@ -83,8 +83,7 @@ pub(crate) fn parse_param_and_compile( opt.k_code_list.append(&mut k_code_list); } let sess = Arc::new(ParseSession::default()); - let mut program = load_program(sess.clone(), &files, Some(opt), param.module_cache) - .map_err(|err| anyhow::anyhow!("Compile failed: {}", err))?; + let mut program = load_program(sess.clone(), &files, Some(opt), param.module_cache)?.program; let prog_scope = resolve_program_with_opts( &mut program, diff --git a/kclvm/tools/src/format/mod.rs b/kclvm/tools/src/format/mod.rs index a566f63f8..9d81901e9 100644 --- a/kclvm/tools/src/format/mod.rs +++ b/kclvm/tools/src/format/mod.rs @@ -10,7 +10,7 @@ use kclvm_ast_pretty::print_ast_module; use kclvm_driver::get_kcl_files; use std::path::Path; -use kclvm_parser::{parse_file, parse_file_with_errors}; +use kclvm_parser::{parse_file, parse_file_force_errors}; #[cfg(test)] mod tests; @@ -84,13 +84,9 @@ pub fn format_file(file: &str, opts: &FormatOptions) -> Result { /// whether the source is changed. pub fn format_source(file: &str, src: &str, opts: &FormatOptions) -> Result<(String, bool)> { let module = if opts.omit_errors { - let (module, err) = parse_file_with_errors(file, Some(src.to_string())); - match module { - Some(module) => module, - None => return Err(anyhow::anyhow!(err)), - } + parse_file(file, Some(src.to_string()))?.module } else { - parse_file(file, Some(src.to_string())).map_err(|err| anyhow::anyhow!(err))? + parse_file_force_errors(file, Some(src.to_string()))? }; let formatted_src = print_ast_module(&module); let is_formatted = src != formatted_src; diff --git a/kclvm/tools/src/format/tests.rs b/kclvm/tools/src/format/tests.rs index 9694b2d0e..a76abc70f 100644 --- a/kclvm/tools/src/format/tests.rs +++ b/kclvm/tools/src/format/tests.rs @@ -1,5 +1,5 @@ use super::*; -use kclvm_parser::parse_file; +use kclvm_parser::parse_file_force_errors; use pretty_assertions::assert_eq; use walkdir::WalkDir; @@ -32,7 +32,7 @@ const TEST_CASES: &[&str; 22] = &[ ]; fn read_data(data_name: &str) -> (String, String) { - let src = std::fs::read_to_string(&format!( + let src = std::fs::read_to_string(format!( "./src/format/test_data/format_data/{}{}", data_name, FILE_INPUT_SUFFIX )) @@ -40,7 +40,7 @@ fn read_data(data_name: &str) -> (String, String) { ( format_source("", &src, &Default::default()).unwrap().0, - std::fs::read_to_string(&format!( + std::fs::read_to_string(format!( "./src/format/test_data/format_data/{}{}", data_name, FILE_OUTPUT_SUFFIX )) @@ -187,17 +187,17 @@ fn test_format_integration_konfig() -> Result<()> { let files = get_files(konfig_path, true, true, ".k"); for file in &files { // Skip test and hidden files. - if file.ends_with("_test.k") || file.starts_with("_") { + if file.ends_with("_test.k") || file.starts_with('_') { continue; } assert!( - parse_file(file, None).is_ok(), + parse_file_force_errors(file, None).is_ok(), "file {} test format failed", file ); let src = std::fs::read_to_string(file)?; let (formatted_src, _) = format_source("", &src, &Default::default())?; - let parse_result = parse_file("test.k", Some(formatted_src.clone() + "\n")); + let parse_result = parse_file_force_errors("test.k", Some(formatted_src.clone() + "\n")); assert!( parse_result.is_ok(), "file {} test format failed, the formatted source is\n{}\n the parse error is\n{}", diff --git a/kclvm/tools/src/lint/mod.rs b/kclvm/tools/src/lint/mod.rs index c2340d8d4..4a0b66fb5 100644 --- a/kclvm/tools/src/lint/mod.rs +++ b/kclvm/tools/src/lint/mod.rs @@ -74,10 +74,10 @@ pub fn lint_files( let mut opts = opts.unwrap_or_default(); opts.load_plugins = true; let mut program = match load_program(sess.clone(), files, Some(opts), None) { - Ok(p) => p, + Ok(p) => p.program, Err(err_str) => { return Handler::default() - .add_panic_info(&PanicInfo::from(err_str)) + .add_panic_info(&PanicInfo::from(err_str.to_string())) .classification(); } }; diff --git a/kclvm/tools/src/testing/suite.rs b/kclvm/tools/src/testing/suite.rs index c56229e5c..c03058ff6 100644 --- a/kclvm/tools/src/testing/suite.rs +++ b/kclvm/tools/src/testing/suite.rs @@ -5,7 +5,7 @@ use anyhow::{anyhow, Result}; use indexmap::IndexMap; use kclvm_ast::ast; use kclvm_driver::{get_kcl_files, get_pkg_list}; -use kclvm_parser::{parse_file, ParseSession}; +use kclvm_parser::{parse_file_force_errors, ParseSession}; use kclvm_runner::runner::ProgramRunner; use kclvm_runner::{build_program, ExecProgramArgs}; use std::sync::Arc; @@ -129,13 +129,13 @@ pub struct TestCase; /// Load test suite from path pub fn load_test_suites>(path: P, opts: &TestOptions) -> Result> { - let pkg_list = get_pkg_list(&path.as_ref())?; + let pkg_list = get_pkg_list(path.as_ref())?; let mut suites = vec![]; for pkg in &pkg_list { let (normal_files, test_files) = get_test_files(pkg)?; let mut cases = IndexMap::new(); for file in &test_files { - let module = parse_file(file, None).map_err(|e| anyhow!(e))?; + let module = parse_file_force_errors(file, None)?; for stmt in &module.body { if let ast::Stmt::Assign(assign_stmt) = &stmt.node { if let ast::Expr::Lambda(_lambda_expr) = &assign_stmt.value.node { @@ -166,12 +166,12 @@ fn get_test_files>(pkg: P) -> Result<(Vec, Vec)> let files = get_kcl_files(pkg, false)?; let normal_files = files .iter() - .filter(|x| !x.starts_with("_") && !x.ends_with(TEST_FILE_SUFFIX)) + .filter(|x| !x.starts_with('_') && !x.ends_with(TEST_FILE_SUFFIX)) .cloned() .collect::>(); let test_files = files .iter() - .filter(|x| !x.starts_with("_") && x.ends_with(TEST_FILE_SUFFIX)) + .filter(|x| !x.starts_with('_') && x.ends_with(TEST_FILE_SUFFIX)) .cloned() .collect::>(); Ok((normal_files, test_files)) diff --git a/kclvm/tools/src/vet/expr_builder.rs b/kclvm/tools/src/vet/expr_builder.rs index d77190bd0..db34a1d76 100644 --- a/kclvm/tools/src/vet/expr_builder.rs +++ b/kclvm/tools/src/vet/expr_builder.rs @@ -236,8 +236,8 @@ impl ExprGenerator for ExprBuilder { } } located_yaml::YamlElt::Real(j_float) => { - if let Some(number_lit) = j_float.parse::().ok() { - if format!("{}", number_lit) != j_float.to_string() { + if let Ok(number_lit) = j_float.parse::() { + if format!("{}", number_lit) != *j_float { bail!("{FAIL_LOAD_VALIDATED_ERR_MSG}, Unsupported Number Type",) } Ok(node_ref!( @@ -314,10 +314,10 @@ impl ExprGenerator for ExprBuilder { names: vec![Node::new( s_name.to_string(), loc.0.clone(), - loc.1.clone() as u64, - loc.2.clone() as u64, - loc.3.clone() as u64, - loc.4.clone() as u64 + loc.1, + loc.2, + loc.3, + loc.4 )], pkgpath: String::new(), ctx: ExprContext::Load @@ -363,7 +363,7 @@ impl ExprGenerator> for E loc )), json_spanned_value::Value::Bool(j_bool) => { - let name_const = match NameConstant::try_from(j_bool.clone()) { + let name_const = match NameConstant::try_from(*j_bool) { Ok(nc) => nc, Err(err) => { bail!("{FAIL_LOAD_VALIDATED_ERR_MSG}, {err}") @@ -483,10 +483,10 @@ impl ExprGenerator> for E names: vec![Node::new( s_name.to_string(), loc.0.clone(), - loc.1.clone(), - loc.2.clone(), - loc.3.clone(), - loc.4.clone() + loc.1, + loc.2, + loc.3, + loc.4 )], pkgpath: String::new(), ctx: ExprContext::Load diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-2.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-2.snap new file mode 100644 index 000000000..b152b25a5 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-2.snap @@ -0,0 +1,178 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "/simple.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "/simple.k.json", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "/simple.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 30, + "end_line": 4, + "filename": "/simple.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/simple.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 19, + "end_line": 2, + "filename": "/simple.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": "simple" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-3.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-3.snap new file mode 100644 index 000000000..c0a67c0ca --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-3.snap @@ -0,0 +1,21 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 1, + "filename": "/plain_value.k.json", + "line": 1, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-4.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-4.snap new file mode 100644 index 000000000..f6da78b6f --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-4.snap @@ -0,0 +1,193 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 7, + "filename": "/list.k.json", + "line": 1, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "data": { + "args": [], + "config": { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "data": { + "items": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 13, + "end_line": 4, + "filename": "/list.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 17, + "end_line": 4, + "filename": "/list.k.json", + "line": 4, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 17, + "end_line": 5, + "filename": "/list.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 19, + "end_column": 34, + "end_line": 5, + "filename": "/list.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 14, + "end_line": 3, + "filename": "/list.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 16, + "end_column": 23, + "end_line": 3, + "filename": "/list.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "ctx": "Load", + "names": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": "list" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } + } + ] + }, + "type": "List" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-5.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-5.snap new file mode 100644 index 000000000..43900de05 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-5.snap @@ -0,0 +1,475 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "/complex.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "/complex.k.json", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 5, + "filename": "/complex.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"data\"", + "value": "data" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "/complex.k.json", + "line": 5, + "node": { + "data": { + "items": [ + { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "/complex.k.json", + "line": 5, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 12, + "end_line": 6, + "filename": "/complex.k.json", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"id\"", + "value": "id" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 15, + "end_line": 6, + "filename": "/complex.k.json", + "line": 6, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "/complex.k.json", + "line": 5, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 15, + "end_line": 7, + "filename": "/complex.k.json", + "line": 7, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value\"", + "value": "value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 17, + "end_column": 25, + "end_line": 7, + "filename": "/complex.k.json", + "line": 7, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value1\"", + "value": "value1" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 8, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"hc\"", + "value": "hc" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 10, + "end_column": 19, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 11, + "end_column": 12, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } + }, + { + "column": 14, + "end_column": 15, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 2, + "type": "Int" + } + }, + "type": "NumberLit" + } + }, + { + "column": 17, + "end_column": 18, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 3, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + ] + }, + "type": "List" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 12, + "end_line": 9, + "filename": "/complex.k.json", + "line": 9, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"labels\"", + "value": "labels" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "/complex.k.json", + "line": 9, + "node": { + "data": { + "items": [ + { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "/complex.k.json", + "line": 9, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 13, + "end_line": 10, + "filename": "/complex.k.json", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"key\"", + "value": "key" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 22, + "end_line": 10, + "filename": "/complex.k.json", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value\"", + "value": "value" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "/complex.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 30, + "end_line": 4, + "filename": "/complex.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/complex.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 19, + "end_line": 2, + "filename": "/complex.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": "complex" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-6.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-6.snap new file mode 100644 index 000000000..3f1c948fc --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-6.snap @@ -0,0 +1,92 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_null.json", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_null.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_null.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 16, + "end_line": 2, + "filename": "/only_with_null.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"null_value\"", + "value": "null_value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 18, + "end_column": 22, + "end_line": 2, + "filename": "/only_with_null.json", + "line": 2, + "node": { + "data": { + "value": "None" + }, + "type": "NameConstantLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_null.json", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_null.json", + "line": 1, + "node": "only_with_null" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-7.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-7.snap new file mode 100644 index 000000000..e430214ea --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-7.snap @@ -0,0 +1,92 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_bool.json", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_bool.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_bool.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/only_with_bool.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"flag\"", + "value": "flag" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 16, + "end_line": 2, + "filename": "/only_with_bool.json", + "line": 2, + "node": { + "data": { + "value": "True" + }, + "type": "NameConstantLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_bool.json", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_bool.json", + "line": 1, + "node": "only_with_bool" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-8.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-8.snap new file mode 100644 index 000000000..43d2bbb61 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath-8.snap @@ -0,0 +1,96 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_float.json", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_float.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_float.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 17, + "end_line": 2, + "filename": "/only_with_float.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"float_value\"", + "value": "float_value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 19, + "end_column": 23, + "end_line": 2, + "filename": "/only_with_float.json", + "line": 2, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 0.33, + "type": "Float" + } + }, + "type": "NumberLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_float.json", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_float.json", + "line": 1, + "node": "only_with_float" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath.snap new file mode 100644 index 000000000..ca6062cef --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_filepath.snap @@ -0,0 +1,331 @@ +--- +source: tools/src/vet/tests.rs +assertion_line: 215 +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "/test.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"address\"", + "value": "address" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "/test.k.json", + "line": 4, + "node": { + "data": { + "items": [ + { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "/test.k.json", + "line": 4, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 14, + "end_line": 6, + "filename": "/test.k.json", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"city\"", + "value": "city" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 16, + "end_column": 24, + "end_line": 6, + "filename": "/test.k.json", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"London\"", + "value": "London" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "/test.k.json", + "line": 4, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 16, + "end_line": 5, + "filename": "/test.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"street\"", + "value": "street" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 18, + "end_column": 37, + "end_line": 5, + "filename": "/test.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"10 Downing Street\"", + "value": "10 Downing Street" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "/test.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "/test.k.json", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 43, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/test.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 22, + "end_line": 2, + "filename": "/test.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"John Doe\"", + "value": "John Doe" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 12, + "end_line": 8, + "filename": "/test.k.json", + "line": 8, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"phones\"", + "value": "phones" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "/test.k.json", + "line": 8, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 8, + "end_column": 21, + "end_line": 9, + "filename": "/test.k.json", + "line": 9, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"+44 1234567\"", + "value": "+44 1234567" + }, + "type": "StringLit" + } + }, + { + "column": 8, + "end_column": 21, + "end_line": 10, + "filename": "/test.k.json", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"+44 2345678\"", + "value": "+44 2345678" + }, + "type": "StringLit" + } + } + ] + }, + "type": "List" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": "test" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-2.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-2.snap new file mode 100644 index 000000000..79977221b --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-2.snap @@ -0,0 +1,178 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 30, + "end_line": 4, + "filename": "", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 19, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "", + "line": 1, + "node": "simple" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-3.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-3.snap new file mode 100644 index 000000000..2c8b0b66f --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-3.snap @@ -0,0 +1,21 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 1, + "filename": "", + "line": 1, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-4.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-4.snap new file mode 100644 index 000000000..0408509ad --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-4.snap @@ -0,0 +1,193 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 7, + "filename": "", + "line": 1, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "", + "line": 2, + "node": { + "data": { + "args": [], + "config": { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "", + "line": 2, + "node": { + "data": { + "items": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 13, + "end_line": 4, + "filename": "", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 17, + "end_line": 4, + "filename": "", + "line": 4, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 17, + "end_line": 5, + "filename": "", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 19, + "end_column": 34, + "end_line": 5, + "filename": "", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 14, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 16, + "end_column": 23, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "", + "line": 2, + "node": { + "ctx": "Load", + "names": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "", + "line": 2, + "node": "list" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } + } + ] + }, + "type": "List" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-5.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-5.snap new file mode 100644 index 000000000..4572c6acb --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-5.snap @@ -0,0 +1,475 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 5, + "filename": "", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"data\"", + "value": "data" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "", + "line": 5, + "node": { + "data": { + "items": [ + { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "", + "line": 5, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 12, + "end_line": 6, + "filename": "", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"id\"", + "value": "id" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 15, + "end_line": 6, + "filename": "", + "line": 6, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "", + "line": 5, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 15, + "end_line": 7, + "filename": "", + "line": 7, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value\"", + "value": "value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 17, + "end_column": 25, + "end_line": 7, + "filename": "", + "line": 7, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value1\"", + "value": "value1" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 8, + "end_line": 12, + "filename": "", + "line": 12, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"hc\"", + "value": "hc" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 10, + "end_column": 19, + "end_line": 12, + "filename": "", + "line": 12, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 11, + "end_column": 12, + "end_line": 12, + "filename": "", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } + }, + { + "column": 14, + "end_column": 15, + "end_line": 12, + "filename": "", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 2, + "type": "Int" + } + }, + "type": "NumberLit" + } + }, + { + "column": 17, + "end_column": 18, + "end_line": 12, + "filename": "", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 3, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + ] + }, + "type": "List" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 12, + "end_line": 9, + "filename": "", + "line": 9, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"labels\"", + "value": "labels" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "", + "line": 9, + "node": { + "data": { + "items": [ + { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "", + "line": 9, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 13, + "end_line": 10, + "filename": "", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"key\"", + "value": "key" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 22, + "end_line": 10, + "filename": "", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value\"", + "value": "value" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 30, + "end_line": 4, + "filename": "", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 19, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "", + "line": 1, + "node": "complex" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-6.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-6.snap new file mode 100644 index 000000000..56b1ae6fd --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-6.snap @@ -0,0 +1,92 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 16, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"null_value\"", + "value": "null_value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 18, + "end_column": 22, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "value": "None" + }, + "type": "NameConstantLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": "only_with_null" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-7.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-7.snap new file mode 100644 index 000000000..baecbf3c2 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-7.snap @@ -0,0 +1,92 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"flag\"", + "value": "flag" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 16, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "value": "True" + }, + "type": "NameConstantLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": "only_with_bool" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-8.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-8.snap new file mode 100644 index 000000000..9608c19a4 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str-8.snap @@ -0,0 +1,96 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 17, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"float_value\"", + "value": "float_value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 19, + "end_column": 23, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 0.33, + "type": "Float" + } + }, + "type": "NumberLit" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "", + "line": 1, + "node": "only_with_float" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str.snap new file mode 100644 index 000000000..208e092cb --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_json_with_str.snap @@ -0,0 +1,330 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": { + "data": { + "args": [], + "config": { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"address\"", + "value": "address" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "", + "line": 4, + "node": { + "data": { + "items": [ + { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "", + "line": 4, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 14, + "end_line": 6, + "filename": "", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"city\"", + "value": "city" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 16, + "end_column": 24, + "end_line": 6, + "filename": "", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"London\"", + "value": "London" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "", + "line": 4, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 16, + "end_line": 5, + "filename": "", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"street\"", + "value": "street" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 18, + "end_column": 37, + "end_line": 5, + "filename": "", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"10 Downing Street\"", + "value": "10 Downing Street" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 43, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 22, + "end_line": 2, + "filename": "", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"John Doe\"", + "value": "John Doe" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 12, + "end_line": 8, + "filename": "", + "line": 8, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"phones\"", + "value": "phones" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "", + "line": 8, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 8, + "end_column": 21, + "end_line": 9, + "filename": "", + "line": 9, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"+44 1234567\"", + "value": "+44 1234567" + }, + "type": "StringLit" + } + }, + { + "column": 8, + "end_column": 21, + "end_line": 10, + "filename": "", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"+44 2345678\"", + "value": "+44 2345678" + }, + "type": "StringLit" + } + } + ] + }, + "type": "List" + } + } + } + } + ] + }, + "type": "Config" + } + }, + "kwargs": [], + "name": { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": { + "ctx": "Load", + "names": [ + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "", + "line": 1, + "node": "test" + } + ], + "pkgpath": "" + } + } + }, + "type": "Schema" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-2.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-2.snap new file mode 100644 index 000000000..c40cb2683 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-2.snap @@ -0,0 +1,143 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "/simple.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "/simple.k.json", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "/simple.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 30, + "end_line": 4, + "filename": "/simple.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 5, + "filename": "/simple.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/simple.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 19, + "end_line": 2, + "filename": "/simple.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-3.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-3.snap new file mode 100644 index 000000000..c0a67c0ca --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-3.snap @@ -0,0 +1,21 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 1, + "filename": "/plain_value.k.json", + "line": 1, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-4.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-4.snap new file mode 100644 index 000000000..05e84deb1 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-4.snap @@ -0,0 +1,158 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 7, + "filename": "/list.k.json", + "line": 1, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "data": { + "items": [ + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 13, + "end_line": 4, + "filename": "/list.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 17, + "end_line": 4, + "filename": "/list.k.json", + "line": 4, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 17, + "end_line": 5, + "filename": "/list.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 19, + "end_column": 34, + "end_line": 5, + "filename": "/list.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 4, + "end_column": 5, + "end_line": 6, + "filename": "/list.k.json", + "line": 2, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 14, + "end_line": 3, + "filename": "/list.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 16, + "end_column": 23, + "end_line": 3, + "filename": "/list.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + ] + }, + "type": "List" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-5.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-5.snap new file mode 100644 index 000000000..b91224bfb --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-5.snap @@ -0,0 +1,440 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "/complex.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "/complex.k.json", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 18, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 5, + "filename": "/complex.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"data\"", + "value": "data" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "/complex.k.json", + "line": 5, + "node": { + "data": { + "items": [ + { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "/complex.k.json", + "line": 5, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 12, + "end_line": 6, + "filename": "/complex.k.json", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"id\"", + "value": "id" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 15, + "end_line": 6, + "filename": "/complex.k.json", + "line": 6, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 12, + "end_column": 5, + "end_line": 8, + "filename": "/complex.k.json", + "line": 5, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 15, + "end_line": 7, + "filename": "/complex.k.json", + "line": 7, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value\"", + "value": "value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 17, + "end_column": 25, + "end_line": 7, + "filename": "/complex.k.json", + "line": 7, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value1\"", + "value": "value1" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 8, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"hc\"", + "value": "hc" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 10, + "end_column": 19, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 11, + "end_column": 12, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 1, + "type": "Int" + } + }, + "type": "NumberLit" + } + }, + { + "column": 14, + "end_column": 15, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 2, + "type": "Int" + } + }, + "type": "NumberLit" + } + }, + { + "column": 17, + "end_column": 18, + "end_line": 12, + "filename": "/complex.k.json", + "line": 12, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 3, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + ] + }, + "type": "List" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 12, + "end_line": 9, + "filename": "/complex.k.json", + "line": 9, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"labels\"", + "value": "labels" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "/complex.k.json", + "line": 9, + "node": { + "data": { + "items": [ + { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "/complex.k.json", + "line": 9, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 13, + "end_line": 10, + "filename": "/complex.k.json", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"key\"", + "value": "key" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 22, + "end_line": 10, + "filename": "/complex.k.json", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"value\"", + "value": "value" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "/complex.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"message\"", + "value": "message" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 30, + "end_line": 4, + "filename": "/complex.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"This is Alice\"", + "value": "This is Alice" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 13, + "filename": "/complex.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/complex.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 19, + "end_line": 2, + "filename": "/complex.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"Alice\"", + "value": "Alice" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-6.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-6.snap new file mode 100644 index 000000000..0d1fe32ae --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-6.snap @@ -0,0 +1,57 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_null.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_null.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 16, + "end_line": 2, + "filename": "/only_with_null.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"null_value\"", + "value": "null_value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 18, + "end_column": 22, + "end_line": 2, + "filename": "/only_with_null.json", + "line": 2, + "node": { + "data": { + "value": "None" + }, + "type": "NameConstantLit" + } + } + } + } + ] + }, + "type": "Config" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-7.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-7.snap new file mode 100644 index 000000000..37b76912b --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-7.snap @@ -0,0 +1,57 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_bool.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_bool.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/only_with_bool.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"flag\"", + "value": "flag" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 16, + "end_line": 2, + "filename": "/only_with_bool.json", + "line": 2, + "node": { + "data": { + "value": "True" + }, + "type": "NameConstantLit" + } + } + } + } + ] + }, + "type": "Config" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-8.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-8.snap new file mode 100644 index 000000000..bb103ea8f --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name-8.snap @@ -0,0 +1,61 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_float.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 3, + "filename": "/only_with_float.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 17, + "end_line": 2, + "filename": "/only_with_float.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"float_value\"", + "value": "float_value" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 19, + "end_column": 23, + "end_line": 2, + "filename": "/only_with_float.json", + "line": 2, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 0.33, + "type": "Float" + } + }, + "type": "NumberLit" + } + } + } + } + ] + }, + "type": "Config" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name.snap new file mode 100644 index 000000000..6f0d1edc3 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_json_no_schema_name.snap @@ -0,0 +1,295 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_json_str +--- +{ + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "data": { + "items": [ + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 13, + "end_line": 4, + "filename": "/test.k.json", + "line": 4, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"address\"", + "value": "address" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "/test.k.json", + "line": 4, + "node": { + "data": { + "items": [ + { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "/test.k.json", + "line": 4, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 14, + "end_line": 6, + "filename": "/test.k.json", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"city\"", + "value": "city" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 16, + "end_column": 24, + "end_line": 6, + "filename": "/test.k.json", + "line": 6, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"London\"", + "value": "London" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 15, + "end_column": 5, + "end_line": 7, + "filename": "/test.k.json", + "line": 4, + "node": { + "insert_index": -1, + "key": { + "column": 8, + "end_column": 16, + "end_line": 5, + "filename": "/test.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"street\"", + "value": "street" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 18, + "end_column": 37, + "end_line": 5, + "filename": "/test.k.json", + "line": 5, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"10 Downing Street\"", + "value": "10 Downing Street" + }, + "type": "StringLit" + } + } + } + } + ] + }, + "type": "Config" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 9, + "end_line": 3, + "filename": "/test.k.json", + "line": 3, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"age\"", + "value": "age" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 11, + "end_column": 13, + "end_line": 3, + "filename": "/test.k.json", + "line": 3, + "node": { + "data": { + "binary_suffix": null, + "value": { + "data": 43, + "type": "Int" + } + }, + "type": "NumberLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 10, + "end_line": 2, + "filename": "/test.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"name\"", + "value": "name" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 12, + "end_column": 22, + "end_line": 2, + "filename": "/test.k.json", + "line": 2, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"John Doe\"", + "value": "John Doe" + }, + "type": "StringLit" + } + } + } + }, + { + "column": 0, + "end_column": 1, + "end_line": 12, + "filename": "/test.k.json", + "line": 1, + "node": { + "insert_index": -1, + "key": { + "column": 4, + "end_column": 12, + "end_line": 8, + "filename": "/test.k.json", + "line": 8, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"phones\"", + "value": "phones" + }, + "type": "StringLit" + } + }, + "operation": "Union", + "value": { + "column": 14, + "end_column": 5, + "end_line": 11, + "filename": "/test.k.json", + "line": 8, + "node": { + "data": { + "ctx": "Load", + "elts": [ + { + "column": 8, + "end_column": 21, + "end_line": 9, + "filename": "/test.k.json", + "line": 9, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"+44 1234567\"", + "value": "+44 1234567" + }, + "type": "StringLit" + } + }, + { + "column": 8, + "end_column": 21, + "end_line": 10, + "filename": "/test.k.json", + "line": 10, + "node": { + "data": { + "is_long_string": false, + "raw_value": "\"+44 2345678\"", + "value": "+44 2345678" + }, + "type": "StringLit" + } + } + ] + }, + "type": "List" + } + } + } + } + ] + }, + "type": "Config" + } +} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-2.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-2.snap new file mode 100644 index 000000000..41af3f7fc --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-2.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"name\"","value":"name"}},"filename":"/simple.k.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Alice,\"","value":"Alice,"}},"filename":"/simple.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"age\"","value":"age"}},"filename":"/simple.k.yaml","line":2,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"18,\"","value":"18,"}},"filename":"/simple.k.yaml","line":2,"column":5,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"message\"","value":"message"}},"filename":"/simple.k.yaml","line":3,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"This is Alice\"","value":"This is Alice"}},"filename":"/simple.k.yaml","line":3,"column":9,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}]}},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-3.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-3.snap new file mode 100644 index 000000000..65c907127 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-3.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":1}}},"filename":"/plain_value.k.yaml","line":1,"column":0,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-4.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-4.snap new file mode 100644 index 000000000..ad1351be4 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-4.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"List","data":{"elts":[{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"name\"","value":"name"}},"filename":"/list.k.yaml","line":1,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Alice\"","value":"Alice"}},"filename":"/list.k.yaml","line":1,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"age\"","value":"age"}},"filename":"/list.k.yaml","line":2,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":18}}},"filename":"/list.k.yaml","line":2,"column":7,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"message\"","value":"message"}},"filename":"/list.k.yaml","line":3,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"This is Alice\"","value":"This is Alice"}},"filename":"/list.k.yaml","line":3,"column":11,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0}]}},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0}],"ctx":"Load"}},"filename":"/list.k.yaml","line":1,"column":0,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-5.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-5.snap new file mode 100644 index 000000000..44d5e9ca1 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-5.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"name\"","value":"name"}},"filename":"/complex.k.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Alice\"","value":"Alice"}},"filename":"/complex.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"age\"","value":"age"}},"filename":"/complex.k.yaml","line":2,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":18}}},"filename":"/complex.k.yaml","line":2,"column":5,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"message\"","value":"message"}},"filename":"/complex.k.yaml","line":3,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"This is Alice\"","value":"This is Alice"}},"filename":"/complex.k.yaml","line":3,"column":9,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"data\"","value":"data"}},"filename":"/complex.k.yaml","line":4,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"id\"","value":"id"}},"filename":"/complex.k.yaml","line":5,"column":4,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":1}}},"filename":"/complex.k.yaml","line":5,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":5,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"value\"","value":"value"}},"filename":"/complex.k.yaml","line":6,"column":4,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"value1\"","value":"value1"}},"filename":"/complex.k.yaml","line":6,"column":11,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":5,"column":6,"end_line":0,"end_column":0}]}},"filename":"/complex.k.yaml","line":5,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"labels\"","value":"labels"}},"filename":"/complex.k.yaml","line":7,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"key\"","value":"key"}},"filename":"/complex.k.yaml","line":8,"column":4,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"value\"","value":"value"}},"filename":"/complex.k.yaml","line":8,"column":9,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":8,"column":7,"end_line":0,"end_column":0}]}},"filename":"/complex.k.yaml","line":8,"column":7,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"hc\"","value":"hc"}},"filename":"/complex.k.yaml","line":9,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"List","data":{"elts":[{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":1}}},"filename":"/complex.k.yaml","line":10,"column":6,"end_line":0,"end_column":0},{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":2}}},"filename":"/complex.k.yaml","line":11,"column":6,"end_line":0,"end_column":0},{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":3}}},"filename":"/complex.k.yaml","line":12,"column":6,"end_line":0,"end_column":0}],"ctx":"Load"}},"filename":"/complex.k.yaml","line":10,"column":4,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}]}},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-6.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-6.snap new file mode 100644 index 000000000..27d9f4d0c --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-6.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"null_val\"","value":"null_val"}},"filename":"/only_with_null.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NameConstantLit","data":{"value":"None"}},"filename":"/only_with_null.yaml","line":1,"column":10,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/only_with_null.yaml","line":1,"column":8,"end_line":0,"end_column":0}]}},"filename":"/only_with_null.yaml","line":1,"column":8,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-7.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-7.snap new file mode 100644 index 000000000..a65c61974 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-7.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"bool_val\"","value":"bool_val"}},"filename":"/only_with_bool.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NameConstantLit","data":{"value":"True"}},"filename":"/only_with_bool.yaml","line":1,"column":10,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/only_with_bool.yaml","line":1,"column":8,"end_line":0,"end_column":0}]}},"filename":"/only_with_bool.yaml","line":1,"column":8,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-8.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-8.snap new file mode 100644 index 000000000..17bbcb643 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name-8.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"float_val\"","value":"float_val"}},"filename":"/only_with_float.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Float","data":0.33}}},"filename":"/only_with_float.yaml","line":1,"column":11,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/only_with_float.yaml","line":1,"column":9,"end_line":0,"end_column":0}]}},"filename":"/only_with_float.yaml","line":1,"column":9,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name.snap new file mode 100644 index 000000000..395e11230 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_with_yaml_no_schema_name.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"languages\"","value":"languages"}},"filename":"/test.k.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"List","data":{"elts":[{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Ruby\"","value":"Ruby"}},"filename":"/test.k.yaml","line":2,"column":4,"end_line":0,"end_column":0},{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Perl\"","value":"Perl"}},"filename":"/test.k.yaml","line":3,"column":4,"end_line":0,"end_column":0},{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Python\"","value":"Python"}},"filename":"/test.k.yaml","line":4,"column":4,"end_line":0,"end_column":0}],"ctx":"Load"}},"filename":"/test.k.yaml","line":2,"column":2,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"websites\"","value":"websites"}},"filename":"/test.k.yaml","line":5,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"YAML\"","value":"YAML"}},"filename":"/test.k.yaml","line":6,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"yaml.org\"","value":"yaml.org"}},"filename":"/test.k.yaml","line":6,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Ruby\"","value":"Ruby"}},"filename":"/test.k.yaml","line":7,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"ruby-lang.org\"","value":"ruby-lang.org"}},"filename":"/test.k.yaml","line":7,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Python\"","value":"Python"}},"filename":"/test.k.yaml","line":8,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"python.org\"","value":"python.org"}},"filename":"/test.k.yaml","line":8,"column":10,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Perl\"","value":"Perl"}},"filename":"/test.k.yaml","line":9,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"use.perl.org\"","value":"use.perl.org"}},"filename":"/test.k.yaml","line":9,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0}]}},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0}]}},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-2.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-2.snap new file mode 100644 index 000000000..be6964963 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-2.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Schema","data":{"name":{"node":{"names":[{"node":"simple","filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}],"pkgpath":"","ctx":"Load"},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},"args":[],"kwargs":[],"config":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"name\"","value":"name"}},"filename":"/simple.k.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Alice,\"","value":"Alice,"}},"filename":"/simple.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"age\"","value":"age"}},"filename":"/simple.k.yaml","line":2,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"18,\"","value":"18,"}},"filename":"/simple.k.yaml","line":2,"column":5,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"message\"","value":"message"}},"filename":"/simple.k.yaml","line":3,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"This is Alice\"","value":"This is Alice"}},"filename":"/simple.k.yaml","line":3,"column":9,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}]}},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}}},"filename":"/simple.k.yaml","line":1,"column":4,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-3.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-3.snap new file mode 100644 index 000000000..65c907127 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-3.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":1}}},"filename":"/plain_value.k.yaml","line":1,"column":0,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-4.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-4.snap new file mode 100644 index 000000000..607f56814 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-4.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"List","data":{"elts":[{"node":{"type":"Schema","data":{"name":{"node":{"names":[{"node":"list","filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0}],"pkgpath":"","ctx":"Load"},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},"args":[],"kwargs":[],"config":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"name\"","value":"name"}},"filename":"/list.k.yaml","line":1,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Alice\"","value":"Alice"}},"filename":"/list.k.yaml","line":1,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"age\"","value":"age"}},"filename":"/list.k.yaml","line":2,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":18}}},"filename":"/list.k.yaml","line":2,"column":7,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"message\"","value":"message"}},"filename":"/list.k.yaml","line":3,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"This is Alice\"","value":"This is Alice"}},"filename":"/list.k.yaml","line":3,"column":11,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0}]}},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0}}},"filename":"/list.k.yaml","line":1,"column":6,"end_line":0,"end_column":0}],"ctx":"Load"}},"filename":"/list.k.yaml","line":1,"column":0,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-5.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-5.snap new file mode 100644 index 000000000..c286526da --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-5.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Schema","data":{"name":{"node":{"names":[{"node":"complex","filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}],"pkgpath":"","ctx":"Load"},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},"args":[],"kwargs":[],"config":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"name\"","value":"name"}},"filename":"/complex.k.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Alice\"","value":"Alice"}},"filename":"/complex.k.yaml","line":1,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"age\"","value":"age"}},"filename":"/complex.k.yaml","line":2,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":18}}},"filename":"/complex.k.yaml","line":2,"column":5,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"message\"","value":"message"}},"filename":"/complex.k.yaml","line":3,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"This is Alice\"","value":"This is Alice"}},"filename":"/complex.k.yaml","line":3,"column":9,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"data\"","value":"data"}},"filename":"/complex.k.yaml","line":4,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"id\"","value":"id"}},"filename":"/complex.k.yaml","line":5,"column":4,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":1}}},"filename":"/complex.k.yaml","line":5,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":5,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"value\"","value":"value"}},"filename":"/complex.k.yaml","line":6,"column":4,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"value1\"","value":"value1"}},"filename":"/complex.k.yaml","line":6,"column":11,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":5,"column":6,"end_line":0,"end_column":0}]}},"filename":"/complex.k.yaml","line":5,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"labels\"","value":"labels"}},"filename":"/complex.k.yaml","line":7,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"key\"","value":"key"}},"filename":"/complex.k.yaml","line":8,"column":4,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"value\"","value":"value"}},"filename":"/complex.k.yaml","line":8,"column":9,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":8,"column":7,"end_line":0,"end_column":0}]}},"filename":"/complex.k.yaml","line":8,"column":7,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"hc\"","value":"hc"}},"filename":"/complex.k.yaml","line":9,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"List","data":{"elts":[{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":1}}},"filename":"/complex.k.yaml","line":10,"column":6,"end_line":0,"end_column":0},{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":2}}},"filename":"/complex.k.yaml","line":11,"column":6,"end_line":0,"end_column":0},{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Int","data":3}}},"filename":"/complex.k.yaml","line":12,"column":6,"end_line":0,"end_column":0}],"ctx":"Load"}},"filename":"/complex.k.yaml","line":10,"column":4,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}]}},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0}}},"filename":"/complex.k.yaml","line":1,"column":4,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-6.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-6.snap new file mode 100644 index 000000000..9613f3c57 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-6.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Schema","data":{"name":{"node":{"names":[{"node":"only_with_null","filename":"/only_with_null.yaml","line":1,"column":8,"end_line":0,"end_column":0}],"pkgpath":"","ctx":"Load"},"filename":"/only_with_null.yaml","line":1,"column":8,"end_line":0,"end_column":0},"args":[],"kwargs":[],"config":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"null_val\"","value":"null_val"}},"filename":"/only_with_null.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NameConstantLit","data":{"value":"None"}},"filename":"/only_with_null.yaml","line":1,"column":10,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/only_with_null.yaml","line":1,"column":8,"end_line":0,"end_column":0}]}},"filename":"/only_with_null.yaml","line":1,"column":8,"end_line":0,"end_column":0}}},"filename":"/only_with_null.yaml","line":1,"column":8,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-7.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-7.snap new file mode 100644 index 000000000..72bb7fd6b --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-7.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Schema","data":{"name":{"node":{"names":[{"node":"only_with_bool","filename":"/only_with_bool.yaml","line":1,"column":8,"end_line":0,"end_column":0}],"pkgpath":"","ctx":"Load"},"filename":"/only_with_bool.yaml","line":1,"column":8,"end_line":0,"end_column":0},"args":[],"kwargs":[],"config":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"bool_val\"","value":"bool_val"}},"filename":"/only_with_bool.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NameConstantLit","data":{"value":"True"}},"filename":"/only_with_bool.yaml","line":1,"column":10,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/only_with_bool.yaml","line":1,"column":8,"end_line":0,"end_column":0}]}},"filename":"/only_with_bool.yaml","line":1,"column":8,"end_line":0,"end_column":0}}},"filename":"/only_with_bool.yaml","line":1,"column":8,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-8.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-8.snap new file mode 100644 index 000000000..3b9cef936 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml-8.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Schema","data":{"name":{"node":{"names":[{"node":"only_with_float","filename":"/only_with_float.yaml","line":1,"column":9,"end_line":0,"end_column":0}],"pkgpath":"","ctx":"Load"},"filename":"/only_with_float.yaml","line":1,"column":9,"end_line":0,"end_column":0},"args":[],"kwargs":[],"config":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"float_val\"","value":"float_val"}},"filename":"/only_with_float.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"NumberLit","data":{"binary_suffix":null,"value":{"type":"Float","data":0.33}}},"filename":"/only_with_float.yaml","line":1,"column":11,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/only_with_float.yaml","line":1,"column":9,"end_line":0,"end_column":0}]}},"filename":"/only_with_float.yaml","line":1,"column":9,"end_line":0,"end_column":0}}},"filename":"/only_with_float.yaml","line":1,"column":9,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml.snap b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml.snap new file mode 100644 index 000000000..a7f6b8700 --- /dev/null +++ b/kclvm/tools/src/vet/snapshots/kclvm_tools__vet__tests__test_expr_builder__build_yaml.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/vet/tests.rs +expression: got_ast_yaml_str +--- +{"node":{"type":"Schema","data":{"name":{"node":{"names":[{"node":"test","filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0}],"pkgpath":"","ctx":"Load"},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0},"args":[],"kwargs":[],"config":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"languages\"","value":"languages"}},"filename":"/test.k.yaml","line":1,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"List","data":{"elts":[{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Ruby\"","value":"Ruby"}},"filename":"/test.k.yaml","line":2,"column":4,"end_line":0,"end_column":0},{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Perl\"","value":"Perl"}},"filename":"/test.k.yaml","line":3,"column":4,"end_line":0,"end_column":0},{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Python\"","value":"Python"}},"filename":"/test.k.yaml","line":4,"column":4,"end_line":0,"end_column":0}],"ctx":"Load"}},"filename":"/test.k.yaml","line":2,"column":2,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"websites\"","value":"websites"}},"filename":"/test.k.yaml","line":5,"column":0,"end_line":0,"end_column":0},"value":{"node":{"type":"Config","data":{"items":[{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"YAML\"","value":"YAML"}},"filename":"/test.k.yaml","line":6,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"yaml.org\"","value":"yaml.org"}},"filename":"/test.k.yaml","line":6,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Ruby\"","value":"Ruby"}},"filename":"/test.k.yaml","line":7,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"ruby-lang.org\"","value":"ruby-lang.org"}},"filename":"/test.k.yaml","line":7,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Python\"","value":"Python"}},"filename":"/test.k.yaml","line":8,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"python.org\"","value":"python.org"}},"filename":"/test.k.yaml","line":8,"column":10,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},{"node":{"key":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"Perl\"","value":"Perl"}},"filename":"/test.k.yaml","line":9,"column":2,"end_line":0,"end_column":0},"value":{"node":{"type":"StringLit","data":{"is_long_string":false,"raw_value":"\"use.perl.org\"","value":"use.perl.org"}},"filename":"/test.k.yaml","line":9,"column":8,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0}]}},"filename":"/test.k.yaml","line":6,"column":6,"end_line":0,"end_column":0},"operation":"Union","insert_index":-1},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0}]}},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0}}},"filename":"/test.k.yaml","line":1,"column":9,"end_line":0,"end_column":0} diff --git a/kclvm/tools/src/vet/tests.rs b/kclvm/tools/src/vet/tests.rs index a1dc35559..0623a8c4e 100644 --- a/kclvm/tools/src/vet/tests.rs +++ b/kclvm/tools/src/vet/tests.rs @@ -14,7 +14,6 @@ pub(crate) fn rel_path() -> String { .display() .to_string() } -const NO_SCHEMA_NAME_PATH: &str = "no_schema_name"; const TEST_CASES: &[&str] = &[ "test.k", @@ -67,7 +66,6 @@ pub(crate) fn path_to_windows(panic_info: &mut PanicInfo) { mod test_expr_builder { use regex::Regex; - use serde_json::Value; use crate::{ util::loader::LoaderKind, @@ -75,26 +73,19 @@ mod test_expr_builder { expr_builder::ExprBuilder, tests::{ construct_full_path, deal_windows_filepath, FILE_EXTENSIONS, INVALID_FILE_RESULT, - LOADER_KIND, NO_SCHEMA_NAME_PATH, SCHEMA_NAMES, TEST_CASES, + LOADER_KIND, SCHEMA_NAMES, TEST_CASES, }, }, }; - use std::{ - fs::{self, File}, - io::Write, - panic, - path::{Path, PathBuf}, - }; + use std::{fs, panic, path::Path}; #[test] + #[cfg(not(target_os = "windows"))] fn test_build_with_json_no_schema_name() { for test_name in TEST_CASES { let file_path = construct_full_path(&format!( "{}.{}", - Path::new(FILE_EXTENSIONS[0]) - .join(test_name) - .display() - .to_string(), + Path::new(FILE_EXTENSIONS[0]).join(test_name).display(), FILE_EXTENSIONS[0] )) .unwrap(); @@ -107,32 +98,12 @@ mod test_expr_builder { .unwrap() .replace( &deal_windows_filepath(construct_full_path("json").unwrap(), |s| { - s.replace("\\", "\\\\") + s.replace('\\', "\\\\") }), "", ); - let got_ast_json: Value = serde_json::from_str(&got_ast_json_str).unwrap(); - - #[cfg(not(target_os = "windows"))] - let test_case_ty = "json"; - #[cfg(target_os = "windows")] - let test_case_ty = "json_win"; - - let expect_file_path = construct_full_path(&format!( - "{}.{}", - Path::new(test_case_ty) - .join(NO_SCHEMA_NAME_PATH) - .join(test_name) - .display() - .to_string(), - FILE_EXTENSIONS[2] - )) - .unwrap(); - - let f = File::open(expect_file_path.clone()).unwrap(); - let expect_ast_json: serde_json::Value = serde_json::from_reader(f).unwrap(); - assert_eq!(expect_ast_json, got_ast_json) + insta::assert_snapshot!(got_ast_json_str); } } @@ -151,32 +122,17 @@ mod test_expr_builder { let got_ast_yaml_str = serde_json::to_string(&got_ast_yaml).unwrap().replace( &deal_windows_filepath(construct_full_path("yaml").unwrap(), |s| { - s.replace("\\", "\\\\") + s.replace('\\', "\\\\") }), "", ); - let got_ast_yaml: Value = serde_yaml::from_str(&got_ast_yaml_str).unwrap(); - - #[cfg(not(target_os = "windows"))] - let test_case_ty = "yaml"; - #[cfg(target_os = "windows")] - let test_case_ty = "yaml_win"; - - let expect_file_path = construct_full_path(&format!( - "{}/{}/{}.{}", - test_case_ty, NO_SCHEMA_NAME_PATH, test_name, FILE_EXTENSIONS[3] - )) - .unwrap(); - - let f = File::open(expect_file_path.clone()).unwrap(); - - let expect_ast_yaml: Value = serde_yaml::from_reader(f).unwrap(); - assert_eq!(expect_ast_yaml, got_ast_yaml); + insta::assert_snapshot!(got_ast_yaml_str) } } #[test] + #[cfg(not(target_os = "windows"))] /// Test `expr_builder.build()` with input json files. fn test_build_json_with_filepath() { for i in 0..TEST_CASES.len() { @@ -193,31 +149,17 @@ mod test_expr_builder { .unwrap() .replace( &deal_windows_filepath(construct_full_path("json").unwrap(), |s| { - s.replace("\\", "\\\\") + s.replace('\\', "\\\\") }), "", ); - let got_ast_json: Value = serde_json::from_str(&got_ast_json_str).unwrap(); - - #[cfg(not(target_os = "windows"))] - let test_case_ty = "json"; - #[cfg(target_os = "windows")] - let test_case_ty = "json_win"; - let expect_file_path = construct_full_path(&format!( - "{}/{}.{}", - test_case_ty, TEST_CASES[i], FILE_EXTENSIONS[2] - )) - .unwrap(); - - let f = File::open(expect_file_path.clone()).unwrap(); - let expect_ast_json: serde_json::Value = serde_json::from_reader(f).unwrap(); - - assert_eq!(expect_ast_json, got_ast_json) + insta::assert_snapshot!(got_ast_json_str); } } #[test] + #[cfg(not(target_os = "windows"))] /// Test `expr_builder.build()` with input json files. fn test_build_json_with_str() { for i in 0..TEST_CASES.len() { @@ -237,32 +179,12 @@ mod test_expr_builder { .unwrap() .replace( &deal_windows_filepath(construct_full_path("json").unwrap(), |s| { - s.replace("\\", "\\\\") + s.replace('\\', "\\\\") }), "", ); - let got_ast_json: Value = serde_json::from_str(&got_ast_json_str).unwrap(); - - #[cfg(not(target_os = "windows"))] - let test_case_ty = "json_str"; - #[cfg(target_os = "windows")] - let test_case_ty = "json_str_win"; - - let expect_file_path = construct_full_path(&format!( - "{}/{}.{}", - test_case_ty, TEST_CASES[i], FILE_EXTENSIONS[2] - )) - .unwrap(); - let f = File::open(expect_file_path.clone()).unwrap(); - let expect_ast_json: serde_json::Value = serde_json::from_reader(f).unwrap(); - let mut expect_path = PathBuf::from(construct_full_path("json").unwrap()); - expect_path.push(""); - let expect_ast_json_str = serde_json::to_string(&expect_ast_json) - .unwrap() - .replace("", &expect_path.display().to_string()); - let expect_ast_json: Value = serde_json::from_str(&expect_ast_json_str).unwrap(); - assert_eq!(expect_ast_json, got_ast_json) + insta::assert_snapshot!(got_ast_json_str); } } @@ -281,28 +203,12 @@ mod test_expr_builder { let got_ast_yaml_str = serde_json::to_string(&got_ast_yaml).unwrap().replace( &deal_windows_filepath(construct_full_path("yaml").unwrap(), |s| { - s.replace("\\", "\\\\") + s.replace('\\', "\\\\") }), "", ); - let got_ast_yaml: serde_yaml::Value = serde_yaml::from_str(&got_ast_yaml_str).unwrap(); - - #[cfg(not(target_os = "windows"))] - let test_case_ty = "yaml"; - #[cfg(target_os = "windows")] - let test_case_ty = "yaml_win"; - - let expect_file_path = construct_full_path(&format!( - "{}/{}.{}", - test_case_ty, TEST_CASES[i], FILE_EXTENSIONS[3] - )) - .unwrap(); - - let f = File::open(expect_file_path.clone()).unwrap(); - let expect_ast_yaml: serde_yaml::Value = serde_yaml::from_reader(f).unwrap(); - - assert_eq!(expect_ast_yaml, got_ast_yaml) + insta::assert_snapshot!(got_ast_yaml_str); } } @@ -458,7 +364,7 @@ mod test_validater { for case in KCL_TEST_CASES { let validated_file_path = construct_full_path(&format!( "{}.{}", - Path::new("validate_cases").join(case).display().to_string(), + Path::new("validate_cases").join(case).display(), file_suffix )) .unwrap(); @@ -493,10 +399,7 @@ mod test_validater { for case in KCL_TEST_CASES { let validated_file_path = construct_full_path(&format!( "{}.{}", - Path::new("invalid_vet_cases_json") - .join(case) - .display() - .to_string(), + Path::new("invalid_vet_cases_json").join(case).display(), "json" )) .unwrap(); @@ -530,13 +433,13 @@ mod test_validater { ); let result = validate(opt).unwrap_err(); - println!("{}", result.to_string()); + println!("{}", result); assert!( - result.to_string().replace("\\", "").contains( + result.to_string().replace('\\', "").contains( &deal_windows_filepath(root_path.join(case).display().to_string(), |s| { - s.replace("\\", "\\\\") + s.replace('\\', "\\\\") }) - .replace("\\", "") + .replace('\\', "") ), "{result}" ); @@ -551,10 +454,7 @@ mod test_validater { for case in KCL_TEST_CASES { let validated_file_path = construct_full_path(&format!( "{}.{}", - Path::new("invalid_vet_cases_yaml") - .join(case) - .display() - .to_string(), + Path::new("invalid_vet_cases_yaml").join(case).display(), "yaml" )) .unwrap(); @@ -588,13 +488,13 @@ mod test_validater { ); let result = validate(opt).unwrap_err(); - println!("{}", result.to_string()); + println!("{}", result); assert!( - result.to_string().replace("\\", "").contains( + result.to_string().replace('\\', "").contains( &deal_windows_filepath(root_path.join(case).display().to_string(), |s| { - s.replace("\\", "\\\\") + s.replace('\\', "\\\\") }) - .replace("\\", "") + .replace('\\', "") ), "{result}" ); @@ -606,10 +506,7 @@ mod test_validater { for case in KCL_TEST_CASES { let validated_file_path = construct_full_path(&format!( "{}.{}", - Path::new("invalid_validate_cases") - .join(case) - .display() - .to_string(), + Path::new("invalid_validate_cases").join(case).display(), file_suffix )) .unwrap(); diff --git a/kclvm/tools/src/vet/validator.rs b/kclvm/tools/src/vet/validator.rs index e7fe40349..b7dced16f 100644 --- a/kclvm/tools/src/vet/validator.rs +++ b/kclvm/tools/src/vet/validator.rs @@ -66,7 +66,7 @@ //! ``` use super::expr_builder::ExprBuilder; pub use crate::util::loader::LoaderKind; -use anyhow::{anyhow, Result}; +use anyhow::Result; use kclvm_ast::{ ast::{AssignStmt, Expr, ExprContext, Identifier, Module, Node, NodeRef, SchemaStmt, Stmt}, node_ref, @@ -177,8 +177,7 @@ pub fn validate(val_opt: ValidateOption) -> Result { None => TMP_FILE.to_string(), }; - let mut module = - kclvm_parser::parse_file(&k_path, val_opt.kcl_code).map_err(|err| anyhow!(err))?; + let mut module = kclvm_parser::parse_file_force_errors(&k_path, val_opt.kcl_code)?; let schemas = filter_schema_stmt(&module); let schema_name = match val_opt.schema_name { diff --git a/kclvm/utils/Cargo.toml b/kclvm/utils/Cargo.toml index 3cf43a29d..89ccb610f 100644 --- a/kclvm/utils/Cargo.toml +++ b/kclvm/utils/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = "1" diff --git a/kclvm/utils/src/pkgpath.rs b/kclvm/utils/src/pkgpath.rs index 512e8de35..ca837359e 100644 --- a/kclvm/utils/src/pkgpath.rs +++ b/kclvm/utils/src/pkgpath.rs @@ -1,5 +1,7 @@ //! This file primarily offers utils for working with kcl package paths. +use anyhow::{anyhow, Result}; + /// Remove the external package name prefix from the current import absolute path. /// /// # Note @@ -8,7 +10,7 @@ /// /// # Error /// An error is returned if an empty string is passed in. -pub fn rm_external_pkg_name(pkgpath: &str) -> Result { +pub fn rm_external_pkg_name(pkgpath: &str) -> Result { Ok(pkgpath .to_string() .trim_start_matches(parse_external_pkg_name(pkgpath)?.as_str()) @@ -23,10 +25,10 @@ pub fn rm_external_pkg_name(pkgpath: &str) -> Result { /// /// # Error /// An error is returned if an empty string is passed in. -pub fn parse_external_pkg_name(pkgpath: &str) -> Result { +pub fn parse_external_pkg_name(pkgpath: &str) -> Result { let mut names = pkgpath.splitn(2, '.'); match names.next() { Some(it) => Ok(it.to_string()), - None => Err(format!("Invalid external package name `{}`", pkgpath)), + None => Err(anyhow!("Invalid external package name `{}`", pkgpath)), } }