From e3371e6c30ccb07ea506326647a62d16efeec424 Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sat, 8 Oct 2022 17:30:15 +0800 Subject: [PATCH 01/10] refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'. move 'printer' from 'kclvm-tools' to 'kclvm-ast' issue #67 --- kclvm/Cargo.lock | 4 + kclvm/ast/Cargo.toml | 4 + kclvm/ast/src/lib.rs | 1 + kclvm/ast/src/printer/mod.rs | 266 ++++++ kclvm/ast/src/printer/node.rs | 873 ++++++++++++++++++ .../ast/src/printer/test_data/arguments.input | 6 + .../src/printer/test_data/arguments.output | 6 + .../src/printer/test_data/codelayout.input | 76 ++ .../src/printer/test_data/codelayout.output | 79 ++ .../src/printer/test_data/collection_if.input | 51 + .../printer/test_data/collection_if.output | 55 ++ kclvm/ast/src/printer/test_data/comment.input | 38 + .../ast/src/printer/test_data/comment.output | 34 + kclvm/ast/src/printer/test_data/empty.input | 4 + kclvm/ast/src/printer/test_data/empty.output | 0 kclvm/ast/src/printer/test_data/if_stmt.input | 16 + .../ast/src/printer/test_data/if_stmt.output | 15 + kclvm/ast/src/printer/test_data/import.input | 4 + kclvm/ast/src/printer/test_data/import.output | 4 + .../src/printer/test_data/index_sign.input | 12 + .../src/printer/test_data/index_sign.output | 13 + .../src/printer/test_data/joined_str.input | 3 + .../src/printer/test_data/joined_str.output | 3 + kclvm/ast/src/printer/test_data/lambda.input | 20 + kclvm/ast/src/printer/test_data/lambda.output | 21 + kclvm/ast/src/printer/test_data/quant.input | 8 + kclvm/ast/src/printer/test_data/quant.output | 12 + kclvm/ast/src/printer/test_data/rule.input | 19 + kclvm/ast/src/printer/test_data/rule.output | 16 + .../src/printer/test_data/type_alias.input | 18 + .../src/printer/test_data/type_alias.output | 13 + kclvm/ast/src/printer/test_data/unary.input | 6 + kclvm/ast/src/printer/test_data/unary.output | 6 + .../src/printer/test_data/unification.input | 5 + .../src/printer/test_data/unification.output | 4 + kclvm/ast/src/printer/tests.rs | 50 + kclvm/ast_pretty/src/lib.rs | 1 + kclvm/ast_pretty/src/node.rs | 6 + kclvm/tools/src/format/mod.rs | 1 + kclvm/tools/src/query/override.rs | 1 + 40 files changed, 1774 insertions(+) create mode 100644 kclvm/ast/src/printer/mod.rs create mode 100644 kclvm/ast/src/printer/node.rs create mode 100644 kclvm/ast/src/printer/test_data/arguments.input create mode 100644 kclvm/ast/src/printer/test_data/arguments.output create mode 100644 kclvm/ast/src/printer/test_data/codelayout.input create mode 100644 kclvm/ast/src/printer/test_data/codelayout.output create mode 100644 kclvm/ast/src/printer/test_data/collection_if.input create mode 100644 kclvm/ast/src/printer/test_data/collection_if.output create mode 100644 kclvm/ast/src/printer/test_data/comment.input create mode 100644 kclvm/ast/src/printer/test_data/comment.output create mode 100644 kclvm/ast/src/printer/test_data/empty.input create mode 100644 kclvm/ast/src/printer/test_data/empty.output create mode 100644 kclvm/ast/src/printer/test_data/if_stmt.input create mode 100644 kclvm/ast/src/printer/test_data/if_stmt.output create mode 100644 kclvm/ast/src/printer/test_data/import.input create mode 100644 kclvm/ast/src/printer/test_data/import.output create mode 100644 kclvm/ast/src/printer/test_data/index_sign.input create mode 100644 kclvm/ast/src/printer/test_data/index_sign.output create mode 100644 kclvm/ast/src/printer/test_data/joined_str.input create mode 100644 kclvm/ast/src/printer/test_data/joined_str.output create mode 100644 kclvm/ast/src/printer/test_data/lambda.input create mode 100644 kclvm/ast/src/printer/test_data/lambda.output create mode 100644 kclvm/ast/src/printer/test_data/quant.input create mode 100644 kclvm/ast/src/printer/test_data/quant.output create mode 100644 kclvm/ast/src/printer/test_data/rule.input create mode 100644 kclvm/ast/src/printer/test_data/rule.output create mode 100644 kclvm/ast/src/printer/test_data/type_alias.input create mode 100644 kclvm/ast/src/printer/test_data/type_alias.output create mode 100644 kclvm/ast/src/printer/test_data/unary.input create mode 100644 kclvm/ast/src/printer/test_data/unary.output create mode 100644 kclvm/ast/src/printer/test_data/unification.input create mode 100644 kclvm/ast/src/printer/test_data/unification.output create mode 100644 kclvm/ast/src/printer/tests.rs diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index a6ce16552..ad38aa34e 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -604,8 +604,12 @@ dependencies = [ name = "kclvm-ast" version = "0.1.0" dependencies = [ + "fancy-regex", + "indexmap", + "kclvm-error", "kclvm-parser", "kclvm-span", + "pretty_assertions", "rustc_span", "serde", "serde_json", diff --git a/kclvm/ast/Cargo.toml b/kclvm/ast/Cargo.toml index 46f689666..eeb9430da 100644 --- a/kclvm/ast/Cargo.toml +++ b/kclvm/ast/Cargo.toml @@ -9,8 +9,12 @@ edition = "2021" rustc_span = { path = "../3rdparty/rustc_span" } serde = { version = "1", features = ["derive"] } serde_json = "1.0" +indexmap = "1.0" +fancy-regex = "0.7.1" kclvm-span = {path = "../span", version = "0.1.0"} +kclvm-error = {path = "../error", version = "0.1.0"} [dev-dependencies] kclvm-parser = {path = "../parser", version = "0.1.0"} +pretty_assertions = "1.2.1" diff --git a/kclvm/ast/src/lib.rs b/kclvm/ast/src/lib.rs index edaf80490..d764a8131 100644 --- a/kclvm/ast/src/lib.rs +++ b/kclvm/ast/src/lib.rs @@ -7,6 +7,7 @@ pub mod path; pub mod token; pub mod token_stream; pub mod walker; +pub mod printer; #[cfg(test)] mod tests; diff --git a/kclvm/ast/src/printer/mod.rs b/kclvm/ast/src/printer/mod.rs new file mode 100644 index 000000000..8918bf1a6 --- /dev/null +++ b/kclvm/ast/src/printer/mod.rs @@ -0,0 +1,266 @@ +use indexmap::IndexMap; +use kclvm_ast::{ + ast::{self, Module}, + token::TokenKind, + walker::MutSelfTypedResultWalker, +}; +use std::collections::VecDeque; + +<<<<<<<< HEAD:kclvm/ast_pretty/src/lib.rs +======== +use crate::{ast, token::TokenKind, walker::MutSelfTypedResultWalker}; + +>>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/mod.rs +mod node; + +#[cfg(test)] +mod tests; + +pub const WHITESPACE: &str = " "; +pub const TAB: &str = "\t"; +pub const NEWLINE: &str = "\n"; + +#[derive(Debug, Clone)] +pub enum Indentation { + Indent = 0, + Dedent = 1, + Newline = 2, + IndentWithNewline = 3, + DedentWithNewline = 4, + Fill = 5, +} + +/// Printer config +#[derive(Debug)] +pub struct Config { + pub tab_len: usize, + pub indent_len: usize, + pub use_spaces: bool, + pub write_comments: bool, +} + +impl Default for Config { + fn default() -> Self { + Self { + tab_len: 4, + indent_len: 4, + use_spaces: true, + write_comments: true, + } + } +} + +#[derive(Copy, Clone)] +pub struct NoHook; + +impl PrinterHook for NoHook {} + +pub enum ASTNode<'p> { + Stmt(&'p ast::NodeRef), + Expr(&'p ast::NodeRef), +} + +pub trait PrinterHook { + fn pre(&self, _printer: &mut Printer<'_>, _node: ASTNode<'_>) {} + fn post(&self, _printer: &mut Printer<'_>, _node: ASTNode<'_>) {} +} + +pub struct Printer<'p> { + /// Output string buffer. + pub out: String, + pub indent: usize, + pub cfg: Config, + /// Print comments, + pub last_ast_line: u64, + pub comments: VecDeque>, + pub import_spec: IndexMap, + pub hook: &'p (dyn PrinterHook + 'p), +} + +impl Default for Printer<'_> { + fn default() -> Self { + Self { + out: Default::default(), + indent: Default::default(), + cfg: Default::default(), + last_ast_line: Default::default(), + comments: Default::default(), + import_spec: Default::default(), + hook: &NoHook, + } + } +} + +impl<'p> Printer<'p> { + pub fn new(cfg: Config, hook: &'p (dyn PrinterHook + 'p)) -> Self { + Self { + out: "".to_string(), + indent: 0, + cfg, + last_ast_line: 0, + comments: VecDeque::default(), + import_spec: IndexMap::default(), + hook, + } + } + + // -------------------------- + // Write functions + // -------------------------- + + /// Write a string + #[inline] + pub fn write(&mut self, text: &str) { + self.write_string(text); + } + + /// Write a string with newline. + #[inline] + pub fn writeln(&mut self, text: &str) { + self.write_string(text); + self.write_string(NEWLINE); + self.fill(""); + } + + /// Write a space. + #[inline] + pub fn write_space(&mut self) { + self.write_string(WHITESPACE); + } + + /// Fill a indent + pub fn fill(&mut self, text: &str) { + if self.cfg.use_spaces { + self.write(&format!( + "{}{}", + WHITESPACE.repeat(self.indent * self.cfg.indent_len), + text + )); + } else { + self.write(&format!("{}{}", TAB.repeat(self.indent), text)); + } + } + + /// Print string + #[inline] + pub fn write_string(&mut self, string: &str) { + self.out.push_str(string); + } + + pub fn write_indentation(&mut self, indentation: Indentation) { + match indentation { + Indentation::Indent => self.enter(), + Indentation::Dedent => self.leave(), + Indentation::Newline => self.write_newline(), + Indentation::IndentWithNewline => { + self.enter(); + self.write_newline() + } + Indentation::DedentWithNewline => { + self.leave(); + self.write_newline(); + } + Indentation::Fill => self.fill(""), + } + } + + #[inline] + pub fn write_newline(&mut self) { + self.writeln("") + } + + #[inline] + pub fn write_newline_without_fill(&mut self) { + self.write_string(NEWLINE); + } + + /// Print value + #[inline] + pub fn write_value(&mut self, value: T) { + self.write(&format!("{}", value)); + } + + /// Print ast token + #[inline] + pub fn write_token(&mut self, tok: TokenKind) { + let tok_str: String = tok.into(); + self.write_string(&tok_str); + } + + /// Print ast node + #[inline] + pub fn write_node(&mut self, node: ASTNode<'_>) { + match node { + ASTNode::Stmt(stmt) => self.stmt(stmt), + ASTNode::Expr(expr) => self.expr(expr), + } + } + + /// Print ast module. + #[inline] + pub fn write_module(&mut self, module: &ast::Module) { + self.walk_module(module); + while let Some(comment) = self.comments.pop_front() { + self.writeln(&comment.node.text); + self.fill(""); + } + } + + /// Print ast comments. + pub fn write_ast_comments(&mut self, node: &ast::NodeRef) { + if !self.cfg.write_comments { + return; + } + if node.line > self.last_ast_line { + self.last_ast_line = node.line; + let mut index = None; + for (i, comment) in self.comments.iter().enumerate() { + if comment.line <= node.line { + index = Some(i); + } else { + break; + } + } + if let Some(index) = index { + let mut count = index as isize; + while count >= 0 { + match self.comments.pop_front() { + Some(comment) => { + self.writeln(&comment.node.text); + } + None => break, + } + count -= 1; + } + } + } + } + + // -------------------------- + // Indent and scope functions + // -------------------------- + + /// Enter with a indent + pub fn enter(&mut self) { + self.indent += 1; + } + + /// Leave with a dedent + pub fn leave(&mut self) { + self.indent -= 1; + } +} + +/// Print AST to string +pub fn print_ast_module(module: &Module) -> String { + let mut printer = Printer::default(); + printer.write_module(module); + printer.out +} + +/// Print AST to string +pub fn print_ast_node(node: ASTNode) -> String { + let mut printer = Printer::default(); + printer.write_node(node); + printer.out +} diff --git a/kclvm/ast/src/printer/node.rs b/kclvm/ast/src/printer/node.rs new file mode 100644 index 000000000..00d354b3f --- /dev/null +++ b/kclvm/ast/src/printer/node.rs @@ -0,0 +1,873 @@ +use std::collections::HashSet; + +<<<<<<<< HEAD:kclvm/ast_pretty/src/node.rs +use kclvm_ast::{ + ast::{self, CallExpr}, + token::{DelimToken, TokenKind}, + walker::MutSelfTypedResultWalker, +}; +use kclvm_error::bug; +======== +use kclvm_error::bug; + +use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; +>>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs + +use super::{Indentation, Printer}; + +type ParameterType<'a> = ( + ( + &'a ast::NodeRef, + &'a Option>, + ), + &'a Option>, +); + +const COMMA_WHITESPACE: &str = ", "; +const IDENTIFIER_REGEX: &str = r#"^\$?[a-zA-Z_]\w*$"#; + +macro_rules! interleave { + ($inter: expr, $f: expr, $seq: expr) => { + if !$seq.is_empty() { + $f(&$seq[0]); + for s in &$seq[1..] { + $inter(); + $f(s); + } + } + }; +} + +impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> { + type Result = (); + + fn walk_module(&mut self, module: &'ctx ast::Module) -> Self::Result { + for comment in &module.comments { + self.comments.push_back(comment.clone()); + } + self.stmts(&module.body); + } + + fn walk_expr_stmt(&mut self, expr_stmt: &'ctx ast::ExprStmt) -> Self::Result { + interleave!( + || self.write(COMMA_WHITESPACE), + |expr| self.expr(expr), + expr_stmt.exprs + ); + self.write_newline_without_fill(); + } + + fn walk_unification_stmt( + &mut self, + unification_stmt: &'ctx ast::UnificationStmt, + ) -> Self::Result { + self.walk_identifier(&unification_stmt.target.node); + self.write(": "); + self.walk_schema_expr(&unification_stmt.value.node); + self.write_newline_without_fill(); + } + + fn walk_type_alias_stmt(&mut self, type_alias_stmt: &'ctx ast::TypeAliasStmt) -> Self::Result { + self.write("type"); + self.write_space(); + self.walk_identifier(&type_alias_stmt.type_name.node); + self.write(" = "); + self.write(&type_alias_stmt.type_value.node); + self.write_newline_without_fill(); + } + + fn walk_assign_stmt(&mut self, assign_stmt: &'ctx ast::AssignStmt) -> Self::Result { + for (i, target) in assign_stmt.targets.iter().enumerate() { + self.walk_identifier(&target.node); + if i == 0 { + if let Some(ty) = &assign_stmt.ty { + self.write(": "); + self.write(&ty.node.to_string()); + } + } + self.write(" = "); + } + self.expr(&assign_stmt.value); + self.write_newline_without_fill(); + if matches!(assign_stmt.value.node, ast::Expr::Schema(_)) { + self.write_newline_without_fill(); + } + } + + fn walk_aug_assign_stmt(&mut self, aug_assign_stmt: &'ctx ast::AugAssignStmt) -> Self::Result { + self.walk_identifier(&aug_assign_stmt.target.node); + self.write_space(); + self.write(aug_assign_stmt.op.symbol()); + self.write_space(); + self.expr(&aug_assign_stmt.value); + self.write_newline_without_fill(); + } + + fn walk_assert_stmt(&mut self, assert_stmt: &'ctx ast::AssertStmt) -> Self::Result { + self.write("assert "); + self.expr(&assert_stmt.test); + if let Some(if_cond) = &assert_stmt.if_cond { + self.write(" if "); + self.expr(if_cond); + } + if let Some(msg) = &assert_stmt.msg { + self.write(COMMA_WHITESPACE); + self.expr(msg); + } + self.write_newline_without_fill(); + } + + fn walk_if_stmt(&mut self, if_stmt: &'ctx ast::IfStmt) -> Self::Result { + self.write("if "); + self.expr(&if_stmt.cond); + self.write_token(TokenKind::Colon); + self.write_newline_without_fill(); + self.write_indentation(Indentation::Indent); + self.stmts(&if_stmt.body); + self.write_indentation(Indentation::Dedent); + if !if_stmt.orelse.is_empty() { + if let ast::Stmt::If(elif_stmt) = &if_stmt.orelse[0].node { + // Nested if statements need to be considered, + // so `el` needs to be preceded by the current indentation. + self.fill("el"); + self.walk_if_stmt(elif_stmt); + } else { + // Nested if statements need to be considered, + // so `el` needs to be preceded by the current indentation. + self.fill("else:"); + self.write_newline_without_fill(); + self.write_indentation(Indentation::Indent); + self.stmts(&if_stmt.orelse); + self.write_indentation(Indentation::Dedent); + } + } else { + self.write_newline_without_fill(); + } + } + + fn walk_import_stmt(&mut self, import_stmt: &'ctx ast::ImportStmt) -> Self::Result { + self.write("import "); + self.write(&import_stmt.path); + if let Some(as_name) = &import_stmt.asname { + self.write(" as "); + self.write(as_name); + } + self.write_newline_without_fill(); + } + + fn walk_schema_stmt(&mut self, schema_stmt: &'ctx ast::SchemaStmt) -> Self::Result { + interleave!( + || self.write_newline(), + |expr: &ast::NodeRef| { + self.write("@"); + self.walk_call_expr(&expr.node); + }, + schema_stmt.decorators + ); + if !schema_stmt.decorators.is_empty() { + self.write_newline(); + } + if schema_stmt.is_mixin { + self.write("mixin "); + } else if schema_stmt.is_protocol { + self.write("protocol "); + } else { + self.write("schema "); + } + self.write(&schema_stmt.name.node); + if let Some(args) = &schema_stmt.args { + self.write("["); + self.walk_arguments(&args.node); + self.write("]"); + } + if let Some(parent_name) = &schema_stmt.parent_name { + self.write("("); + self.walk_identifier(&parent_name.node); + self.write(")"); + } + if let Some(host_name) = &schema_stmt.for_host_name { + self.write(" for "); + self.walk_identifier(&host_name.node); + } + self.write_token(TokenKind::Colon); + self.write_newline_without_fill(); + self.write_indentation(Indentation::Indent); + if !schema_stmt.doc.is_empty() { + self.fill(""); + self.write(&schema_stmt.doc); + self.write_newline_without_fill(); + } + if !schema_stmt.mixins.is_empty() { + self.fill(""); + self.write("mixin ["); + self.write_indentation(Indentation::IndentWithNewline); + interleave!( + || { + self.write(","); + self.write_newline(); + }, + |mixin_name: &ast::NodeRef| self.walk_identifier(&mixin_name.node), + schema_stmt.mixins + ); + self.write_indentation(Indentation::Dedent); + self.write_newline(); + self.write("]"); + self.write_newline_without_fill(); + } + if let Some(index_signature) = &schema_stmt.index_signature { + self.fill(""); + self.write_token(TokenKind::OpenDelim(DelimToken::Bracket)); + if index_signature.node.any_other { + self.write_token(TokenKind::DotDotDot); + } + if let Some(key_name) = &index_signature.node.key_name { + self.write(&format!("{}: ", key_name)); + } + self.write(&index_signature.node.key_type.node); + self.write_token(TokenKind::CloseDelim(DelimToken::Bracket)); + self.write_token(TokenKind::Colon); + self.write_space(); + self.write(&index_signature.node.value_type.node); + if let Some(value) = &index_signature.node.value { + self.write(" = "); + self.expr(value); + } + self.write_newline_without_fill(); + } + self.stmts(&schema_stmt.body); + self.write_newline_without_fill(); + if !schema_stmt.checks.is_empty() { + self.fill("check:"); + // Schema check indent + self.write_indentation(Indentation::IndentWithNewline); + interleave!( + || self.write_newline(), + |check_expr: &ast::NodeRef| self.walk_check_expr(&check_expr.node), + schema_stmt.checks + ); + self.write_newline_without_fill(); + // Schema check dedent + self.write_indentation(Indentation::Dedent); + self.write_newline_without_fill(); + } + // Schema Stmt dedent + self.write_indentation(Indentation::Dedent); + } + + fn walk_rule_stmt(&mut self, rule_stmt: &'ctx ast::RuleStmt) -> Self::Result { + interleave!( + || self.write_newline(), + |expr: &ast::NodeRef| { + self.write("@"); + self.walk_call_expr(&expr.node); + }, + rule_stmt.decorators + ); + if !rule_stmt.decorators.is_empty() { + self.write_newline(); + } + self.write("rule "); + self.write(&rule_stmt.name.node); + if let Some(args) = &rule_stmt.args { + self.write("["); + self.walk_arguments(&args.node); + self.write("]"); + } + if !rule_stmt.parent_rules.is_empty() { + self.write("("); + interleave!( + || self.write(COMMA_WHITESPACE), + |identifier: &ast::NodeRef| self.walk_identifier(&identifier.node), + rule_stmt.parent_rules + ); + self.write(")"); + } + if let Some(host_name) = &rule_stmt.for_host_name { + self.write(" for "); + self.walk_identifier(&host_name.node); + } + self.write_token(TokenKind::Colon); + // Rule Stmt indent + self.write_indentation(Indentation::IndentWithNewline); + if !rule_stmt.doc.is_empty() { + self.write(&rule_stmt.doc); + self.write_newline(); + } + if !rule_stmt.checks.is_empty() { + interleave!( + || self.write_newline(), + |check_expr: &ast::NodeRef| self.walk_check_expr(&check_expr.node), + rule_stmt.checks + ); + self.write_newline_without_fill(); + } + // Rule Stmt dedent + self.write_indentation(Indentation::Dedent); + } + + fn walk_quant_expr(&mut self, quant_expr: &'ctx ast::QuantExpr) -> Self::Result { + let in_one_line = false; + let quant_op_string: String = quant_expr.op.clone().into(); + self.write(&quant_op_string); + self.write_space(); + interleave!( + || self.write(COMMA_WHITESPACE), + |identifier: &ast::NodeRef| self.walk_identifier(&identifier.node), + quant_expr.variables + ); + self.write(" in "); + self.expr(&quant_expr.target); + self.write(" {"); + if !in_one_line { + self.write_indentation(Indentation::IndentWithNewline); + } + self.expr(&quant_expr.test); + if let Some(if_cond) = &quant_expr.if_cond { + self.write(" if "); + self.expr(if_cond); + } + if !in_one_line { + self.write_indentation(Indentation::DedentWithNewline) + } + self.write("}") + } + + fn walk_schema_attr(&mut self, schema_attr: &'ctx ast::SchemaAttr) -> Self::Result { + interleave!( + || self.write_newline(), + |expr: &ast::NodeRef| { + self.write("@"); + self.walk_call_expr(&expr.node) + }, + schema_attr.decorators + ); + if !schema_attr.decorators.is_empty() { + self.write_newline(); + } + self.write(&schema_attr.name.node); + if schema_attr.is_optional { + self.write("?"); + } + self.write(": "); + self.write(&schema_attr.type_str.node); + if let Some(op) = &schema_attr.op { + let symbol = match op { + ast::BinOrAugOp::Bin(bin_op) => bin_op.symbol(), + ast::BinOrAugOp::Aug(aug_op) => aug_op.symbol(), + }; + self.write_space(); + self.write(symbol); + self.write_space(); + } + if let Some(value) = &schema_attr.value { + self.expr(value); + } + self.write_newline_without_fill(); + } + + fn walk_if_expr(&mut self, if_expr: &'ctx ast::IfExpr) -> Self::Result { + self.expr(&if_expr.body); + self.write(" if "); + self.expr(&if_expr.cond); + self.write(" else "); + self.expr(&if_expr.orelse); + } + + fn walk_unary_expr(&mut self, unary_expr: &'ctx ast::UnaryExpr) -> Self::Result { + self.write(unary_expr.op.symbol()); + // Four forms: `+expr`, `-expr`, `~expr`, `not expr` + // `not expr` needs a space between `not` and `expr` + if matches!(unary_expr.op, ast::UnaryOp::Not) { + self.write_space(); + } + self.expr(&unary_expr.operand); + } + + fn walk_binary_expr(&mut self, binary_expr: &'ctx ast::BinaryExpr) -> Self::Result { + let symbol = match &binary_expr.op { + ast::BinOrCmpOp::Bin(bin_op) => bin_op.symbol(), + ast::BinOrCmpOp::Cmp(cmp_op) => cmp_op.symbol(), + }; + self.expr(&binary_expr.left); + self.write_space(); + self.write(symbol); + self.write_space(); + self.expr(&binary_expr.right); + } + + fn walk_selector_expr(&mut self, selector_expr: &'ctx ast::SelectorExpr) -> Self::Result { + self.expr(&selector_expr.value); + self.write(if selector_expr.has_question { + "?." + } else { + "." + }); + self.walk_identifier(&selector_expr.attr.node); + } + + fn walk_call_expr(&mut self, call_expr: &'ctx ast::CallExpr) -> Self::Result { + self.expr(&call_expr.func); + self.write("("); + self.write_args_and_kwargs(&call_expr.args, &call_expr.keywords); + self.write(")"); + } + + fn walk_subscript(&mut self, subscript: &'ctx ast::Subscript) -> Self::Result { + self.expr(&subscript.value); + if subscript.has_question { + self.write("?"); + } + self.write("["); + if let Some(index) = &subscript.index { + self.expr(index); + } else { + if let Some(lower) = &subscript.lower { + self.expr(lower); + } + self.write_token(TokenKind::Colon); + if let Some(upper) = &subscript.upper { + self.expr(upper); + } + self.write_token(TokenKind::Colon); + if let Some(step) = &subscript.step { + self.expr(step); + } + } + self.write("]"); + } + + fn walk_paren_expr(&mut self, paren_expr: &'ctx ast::ParenExpr) -> Self::Result { + self.write_token(TokenKind::OpenDelim(DelimToken::Paren)); + self.expr(&paren_expr.expr); + self.write_token(TokenKind::CloseDelim(DelimToken::Paren)); + } + + fn walk_list_expr(&mut self, list_expr: &'ctx ast::ListExpr) -> Self::Result { + let line_set = list_expr + .elts + .iter() + .map(|e| e.line) + .collect::>(); + let mut in_one_line = line_set.len() <= 1; + if let Some(elt) = list_expr.elts.first() { + if let ast::Expr::ListIfItem(_) = &elt.node { + in_one_line = false; + } + } + self.write_token(TokenKind::OpenDelim(DelimToken::Bracket)); + if !in_one_line { + self.write_indentation(Indentation::IndentWithNewline); + } + interleave!( + || if in_one_line { + self.write(COMMA_WHITESPACE); + } else { + self.write_newline(); + }, + |elt| self.expr(elt), + list_expr.elts + ); + if !in_one_line { + self.write_indentation(Indentation::DedentWithNewline); + } + self.write_token(TokenKind::CloseDelim(DelimToken::Bracket)); + } + + fn walk_list_comp(&mut self, list_comp: &'ctx ast::ListComp) -> Self::Result { + self.write_token(TokenKind::OpenDelim(DelimToken::Bracket)); + self.expr(&list_comp.elt); + for gen in &list_comp.generators { + self.walk_comp_clause(&gen.node); + } + self.write_token(TokenKind::CloseDelim(DelimToken::Bracket)); + } + + fn walk_list_if_item_expr( + &mut self, + list_if_item_expr: &'ctx ast::ListIfItemExpr, + ) -> Self::Result { + self.write("if "); + self.expr(&list_if_item_expr.if_cond); + self.write(":"); + self.write_indentation(Indentation::IndentWithNewline); + interleave!( + || self.write_newline(), + |expr| self.expr(expr), + list_if_item_expr.exprs + ); + self.write_indentation(Indentation::DedentWithNewline); + if let Some(orelse) = &list_if_item_expr.orelse { + match &orelse.node { + ast::Expr::List(list_expr) => { + self.write("else:"); + self.write_indentation(Indentation::IndentWithNewline); + interleave!( + || self.write_newline(), + |expr| self.expr(expr), + list_expr.elts + ); + self.write_indentation(Indentation::Dedent); + } + ast::Expr::ListIfItem(_) => { + self.write("el"); + self.expr(orelse); + } + _ => bug!("Invalid list if expr orelse node {:?}", orelse.node), + } + } + } + + fn walk_starred_expr(&mut self, starred_expr: &'ctx ast::StarredExpr) -> Self::Result { + self.write("*"); + self.expr(&starred_expr.value) + } + + fn walk_dict_comp(&mut self, dict_comp: &'ctx ast::DictComp) -> Self::Result { + self.write_token(TokenKind::OpenDelim(DelimToken::Brace)); + self.expr(match &dict_comp.entry.key { + Some(key) => key, + None => bug!("Invalid dict comp key"), + }); + if !matches!(dict_comp.entry.operation, ast::ConfigEntryOperation::Union) { + self.write_space(); + } + self.write(dict_comp.entry.operation.symbol()); + self.write_space(); + for gen in &dict_comp.generators { + self.walk_comp_clause(&gen.node); + } + self.write_token(TokenKind::CloseDelim(DelimToken::Brace)); + } + + fn walk_config_if_entry_expr( + &mut self, + config_if_entry_expr: &'ctx ast::ConfigIfEntryExpr, + ) -> Self::Result { + self.write("if "); + self.expr(&config_if_entry_expr.if_cond); + self.write_token(TokenKind::Colon); + self.write_indentation(Indentation::IndentWithNewline); + interleave!( + || self.write_newline(), + |entry: &ast::NodeRef| self.write_entry(entry), + config_if_entry_expr.items + ); + self.write_indentation(Indentation::DedentWithNewline); + if let Some(orelse) = &config_if_entry_expr.orelse { + match &orelse.node { + ast::Expr::Config(config_expr) => { + self.write("else:"); + self.write_indentation(Indentation::IndentWithNewline); + interleave!( + || self.write_newline(), + |entry: &ast::NodeRef| self.write_entry(entry), + config_expr.items + ); + self.write_indentation(Indentation::Dedent); + } + ast::Expr::ConfigIfEntry(_) => { + self.write("el"); + self.expr(orelse); + } + _ => bug!("Invalid config if expr orelse node {:?}", orelse.node), + } + } + } + + fn walk_comp_clause(&mut self, comp_clause: &'ctx ast::CompClause) -> Self::Result { + self.write(" for "); + interleave!( + || self.write(COMMA_WHITESPACE), + |target: &ast::NodeRef| self.walk_identifier(&target.node), + comp_clause.targets + ); + self.write(" in "); + self.expr(&comp_clause.iter); + for if_clause in &comp_clause.ifs { + self.write(" if "); + self.expr(if_clause); + } + } + + fn walk_schema_expr(&mut self, schema_expr: &'ctx ast::SchemaExpr) -> Self::Result { + self.walk_identifier(&schema_expr.name.node); + if !schema_expr.args.is_empty() || !schema_expr.kwargs.is_empty() { + self.write_token(TokenKind::OpenDelim(DelimToken::Paren)); + self.write_args_and_kwargs(&schema_expr.args, &schema_expr.kwargs); + self.write_token(TokenKind::CloseDelim(DelimToken::Paren)); + } + self.write_space(); + self.expr(&schema_expr.config) + } + + fn walk_config_expr(&mut self, config_expr: &'ctx ast::ConfigExpr) -> Self::Result { + let line_set: HashSet = config_expr.items.iter().map(|item| item.line).collect(); + let mut in_one_line = line_set.len() <= 1; + if let Some(item) = config_expr.items.first() { + if let ast::Expr::ConfigIfEntry(_) = &item.node.value.node { + in_one_line = false; + } + } + self.write_token(TokenKind::OpenDelim(DelimToken::Brace)); + if !config_expr.items.is_empty() { + if !in_one_line { + self.write_indentation(Indentation::IndentWithNewline); + } + interleave!( + || if in_one_line { + self.write(COMMA_WHITESPACE); + } else { + self.write_newline(); + }, + |entry: &ast::NodeRef| self.write_entry(entry), + config_expr.items + ); + if !in_one_line { + self.write_indentation(Indentation::DedentWithNewline); + } + } + self.write_token(TokenKind::CloseDelim(DelimToken::Brace)); + } + + fn walk_check_expr(&mut self, check_expr: &'ctx ast::CheckExpr) -> Self::Result { + self.expr(&check_expr.test); + if let Some(if_cond) = &check_expr.if_cond { + self.write(" if "); + self.expr(if_cond); + } + if let Some(msg) = &check_expr.msg { + self.write(COMMA_WHITESPACE); + self.expr(msg); + } + } + + fn walk_lambda_expr(&mut self, lambda_expr: &'ctx ast::LambdaExpr) -> Self::Result { + self.write("lambda"); + if let Some(args) = &lambda_expr.args { + self.write_space(); + self.walk_arguments(&args.node); + } + if let Some(ty_str) = &lambda_expr.return_type_str { + self.write_space(); + self.write_token(TokenKind::RArrow); + self.write_space(); + self.write(ty_str); + } + self.write_space(); + self.write_token(TokenKind::OpenDelim(DelimToken::Brace)); + self.write_newline(); + self.write_indentation(Indentation::Indent); + + // lambda body + self.stmts(&lambda_expr.body); + + self.write_indentation(Indentation::Dedent); + self.write_newline(); + self.write_token(TokenKind::CloseDelim(DelimToken::Brace)); + } + + fn walk_keyword(&mut self, keyword: &'ctx ast::Keyword) -> Self::Result { + self.walk_identifier(&keyword.arg.node); + if let Some(value) = &keyword.value { + self.write("="); + self.expr(value); + } + } + + fn walk_arguments(&mut self, arguments: &'ctx ast::Arguments) -> Self::Result { + let parameter_zip_list: Vec> = arguments + .args + .iter() + .zip(arguments.type_annotation_list.iter()) + .zip(arguments.defaults.iter()) + .collect(); + interleave!( + || self.write(COMMA_WHITESPACE), + |para: &ParameterType<'_>| { + let ((arg, ty_str), default) = para; + self.walk_identifier(&arg.node); + if let Some(ty_str) = ty_str { + self.write(&format!(": {}", ty_str.node)); + } + if let Some(default) = default { + self.write(" = "); + self.expr(default); + } + }, + parameter_zip_list + ); + } + + fn walk_compare(&mut self, compare: &'ctx ast::Compare) -> Self::Result { + self.expr(&compare.left); + for (op, expr) in compare.ops.iter().zip(compare.comparators.iter()) { + self.write_space(); + self.write(op.symbol()); + self.write_space(); + self.expr(expr); + } + } + + #[inline] + fn walk_identifier(&mut self, identifier: &'ctx ast::Identifier) -> Self::Result { + self.write(&identifier.get_name()); + } + + fn walk_number_lit(&mut self, number_lit: &'ctx ast::NumberLit) -> Self::Result { + match number_lit.value { + ast::NumberLitValue::Int(int_val) => self.write(&int_val.to_string()), + ast::NumberLitValue::Float(float_val) => self.write(&float_val.to_string()), + } + } + + fn walk_string_lit(&mut self, string_lit: &'ctx ast::StringLit) -> Self::Result { + if !string_lit.raw_value.is_empty() { + self.write(&string_lit.raw_value) + } else { + self.write(&format!("\"{}\"", string_lit.value.replace('\"', "\\\""))); + } + } + + #[inline] + fn walk_name_constant_lit( + &mut self, + name_constant_lit: &'ctx ast::NameConstantLit, + ) -> Self::Result { + self.write(name_constant_lit.value.symbol()); + } + + fn walk_joined_string(&mut self, joined_string: &'ctx ast::JoinedString) -> Self::Result { + self.write("\""); + for value in &joined_string.values { + match &value.node { + ast::Expr::StringLit(string_lit) => { + self.write(&string_lit.value.replace('\"', "\\\"")); + } + _ => self.expr(value), + } + } + self.write("\""); + } + + fn walk_formatted_value(&mut self, formatted_value: &'ctx ast::FormattedValue) -> Self::Result { + self.write("${"); + self.expr(&formatted_value.value); + if let Some(spec) = &formatted_value.format_spec { + self.write(&format!(": {}", spec)); + } + self.write("}"); + } + + fn walk_comment(&mut self, comment: &'ctx ast::Comment) -> Self::Result { + self.writeln(&comment.text); + self.fill(""); + } +} + +impl<'p> Printer<'p> { + pub fn write_args_and_kwargs( + &mut self, + args: &[ast::NodeRef], + kwargs: &[ast::NodeRef], + ) { + interleave!(|| self.write(COMMA_WHITESPACE), |arg| self.expr(arg), args); + if !args.is_empty() && !kwargs.is_empty() { + self.write(COMMA_WHITESPACE); + } + interleave!( + || self.write(COMMA_WHITESPACE), + |kwarg: &ast::NodeRef| self.walk_keyword(&kwarg.node), + kwargs + ); + } + + pub fn write_entry(&mut self, item: &ast::NodeRef) { + match &item.node.key { + Some(key) => { + let print_right_brace_count = self.write_config_key(key); + if item.node.insert_index >= 0 { + self.write(&format!("[{}]", item.node.insert_index)); + } + if !matches!(item.node.operation, ast::ConfigEntryOperation::Union) { + self.write_space(); + } + self.write(item.node.operation.symbol()); + self.write_space(); + self.expr(&item.node.value); + self.write(&"}".repeat(print_right_brace_count)); + } + None => { + if !matches!(&item.node.value.node, ast::Expr::ConfigIfEntry(_)) { + self.write("**"); + } + self.expr(&item.node.value) + } + }; + } + + fn write_config_key(&mut self, key: &ast::NodeRef) -> usize { + match &key.node { + ast::Expr::Identifier(identifier) => { + self.hook.pre(self, super::ASTNode::Expr(key)); + self.write_ast_comments(key); + // Judge contains string identifier, e.g., "x-y-z" + let names = &identifier.names; + + let re = fancy_regex::Regex::new(IDENTIFIER_REGEX).unwrap(); + let need_right_brace = !names.iter().all(|n| re.is_match(n).unwrap_or(false)); + let count = if need_right_brace { + self.write( + &names + .iter() + .map(|n| n.replace('\"', "\\\"")) + .collect::>() + .join(": {"), + ); + names.len() - 1 + } else { + self.expr(key); + 0 + }; + self.hook.post(self, super::ASTNode::Expr(key)); + count + } + _ => { + self.expr(key); + 0 + } + } + } +} + +impl<'p> Printer<'p> { + // ------------------------------ + // Expr and Stmt walker functions + // ------------------------------ + + pub fn expr(&mut self, expr: &ast::NodeRef) { + self.hook.pre(self, super::ASTNode::Expr(expr)); + self.write_ast_comments(expr); + self.walk_expr(&expr.node); + self.hook.post(self, super::ASTNode::Expr(expr)); + } + + pub fn stmt(&mut self, stmt: &ast::NodeRef) { + self.hook.pre(self, super::ASTNode::Stmt(stmt)); + self.fill(""); + self.write_ast_comments(stmt); + self.walk_stmt(&stmt.node); + self.hook.post(self, super::ASTNode::Stmt(stmt)); + } + + pub fn exprs(&mut self, exprs: &[ast::NodeRef]) { + for expr in exprs { + self.expr(expr); + } + } + + pub fn stmts(&mut self, stmts: &[ast::NodeRef]) { + for stmt in stmts { + self.stmt(stmt); + } + } +} diff --git a/kclvm/ast/src/printer/test_data/arguments.input b/kclvm/ast/src/printer/test_data/arguments.input new file mode 100644 index 000000000..d356f83fb --- /dev/null +++ b/kclvm/ast/src/printer/test_data/arguments.input @@ -0,0 +1,6 @@ +schema Config[nameVar, textVar: str, idVar: int = 1]: + name: str = nameVar + text: str = textVar + id?: int = idVar + +config = Config("test", "text") diff --git a/kclvm/ast/src/printer/test_data/arguments.output b/kclvm/ast/src/printer/test_data/arguments.output new file mode 100644 index 000000000..d356f83fb --- /dev/null +++ b/kclvm/ast/src/printer/test_data/arguments.output @@ -0,0 +1,6 @@ +schema Config[nameVar, textVar: str, idVar: int = 1]: + name: str = nameVar + text: str = textVar + id?: int = idVar + +config = Config("test", "text") diff --git a/kclvm/ast/src/printer/test_data/codelayout.input b/kclvm/ast/src/printer/test_data/codelayout.input new file mode 100644 index 000000000..b8eeb768d --- /dev/null +++ b/kclvm/ast/src/printer/test_data/codelayout.input @@ -0,0 +1,76 @@ + + + +import math as alias_math +schema Person ( Base): + name:str + age:int + check : + age>0 if age , "age must > 0" +person = Person{ + name:"Alice" + age:18 +} +if True: + a = 1 +elif True: + b = 2 +else: + c = 3 +d = 1 + 2 +e = ( 1 + 2 ) +f=[ 1, 2, 3 ] +g = { "key" : "value" } +print (1) +dct={"key": "value"} +lst=[1,2,3] +h = dct [ 'key' ] +i = lst [ 1 ] +x = 1 +y = 2 +long_variable = 3 +i = i+1 +submitted+=1 +x = x*2 - 1 +hypot2 = x*x + y*y +_c = (a+b) * (a-b) +_b=2 +_c= 3 +_d =4 + +_value = (1 + 2 * 3) +_value = (1+2*3) +_value =1+ - 2 * ~ 3 +_list = [1, 2, 3] +_list = [*_list, [4, 5 ,6]] +_list = [* _list, [4, 5 ,6]] + +_dict = {** {"k": "v"}, ** {"k": "v"}} +a = [1,2,3] +b = [ + 1,2,3, + 4,5,6, +] +_dict={ + "k1":"v1" + "k2" :"v2" + "k3": "v3" + "k4" : "v4" + "k5" : "v5" +} +foo=1 +if foo is not None: + _a = 1 + _dict|={} + hello = "world{}" . format( 1 )[2 : 4] . lower( ) + range_int = [ i for i in range( 10 ) ] +op = 1+2 - - 3 + (3 - 1) // 3 +op += 1 +op -= 12 + 23 +print( " " , end= '') +log = math. log(12) +aa = 1 +assert aa == 1,"message" +assert aa == 1 if aa,"message" +aaaa = (1 + 2 / 2) if _a == 2 + + 134.3 else ("a"*3) +bbbb = "{}". format(a) \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/codelayout.output b/kclvm/ast/src/printer/test_data/codelayout.output new file mode 100644 index 000000000..28fa41ccc --- /dev/null +++ b/kclvm/ast/src/printer/test_data/codelayout.output @@ -0,0 +1,79 @@ +import math as alias_math +schema Person(Base): + name: str + age: int + + check: + age > 0 if age, "age must > 0" + +person = Person { + name: "Alice" + age: 18 +} + +if True: + a = 1 +elif True: + b = 2 +else: + c = 3 +d = 1 + 2 +e = (1 + 2) +f = [1, 2, 3] +g = {"key": "value"} +print(1) +dct = {"key": "value"} +lst = [1, 2, 3] +h = dct['key'] +i = lst[1] +x = 1 +y = 2 +long_variable = 3 +i = i + 1 +submitted += 1 +x = x * 2 - 1 +hypot2 = x * x + y * y +_c = (a + b) * (a - b) +_b = 2 +_c = 3 +_d = 4 +_value = (1 + 2 * 3) +_value = (1 + 2 * 3) +_value = 1 + -2 * ~3 +_list = [1, 2, 3] +_list = [*_list, [4, 5, 6]] +_list = [*_list, [4, 5, 6]] +_dict = {**{"k": "v"}, **{"k": "v"}} +a = [1, 2, 3] +b = [ + 1 + 2 + 3 + 4 + 5 + 6 +] +_dict = { + "k1": "v1" + "k2": "v2" + "k3": "v3" + "k4": "v4" + "k5": "v5" +} +foo = 1 +if foo is not None: + _a = 1 + _dict |= {} + hello = "world{}".format(1)[2:4:].lower() + range_int = [i for i in range(10)] + +op = 1 + 2 - -3 + (3 - 1) // 3 +op += 1 +op -= 12 + 23 +print(" ", end='') +log = math.log(12) +aa = 1 +assert aa == 1, "message" +assert aa == 1 if aa, "message" +aaaa = (1 + 2 / 2) if _a == 2 + +134.3 else ("a" * 3) +bbbb = "{}".format(a) diff --git a/kclvm/ast/src/printer/test_data/collection_if.input b/kclvm/ast/src/printer/test_data/collection_if.input new file mode 100644 index 000000000..080538c1c --- /dev/null +++ b/kclvm/ast/src/printer/test_data/collection_if.input @@ -0,0 +1,51 @@ +schema Config: + name: str + env: str + data: [int] +env = "env" +data1 = Config { + if env == "env": + name: env + env: env + data += [0] + else: + name = "name" + env = "name" + data += [1] +} +data1 = Config { + if env == "env": + name: env + env: env + else: + name: "name" + env: "name" +} +data2 = Config { + if env != "env": + name: env + env: env + else: + name: "name" + env: "name" +} +data3 = { + if True: + key1: "value1" + elif True: + key2: "value2" + elif True: + key3: "value3" + else: + key4: "value4" +} +data4 = [ + if True: + "value1" + elif True: + "value2" + elif True: + "value3" + else: + "value4" +] diff --git a/kclvm/ast/src/printer/test_data/collection_if.output b/kclvm/ast/src/printer/test_data/collection_if.output new file mode 100644 index 000000000..009f8947a --- /dev/null +++ b/kclvm/ast/src/printer/test_data/collection_if.output @@ -0,0 +1,55 @@ +schema Config: + name: str + env: str + data: [int] + +env = "env" +data1 = Config { + if env == "env": + name: env + env: env + data += [0] + else: + name = "name" + env = "name" + data += [1] +} + +data1 = Config { + if env == "env": + name: env + env: env + else: + name: "name" + env: "name" +} + +data2 = Config { + if env != "env": + name: env + env: env + else: + name: "name" + env: "name" +} + +data3 = { + if True: + key1: "value1" + elif True: + key2: "value2" + elif True: + key3: "value3" + else: + key4: "value4" +} +data4 = [ + if True: + "value1" + elif True: + "value2" + elif True: + "value3" + else: + "value4" +] diff --git a/kclvm/ast/src/printer/test_data/comment.input b/kclvm/ast/src/printer/test_data/comment.input new file mode 100644 index 000000000..681a69c31 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/comment.input @@ -0,0 +1,38 @@ +# Comment One +schema Main: + name?: str + env?: [{str:}] + +# Comment Two +schema AppConfiguration: + appName: str + image: str + overQuota: bool = False + resource: {str:} + mainContainer?: Main + labels: {str:} + +# Comment Three +appConfiguration = AppConfiguration { + # Comment Four + appName: "kusion" + image: "test-image:v1" # Comment Five + resource: { + cpu: "4" + disk: "50Gi" + memory: "12Gi" + } + labels: { + key: { + key: 12 + } + } + # Comment Six + mainContainer: Main { + name: "kusion_override" + }# Comment Seven + + # Comment Eight + overQuota: True +} +# Comment Nine diff --git a/kclvm/ast/src/printer/test_data/comment.output b/kclvm/ast/src/printer/test_data/comment.output new file mode 100644 index 000000000..bae5a376c --- /dev/null +++ b/kclvm/ast/src/printer/test_data/comment.output @@ -0,0 +1,34 @@ +# Comment One +schema Main: + name?: str + env?: [{str:}] + +# Comment Two +schema AppConfiguration: + appName: str + image: str + overQuota: bool = False + resource: {str:} + mainContainer?: Main + labels: {str:} + +# Comment Three +appConfiguration = AppConfiguration { + # Comment Four + appName: "kusion" + # Comment Five + image: "test-image:v1" + resource: { + cpu: "4" + disk: "50Gi" + memory: "12Gi" + } + labels: {key: {key: 12}} + # Comment Six + mainContainer: Main {name: "kusion_override"} + # Comment Seven + # Comment Eight + overQuota: True +} + +# Comment Nine diff --git a/kclvm/ast/src/printer/test_data/empty.input b/kclvm/ast/src/printer/test_data/empty.input new file mode 100644 index 000000000..fd40910d9 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/empty.input @@ -0,0 +1,4 @@ + + + + diff --git a/kclvm/ast/src/printer/test_data/empty.output b/kclvm/ast/src/printer/test_data/empty.output new file mode 100644 index 000000000..e69de29bb diff --git a/kclvm/ast/src/printer/test_data/if_stmt.input b/kclvm/ast/src/printer/test_data/if_stmt.input new file mode 100644 index 000000000..40aeb4d0a --- /dev/null +++ b/kclvm/ast/src/printer/test_data/if_stmt.input @@ -0,0 +1,16 @@ +if True: + a = 1 +elif True: + b = 2 +else: + c = 3 + +if True: + if False: + d = 4 + elif True: + e = 5 + else: + f = 6 +else: + g = 7 diff --git a/kclvm/ast/src/printer/test_data/if_stmt.output b/kclvm/ast/src/printer/test_data/if_stmt.output new file mode 100644 index 000000000..8a20e1acd --- /dev/null +++ b/kclvm/ast/src/printer/test_data/if_stmt.output @@ -0,0 +1,15 @@ +if True: + a = 1 +elif True: + b = 2 +else: + c = 3 +if True: + if False: + d = 4 + elif True: + e = 5 + else: + f = 6 +else: + g = 7 diff --git a/kclvm/ast/src/printer/test_data/import.input b/kclvm/ast/src/printer/test_data/import.input new file mode 100644 index 000000000..c25142c17 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/import.input @@ -0,0 +1,4 @@ +import path.to.pkg +import path.to.pkg as abs_pkg_alias +import .relative.path +import .relative.path as re_pkg_alias diff --git a/kclvm/ast/src/printer/test_data/import.output b/kclvm/ast/src/printer/test_data/import.output new file mode 100644 index 000000000..c25142c17 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/import.output @@ -0,0 +1,4 @@ +import path.to.pkg +import path.to.pkg as abs_pkg_alias +import .relative.path +import .relative.path as re_pkg_alias diff --git a/kclvm/ast/src/printer/test_data/index_sign.input b/kclvm/ast/src/printer/test_data/index_sign.input new file mode 100644 index 000000000..54d611873 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/index_sign.input @@ -0,0 +1,12 @@ +schema Data: + [str]: any + +schema DataOther: + [...str]: str + id?: int + +schema DataMap: + [name: str]: str + check: + name in ["A", "B", "C"] + \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/index_sign.output b/kclvm/ast/src/printer/test_data/index_sign.output new file mode 100644 index 000000000..7da6687ac --- /dev/null +++ b/kclvm/ast/src/printer/test_data/index_sign.output @@ -0,0 +1,13 @@ +schema Data: + [str]: any + +schema DataOther: + [...str]: str + id?: int + +schema DataMap: + [name: str]: str + + check: + name in ["A", "B", "C"] + diff --git a/kclvm/ast/src/printer/test_data/joined_str.input b/kclvm/ast/src/printer/test_data/joined_str.input new file mode 100644 index 000000000..8af336d4a --- /dev/null +++ b/kclvm/ast/src/printer/test_data/joined_str.input @@ -0,0 +1,3 @@ +a = 1 +b = "${a}" +c = "a.${1}" diff --git a/kclvm/ast/src/printer/test_data/joined_str.output b/kclvm/ast/src/printer/test_data/joined_str.output new file mode 100644 index 000000000..8af336d4a --- /dev/null +++ b/kclvm/ast/src/printer/test_data/joined_str.output @@ -0,0 +1,3 @@ +a = 1 +b = "${a}" +c = "a.${1}" diff --git a/kclvm/ast/src/printer/test_data/lambda.input b/kclvm/ast/src/printer/test_data/lambda.input new file mode 100644 index 000000000..5402976ca --- /dev/null +++ b/kclvm/ast/src/printer/test_data/lambda.input @@ -0,0 +1,20 @@ +sumFunc1 = lambda x, y { + z = x + y + z + x +} +sumFunc2 = lambda x, y = 1 { + x + y + +} +sumFunc3 = lambda x = 1, y = 1 { + x + y + +} +sumFunc4 = lambda x: int = 1, y: int = 1 -> int { + x + y + +} +x0 = sumFunc1(1, 2) +x1 = sumFunc1(2, 3) +x2 = sumFunc1(3, 4) +x3 = sumFunc1(4, 5) diff --git a/kclvm/ast/src/printer/test_data/lambda.output b/kclvm/ast/src/printer/test_data/lambda.output new file mode 100644 index 000000000..db23acee4 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/lambda.output @@ -0,0 +1,21 @@ +sumFunc1 = lambda x, y { + z = x + y + z + x + +} +sumFunc2 = lambda x, y = 1 { + x + y + +} +sumFunc3 = lambda x = 1, y = 1 { + x + y + +} +sumFunc4 = lambda x: int = 1, y: int = 1 -> int { + x + y + +} +x0 = sumFunc1(1, 2) +x1 = sumFunc1(2, 3) +x2 = sumFunc1(3, 4) +x3 = sumFunc1(4, 5) diff --git a/kclvm/ast/src/printer/test_data/quant.input b/kclvm/ast/src/printer/test_data/quant.input new file mode 100644 index 000000000..23022c694 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/quant.input @@ -0,0 +1,8 @@ +a = all x in [-1, 0, 1, 2, 3] { + x >= 1 if x > 0 +} +b = any x in {k1 = "v1", k2 = "v2"} {x in ["k1", "v2"]} +c = map x in {k1 = "v1", k2 = "v2"} {x} +d = filter x in [1, 2, 3] { + x > 1 +} \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/quant.output b/kclvm/ast/src/printer/test_data/quant.output new file mode 100644 index 000000000..4d35a3ba6 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/quant.output @@ -0,0 +1,12 @@ +a = all x in [-1, 0, 1, 2, 3] { + x >= 1 if x > 0 +} +b = any x in {k1 = "v1", k2 = "v2"} { + x in ["k1", "v2"] +} +c = map x in {k1 = "v1", k2 = "v2"} { + x +} +d = filter x in [1, 2, 3] { + x > 1 +} diff --git a/kclvm/ast/src/printer/test_data/rule.input b/kclvm/ast/src/printer/test_data/rule.input new file mode 100644 index 000000000..662e8eec3 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/rule.input @@ -0,0 +1,19 @@ +age = 1 + +schema MainProtocol: + """Protocol doc""" + var: int + +schema MainMixin for MainProtocol: + var: int + +@deprecated +rule Base: + """Rule doc""" + age > 0 + age < 10 + +rule Main[var](Base) for MainProtocol: + var + +Main(1) diff --git a/kclvm/ast/src/printer/test_data/rule.output b/kclvm/ast/src/printer/test_data/rule.output new file mode 100644 index 000000000..6d4543302 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/rule.output @@ -0,0 +1,16 @@ +age = 1 +protocol MainProtocol: + """Protocol doc""" + var: int + +mixin MainMixin for MainProtocol: + var: int + +@deprecated() +rule Base: + """Rule doc""" + age > 0 + age < 10 +rule Main[var](Base) for MainProtocol: + var +Main(1) diff --git a/kclvm/ast/src/printer/test_data/type_alias.input b/kclvm/ast/src/printer/test_data/type_alias.input new file mode 100644 index 000000000..9924443d4 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/type_alias.input @@ -0,0 +1,18 @@ +type Color = "Red" | "Yellow" | "Blue" + +colorRed: Color = "Red" +colorYellow: Color = "Yellow" +colorBlue: Color = "Blue" + +schema Data: + color: Color + +dataColorRed = Data { + color = "Red" +} +dataColorYellow = Data { + color = "Yellow" +} +dataColorBlue = Data { + color = "Blue" +} diff --git a/kclvm/ast/src/printer/test_data/type_alias.output b/kclvm/ast/src/printer/test_data/type_alias.output new file mode 100644 index 000000000..d80ac1c1b --- /dev/null +++ b/kclvm/ast/src/printer/test_data/type_alias.output @@ -0,0 +1,13 @@ +type Color = "Red"|"Yellow"|"Blue" +colorRed: Color = "Red" +colorYellow: Color = "Yellow" +colorBlue: Color = "Blue" +schema Data: + color: Color + +dataColorRed = Data {color = "Red"} + +dataColorYellow = Data {color = "Yellow"} + +dataColorBlue = Data {color = "Blue"} + diff --git a/kclvm/ast/src/printer/test_data/unary.input b/kclvm/ast/src/printer/test_data/unary.input new file mode 100644 index 000000000..613bcab7c --- /dev/null +++ b/kclvm/ast/src/printer/test_data/unary.input @@ -0,0 +1,6 @@ +a = + 1 +b = - 1 +c = ~ 1 +d = not True +e = + 1 + + 1 +f = + 1 - - 1 diff --git a/kclvm/ast/src/printer/test_data/unary.output b/kclvm/ast/src/printer/test_data/unary.output new file mode 100644 index 000000000..552bdc5d0 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/unary.output @@ -0,0 +1,6 @@ +a = +1 +b = -1 +c = ~1 +d = not True +e = +1 + +1 +f = +1 - -1 diff --git a/kclvm/ast/src/printer/test_data/unification.input b/kclvm/ast/src/printer/test_data/unification.input new file mode 100644 index 000000000..22d05d0bb --- /dev/null +++ b/kclvm/ast/src/printer/test_data/unification.input @@ -0,0 +1,5 @@ +schema Config: + name: str +config: Config { + name = "name" +} \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/unification.output b/kclvm/ast/src/printer/test_data/unification.output new file mode 100644 index 000000000..4db7bd2d5 --- /dev/null +++ b/kclvm/ast/src/printer/test_data/unification.output @@ -0,0 +1,4 @@ +schema Config: + name: str + +config: Config {name = "name"} diff --git a/kclvm/ast/src/printer/tests.rs b/kclvm/ast/src/printer/tests.rs new file mode 100644 index 000000000..26f971ec9 --- /dev/null +++ b/kclvm/ast/src/printer/tests.rs @@ -0,0 +1,50 @@ +use std::path::PathBuf; + +use super::print_ast_module; +use kclvm_parser::parse_file; +use pretty_assertions::assert_eq; + +const FILE_INPUT_SUFFIX: &str = ".input"; +const FILE_OUTPUT_SUFFIX: &str = ".output"; +const TEST_CASES: &[&'static str; 15] = &[ + "arguments", + "empty", + "if_stmt", + "import", + "unary", + "codelayout", + "collection_if", + "comment", + "index_sign", + "joined_str", + "lambda", + "quant", + "rule", + "type_alias", + "unification", +]; + +fn read_data(data_name: &str) -> (String, String) { + let mut filename = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + filename.push(&format!("src/test_data/{}{}", data_name, FILE_INPUT_SUFFIX)); + + let module = parse_file(filename.to_str().unwrap(), None); + + let mut filename_expect = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + filename_expect.push(&format!( + "src/test_data/{}{}", + data_name, FILE_OUTPUT_SUFFIX + )); + ( + print_ast_module(&module.unwrap()), + std::fs::read_to_string(filename_expect.to_str().unwrap()).unwrap(), + ) +} + +#[test] +fn test_ast_printer() { + for case in TEST_CASES { + let (data_input, data_output) = read_data(case); + assert_eq!(data_input, data_output, "Test failed on {}", case); + } +} diff --git a/kclvm/ast_pretty/src/lib.rs b/kclvm/ast_pretty/src/lib.rs index 1c7f2f870..cab3ebaf9 100644 --- a/kclvm/ast_pretty/src/lib.rs +++ b/kclvm/ast_pretty/src/lib.rs @@ -6,6 +6,7 @@ use kclvm_ast::{ }; use std::collections::VecDeque; +use crate::{ast, token::TokenKind, walker::MutSelfTypedResultWalker}; mod node; #[cfg(test)] diff --git a/kclvm/ast_pretty/src/node.rs b/kclvm/ast_pretty/src/node.rs index c9db75b3f..00d354b3f 100644 --- a/kclvm/ast_pretty/src/node.rs +++ b/kclvm/ast_pretty/src/node.rs @@ -1,11 +1,17 @@ use std::collections::HashSet; +<<<<<<<< HEAD:kclvm/ast_pretty/src/node.rs use kclvm_ast::{ ast::{self, CallExpr}, token::{DelimToken, TokenKind}, walker::MutSelfTypedResultWalker, }; use kclvm_error::bug; +======== +use kclvm_error::bug; + +use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; +>>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs use super::{Indentation, Printer}; diff --git a/kclvm/tools/src/format/mod.rs b/kclvm/tools/src/format/mod.rs index 17539178f..97e90f9d1 100644 --- a/kclvm/tools/src/format/mod.rs +++ b/kclvm/tools/src/format/mod.rs @@ -11,6 +11,7 @@ use std::path::Path; use crate::util::get_kcl_files; use kclvm_parser::parse_file; +use kclvm_ast::printer::print_ast_module; #[cfg(test)] mod tests; diff --git a/kclvm/tools/src/query/override.rs b/kclvm/tools/src/query/override.rs index 413c5c10a..3defc4257 100644 --- a/kclvm/tools/src/query/override.rs +++ b/kclvm/tools/src/query/override.rs @@ -4,6 +4,7 @@ use anyhow::{anyhow, Result}; use kclvm_ast::config::try_get_config_expr_mut; use kclvm_ast::path::{get_attr_paths_from_config_expr, get_key_path}; +use kclvm_ast::printer::print_ast_module; use kclvm_ast::walker::MutSelfMutWalker; use kclvm_ast::{ast, walk_if_mut}; use kclvm_ast_pretty::print_ast_module; From 251c69dfe2ae46bb1fdef5090d9272d1ded07a7a Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sat, 8 Oct 2022 17:33:00 +0800 Subject: [PATCH 02/10] fmt --- kclvm/ast/src/lib.rs | 2 +- kclvm/ast/src/printer/node.rs | 8 ++++++++ kclvm/tools/src/format/mod.rs | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/kclvm/ast/src/lib.rs b/kclvm/ast/src/lib.rs index d764a8131..0f2cb628b 100644 --- a/kclvm/ast/src/lib.rs +++ b/kclvm/ast/src/lib.rs @@ -4,10 +4,10 @@ use crate::ast::*; pub mod ast; pub mod config; pub mod path; +pub mod printer; pub mod token; pub mod token_stream; pub mod walker; -pub mod printer; #[cfg(test)] mod tests; diff --git a/kclvm/ast/src/printer/node.rs b/kclvm/ast/src/printer/node.rs index 00d354b3f..80b4cb1d6 100644 --- a/kclvm/ast/src/printer/node.rs +++ b/kclvm/ast/src/printer/node.rs @@ -10,8 +10,16 @@ use kclvm_error::bug; ======== use kclvm_error::bug; +<<<<<<< HEAD use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; >>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs +======= +use crate::{ + ast::{self, CallExpr}, + token::{DelimToken, TokenKind}, + walker::MutSelfTypedResultWalker, +}; +>>>>>>> 55680e6 (fmt) use super::{Indentation, Printer}; diff --git a/kclvm/tools/src/format/mod.rs b/kclvm/tools/src/format/mod.rs index 97e90f9d1..f2196ae15 100644 --- a/kclvm/tools/src/format/mod.rs +++ b/kclvm/tools/src/format/mod.rs @@ -10,8 +10,8 @@ use kclvm_ast_pretty::print_ast_module; use std::path::Path; use crate::util::get_kcl_files; -use kclvm_parser::parse_file; use kclvm_ast::printer::print_ast_module; +use kclvm_parser::parse_file; #[cfg(test)] mod tests; From 2bd6372e1f16853d8c7d852860b9395ea7a40385 Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sat, 8 Oct 2022 20:28:11 +0800 Subject: [PATCH 03/10] mv query to ast_pretty --- kclvm/Cargo.lock | 3 + kclvm/ast/src/lib.rs | 1 - kclvm/ast/src/printer/mod.rs | 266 ------ kclvm/ast/src/printer/node.rs | 881 ------------------ .../ast/src/printer/test_data/arguments.input | 6 - .../src/printer/test_data/arguments.output | 6 - .../src/printer/test_data/codelayout.input | 76 -- .../src/printer/test_data/codelayout.output | 79 -- .../src/printer/test_data/collection_if.input | 51 - .../printer/test_data/collection_if.output | 55 -- kclvm/ast/src/printer/test_data/comment.input | 38 - .../ast/src/printer/test_data/comment.output | 34 - kclvm/ast/src/printer/test_data/empty.input | 4 - kclvm/ast/src/printer/test_data/empty.output | 0 kclvm/ast/src/printer/test_data/if_stmt.input | 16 - .../ast/src/printer/test_data/if_stmt.output | 15 - kclvm/ast/src/printer/test_data/import.input | 4 - kclvm/ast/src/printer/test_data/import.output | 4 - .../src/printer/test_data/index_sign.input | 12 - .../src/printer/test_data/index_sign.output | 13 - .../src/printer/test_data/joined_str.input | 3 - .../src/printer/test_data/joined_str.output | 3 - kclvm/ast/src/printer/test_data/lambda.input | 20 - kclvm/ast/src/printer/test_data/lambda.output | 21 - kclvm/ast/src/printer/test_data/quant.input | 8 - kclvm/ast/src/printer/test_data/quant.output | 12 - kclvm/ast/src/printer/test_data/rule.input | 19 - kclvm/ast/src/printer/test_data/rule.output | 16 - .../src/printer/test_data/type_alias.input | 18 - .../src/printer/test_data/type_alias.output | 13 - kclvm/ast/src/printer/test_data/unary.input | 6 - kclvm/ast/src/printer/test_data/unary.output | 6 - .../src/printer/test_data/unification.input | 5 - .../src/printer/test_data/unification.output | 4 - kclvm/ast/src/printer/tests.rs | 50 - kclvm/ast_pretty/Cargo.toml | 6 +- kclvm/ast_pretty/src/lib.rs | 11 + kclvm/ast_pretty/src/node.rs | 24 + kclvm/ast_pretty/src/tests.rs | 10 + kclvm/parser/src/lib.rs | 1 + kclvm/tools/src/format/mod.rs | 1 - kclvm/tools/src/query/override.rs | 1 - 42 files changed, 54 insertions(+), 1768 deletions(-) delete mode 100644 kclvm/ast/src/printer/mod.rs delete mode 100644 kclvm/ast/src/printer/node.rs delete mode 100644 kclvm/ast/src/printer/test_data/arguments.input delete mode 100644 kclvm/ast/src/printer/test_data/arguments.output delete mode 100644 kclvm/ast/src/printer/test_data/codelayout.input delete mode 100644 kclvm/ast/src/printer/test_data/codelayout.output delete mode 100644 kclvm/ast/src/printer/test_data/collection_if.input delete mode 100644 kclvm/ast/src/printer/test_data/collection_if.output delete mode 100644 kclvm/ast/src/printer/test_data/comment.input delete mode 100644 kclvm/ast/src/printer/test_data/comment.output delete mode 100644 kclvm/ast/src/printer/test_data/empty.input delete mode 100644 kclvm/ast/src/printer/test_data/empty.output delete mode 100644 kclvm/ast/src/printer/test_data/if_stmt.input delete mode 100644 kclvm/ast/src/printer/test_data/if_stmt.output delete mode 100644 kclvm/ast/src/printer/test_data/import.input delete mode 100644 kclvm/ast/src/printer/test_data/import.output delete mode 100644 kclvm/ast/src/printer/test_data/index_sign.input delete mode 100644 kclvm/ast/src/printer/test_data/index_sign.output delete mode 100644 kclvm/ast/src/printer/test_data/joined_str.input delete mode 100644 kclvm/ast/src/printer/test_data/joined_str.output delete mode 100644 kclvm/ast/src/printer/test_data/lambda.input delete mode 100644 kclvm/ast/src/printer/test_data/lambda.output delete mode 100644 kclvm/ast/src/printer/test_data/quant.input delete mode 100644 kclvm/ast/src/printer/test_data/quant.output delete mode 100644 kclvm/ast/src/printer/test_data/rule.input delete mode 100644 kclvm/ast/src/printer/test_data/rule.output delete mode 100644 kclvm/ast/src/printer/test_data/type_alias.input delete mode 100644 kclvm/ast/src/printer/test_data/type_alias.output delete mode 100644 kclvm/ast/src/printer/test_data/unary.input delete mode 100644 kclvm/ast/src/printer/test_data/unary.output delete mode 100644 kclvm/ast/src/printer/test_data/unification.input delete mode 100644 kclvm/ast/src/printer/test_data/unification.output delete mode 100644 kclvm/ast/src/printer/tests.rs diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index ad38aa34e..915761b5b 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -624,7 +624,10 @@ dependencies = [ "kclvm-ast", "kclvm-error", "kclvm-parser", +<<<<<<< HEAD "pretty_assertions", +======= +>>>>>>> b15d822 (mv query to ast_pretty) ] [[package]] diff --git a/kclvm/ast/src/lib.rs b/kclvm/ast/src/lib.rs index 0f2cb628b..edaf80490 100644 --- a/kclvm/ast/src/lib.rs +++ b/kclvm/ast/src/lib.rs @@ -4,7 +4,6 @@ use crate::ast::*; pub mod ast; pub mod config; pub mod path; -pub mod printer; pub mod token; pub mod token_stream; pub mod walker; diff --git a/kclvm/ast/src/printer/mod.rs b/kclvm/ast/src/printer/mod.rs deleted file mode 100644 index 8918bf1a6..000000000 --- a/kclvm/ast/src/printer/mod.rs +++ /dev/null @@ -1,266 +0,0 @@ -use indexmap::IndexMap; -use kclvm_ast::{ - ast::{self, Module}, - token::TokenKind, - walker::MutSelfTypedResultWalker, -}; -use std::collections::VecDeque; - -<<<<<<<< HEAD:kclvm/ast_pretty/src/lib.rs -======== -use crate::{ast, token::TokenKind, walker::MutSelfTypedResultWalker}; - ->>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/mod.rs -mod node; - -#[cfg(test)] -mod tests; - -pub const WHITESPACE: &str = " "; -pub const TAB: &str = "\t"; -pub const NEWLINE: &str = "\n"; - -#[derive(Debug, Clone)] -pub enum Indentation { - Indent = 0, - Dedent = 1, - Newline = 2, - IndentWithNewline = 3, - DedentWithNewline = 4, - Fill = 5, -} - -/// Printer config -#[derive(Debug)] -pub struct Config { - pub tab_len: usize, - pub indent_len: usize, - pub use_spaces: bool, - pub write_comments: bool, -} - -impl Default for Config { - fn default() -> Self { - Self { - tab_len: 4, - indent_len: 4, - use_spaces: true, - write_comments: true, - } - } -} - -#[derive(Copy, Clone)] -pub struct NoHook; - -impl PrinterHook for NoHook {} - -pub enum ASTNode<'p> { - Stmt(&'p ast::NodeRef), - Expr(&'p ast::NodeRef), -} - -pub trait PrinterHook { - fn pre(&self, _printer: &mut Printer<'_>, _node: ASTNode<'_>) {} - fn post(&self, _printer: &mut Printer<'_>, _node: ASTNode<'_>) {} -} - -pub struct Printer<'p> { - /// Output string buffer. - pub out: String, - pub indent: usize, - pub cfg: Config, - /// Print comments, - pub last_ast_line: u64, - pub comments: VecDeque>, - pub import_spec: IndexMap, - pub hook: &'p (dyn PrinterHook + 'p), -} - -impl Default for Printer<'_> { - fn default() -> Self { - Self { - out: Default::default(), - indent: Default::default(), - cfg: Default::default(), - last_ast_line: Default::default(), - comments: Default::default(), - import_spec: Default::default(), - hook: &NoHook, - } - } -} - -impl<'p> Printer<'p> { - pub fn new(cfg: Config, hook: &'p (dyn PrinterHook + 'p)) -> Self { - Self { - out: "".to_string(), - indent: 0, - cfg, - last_ast_line: 0, - comments: VecDeque::default(), - import_spec: IndexMap::default(), - hook, - } - } - - // -------------------------- - // Write functions - // -------------------------- - - /// Write a string - #[inline] - pub fn write(&mut self, text: &str) { - self.write_string(text); - } - - /// Write a string with newline. - #[inline] - pub fn writeln(&mut self, text: &str) { - self.write_string(text); - self.write_string(NEWLINE); - self.fill(""); - } - - /// Write a space. - #[inline] - pub fn write_space(&mut self) { - self.write_string(WHITESPACE); - } - - /// Fill a indent - pub fn fill(&mut self, text: &str) { - if self.cfg.use_spaces { - self.write(&format!( - "{}{}", - WHITESPACE.repeat(self.indent * self.cfg.indent_len), - text - )); - } else { - self.write(&format!("{}{}", TAB.repeat(self.indent), text)); - } - } - - /// Print string - #[inline] - pub fn write_string(&mut self, string: &str) { - self.out.push_str(string); - } - - pub fn write_indentation(&mut self, indentation: Indentation) { - match indentation { - Indentation::Indent => self.enter(), - Indentation::Dedent => self.leave(), - Indentation::Newline => self.write_newline(), - Indentation::IndentWithNewline => { - self.enter(); - self.write_newline() - } - Indentation::DedentWithNewline => { - self.leave(); - self.write_newline(); - } - Indentation::Fill => self.fill(""), - } - } - - #[inline] - pub fn write_newline(&mut self) { - self.writeln("") - } - - #[inline] - pub fn write_newline_without_fill(&mut self) { - self.write_string(NEWLINE); - } - - /// Print value - #[inline] - pub fn write_value(&mut self, value: T) { - self.write(&format!("{}", value)); - } - - /// Print ast token - #[inline] - pub fn write_token(&mut self, tok: TokenKind) { - let tok_str: String = tok.into(); - self.write_string(&tok_str); - } - - /// Print ast node - #[inline] - pub fn write_node(&mut self, node: ASTNode<'_>) { - match node { - ASTNode::Stmt(stmt) => self.stmt(stmt), - ASTNode::Expr(expr) => self.expr(expr), - } - } - - /// Print ast module. - #[inline] - pub fn write_module(&mut self, module: &ast::Module) { - self.walk_module(module); - while let Some(comment) = self.comments.pop_front() { - self.writeln(&comment.node.text); - self.fill(""); - } - } - - /// Print ast comments. - pub fn write_ast_comments(&mut self, node: &ast::NodeRef) { - if !self.cfg.write_comments { - return; - } - if node.line > self.last_ast_line { - self.last_ast_line = node.line; - let mut index = None; - for (i, comment) in self.comments.iter().enumerate() { - if comment.line <= node.line { - index = Some(i); - } else { - break; - } - } - if let Some(index) = index { - let mut count = index as isize; - while count >= 0 { - match self.comments.pop_front() { - Some(comment) => { - self.writeln(&comment.node.text); - } - None => break, - } - count -= 1; - } - } - } - } - - // -------------------------- - // Indent and scope functions - // -------------------------- - - /// Enter with a indent - pub fn enter(&mut self) { - self.indent += 1; - } - - /// Leave with a dedent - pub fn leave(&mut self) { - self.indent -= 1; - } -} - -/// Print AST to string -pub fn print_ast_module(module: &Module) -> String { - let mut printer = Printer::default(); - printer.write_module(module); - printer.out -} - -/// Print AST to string -pub fn print_ast_node(node: ASTNode) -> String { - let mut printer = Printer::default(); - printer.write_node(node); - printer.out -} diff --git a/kclvm/ast/src/printer/node.rs b/kclvm/ast/src/printer/node.rs deleted file mode 100644 index 80b4cb1d6..000000000 --- a/kclvm/ast/src/printer/node.rs +++ /dev/null @@ -1,881 +0,0 @@ -use std::collections::HashSet; - -<<<<<<<< HEAD:kclvm/ast_pretty/src/node.rs -use kclvm_ast::{ - ast::{self, CallExpr}, - token::{DelimToken, TokenKind}, - walker::MutSelfTypedResultWalker, -}; -use kclvm_error::bug; -======== -use kclvm_error::bug; - -<<<<<<< HEAD -use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; ->>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs -======= -use crate::{ - ast::{self, CallExpr}, - token::{DelimToken, TokenKind}, - walker::MutSelfTypedResultWalker, -}; ->>>>>>> 55680e6 (fmt) - -use super::{Indentation, Printer}; - -type ParameterType<'a> = ( - ( - &'a ast::NodeRef, - &'a Option>, - ), - &'a Option>, -); - -const COMMA_WHITESPACE: &str = ", "; -const IDENTIFIER_REGEX: &str = r#"^\$?[a-zA-Z_]\w*$"#; - -macro_rules! interleave { - ($inter: expr, $f: expr, $seq: expr) => { - if !$seq.is_empty() { - $f(&$seq[0]); - for s in &$seq[1..] { - $inter(); - $f(s); - } - } - }; -} - -impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> { - type Result = (); - - fn walk_module(&mut self, module: &'ctx ast::Module) -> Self::Result { - for comment in &module.comments { - self.comments.push_back(comment.clone()); - } - self.stmts(&module.body); - } - - fn walk_expr_stmt(&mut self, expr_stmt: &'ctx ast::ExprStmt) -> Self::Result { - interleave!( - || self.write(COMMA_WHITESPACE), - |expr| self.expr(expr), - expr_stmt.exprs - ); - self.write_newline_without_fill(); - } - - fn walk_unification_stmt( - &mut self, - unification_stmt: &'ctx ast::UnificationStmt, - ) -> Self::Result { - self.walk_identifier(&unification_stmt.target.node); - self.write(": "); - self.walk_schema_expr(&unification_stmt.value.node); - self.write_newline_without_fill(); - } - - fn walk_type_alias_stmt(&mut self, type_alias_stmt: &'ctx ast::TypeAliasStmt) -> Self::Result { - self.write("type"); - self.write_space(); - self.walk_identifier(&type_alias_stmt.type_name.node); - self.write(" = "); - self.write(&type_alias_stmt.type_value.node); - self.write_newline_without_fill(); - } - - fn walk_assign_stmt(&mut self, assign_stmt: &'ctx ast::AssignStmt) -> Self::Result { - for (i, target) in assign_stmt.targets.iter().enumerate() { - self.walk_identifier(&target.node); - if i == 0 { - if let Some(ty) = &assign_stmt.ty { - self.write(": "); - self.write(&ty.node.to_string()); - } - } - self.write(" = "); - } - self.expr(&assign_stmt.value); - self.write_newline_without_fill(); - if matches!(assign_stmt.value.node, ast::Expr::Schema(_)) { - self.write_newline_without_fill(); - } - } - - fn walk_aug_assign_stmt(&mut self, aug_assign_stmt: &'ctx ast::AugAssignStmt) -> Self::Result { - self.walk_identifier(&aug_assign_stmt.target.node); - self.write_space(); - self.write(aug_assign_stmt.op.symbol()); - self.write_space(); - self.expr(&aug_assign_stmt.value); - self.write_newline_without_fill(); - } - - fn walk_assert_stmt(&mut self, assert_stmt: &'ctx ast::AssertStmt) -> Self::Result { - self.write("assert "); - self.expr(&assert_stmt.test); - if let Some(if_cond) = &assert_stmt.if_cond { - self.write(" if "); - self.expr(if_cond); - } - if let Some(msg) = &assert_stmt.msg { - self.write(COMMA_WHITESPACE); - self.expr(msg); - } - self.write_newline_without_fill(); - } - - fn walk_if_stmt(&mut self, if_stmt: &'ctx ast::IfStmt) -> Self::Result { - self.write("if "); - self.expr(&if_stmt.cond); - self.write_token(TokenKind::Colon); - self.write_newline_without_fill(); - self.write_indentation(Indentation::Indent); - self.stmts(&if_stmt.body); - self.write_indentation(Indentation::Dedent); - if !if_stmt.orelse.is_empty() { - if let ast::Stmt::If(elif_stmt) = &if_stmt.orelse[0].node { - // Nested if statements need to be considered, - // so `el` needs to be preceded by the current indentation. - self.fill("el"); - self.walk_if_stmt(elif_stmt); - } else { - // Nested if statements need to be considered, - // so `el` needs to be preceded by the current indentation. - self.fill("else:"); - self.write_newline_without_fill(); - self.write_indentation(Indentation::Indent); - self.stmts(&if_stmt.orelse); - self.write_indentation(Indentation::Dedent); - } - } else { - self.write_newline_without_fill(); - } - } - - fn walk_import_stmt(&mut self, import_stmt: &'ctx ast::ImportStmt) -> Self::Result { - self.write("import "); - self.write(&import_stmt.path); - if let Some(as_name) = &import_stmt.asname { - self.write(" as "); - self.write(as_name); - } - self.write_newline_without_fill(); - } - - fn walk_schema_stmt(&mut self, schema_stmt: &'ctx ast::SchemaStmt) -> Self::Result { - interleave!( - || self.write_newline(), - |expr: &ast::NodeRef| { - self.write("@"); - self.walk_call_expr(&expr.node); - }, - schema_stmt.decorators - ); - if !schema_stmt.decorators.is_empty() { - self.write_newline(); - } - if schema_stmt.is_mixin { - self.write("mixin "); - } else if schema_stmt.is_protocol { - self.write("protocol "); - } else { - self.write("schema "); - } - self.write(&schema_stmt.name.node); - if let Some(args) = &schema_stmt.args { - self.write("["); - self.walk_arguments(&args.node); - self.write("]"); - } - if let Some(parent_name) = &schema_stmt.parent_name { - self.write("("); - self.walk_identifier(&parent_name.node); - self.write(")"); - } - if let Some(host_name) = &schema_stmt.for_host_name { - self.write(" for "); - self.walk_identifier(&host_name.node); - } - self.write_token(TokenKind::Colon); - self.write_newline_without_fill(); - self.write_indentation(Indentation::Indent); - if !schema_stmt.doc.is_empty() { - self.fill(""); - self.write(&schema_stmt.doc); - self.write_newline_without_fill(); - } - if !schema_stmt.mixins.is_empty() { - self.fill(""); - self.write("mixin ["); - self.write_indentation(Indentation::IndentWithNewline); - interleave!( - || { - self.write(","); - self.write_newline(); - }, - |mixin_name: &ast::NodeRef| self.walk_identifier(&mixin_name.node), - schema_stmt.mixins - ); - self.write_indentation(Indentation::Dedent); - self.write_newline(); - self.write("]"); - self.write_newline_without_fill(); - } - if let Some(index_signature) = &schema_stmt.index_signature { - self.fill(""); - self.write_token(TokenKind::OpenDelim(DelimToken::Bracket)); - if index_signature.node.any_other { - self.write_token(TokenKind::DotDotDot); - } - if let Some(key_name) = &index_signature.node.key_name { - self.write(&format!("{}: ", key_name)); - } - self.write(&index_signature.node.key_type.node); - self.write_token(TokenKind::CloseDelim(DelimToken::Bracket)); - self.write_token(TokenKind::Colon); - self.write_space(); - self.write(&index_signature.node.value_type.node); - if let Some(value) = &index_signature.node.value { - self.write(" = "); - self.expr(value); - } - self.write_newline_without_fill(); - } - self.stmts(&schema_stmt.body); - self.write_newline_without_fill(); - if !schema_stmt.checks.is_empty() { - self.fill("check:"); - // Schema check indent - self.write_indentation(Indentation::IndentWithNewline); - interleave!( - || self.write_newline(), - |check_expr: &ast::NodeRef| self.walk_check_expr(&check_expr.node), - schema_stmt.checks - ); - self.write_newline_without_fill(); - // Schema check dedent - self.write_indentation(Indentation::Dedent); - self.write_newline_without_fill(); - } - // Schema Stmt dedent - self.write_indentation(Indentation::Dedent); - } - - fn walk_rule_stmt(&mut self, rule_stmt: &'ctx ast::RuleStmt) -> Self::Result { - interleave!( - || self.write_newline(), - |expr: &ast::NodeRef| { - self.write("@"); - self.walk_call_expr(&expr.node); - }, - rule_stmt.decorators - ); - if !rule_stmt.decorators.is_empty() { - self.write_newline(); - } - self.write("rule "); - self.write(&rule_stmt.name.node); - if let Some(args) = &rule_stmt.args { - self.write("["); - self.walk_arguments(&args.node); - self.write("]"); - } - if !rule_stmt.parent_rules.is_empty() { - self.write("("); - interleave!( - || self.write(COMMA_WHITESPACE), - |identifier: &ast::NodeRef| self.walk_identifier(&identifier.node), - rule_stmt.parent_rules - ); - self.write(")"); - } - if let Some(host_name) = &rule_stmt.for_host_name { - self.write(" for "); - self.walk_identifier(&host_name.node); - } - self.write_token(TokenKind::Colon); - // Rule Stmt indent - self.write_indentation(Indentation::IndentWithNewline); - if !rule_stmt.doc.is_empty() { - self.write(&rule_stmt.doc); - self.write_newline(); - } - if !rule_stmt.checks.is_empty() { - interleave!( - || self.write_newline(), - |check_expr: &ast::NodeRef| self.walk_check_expr(&check_expr.node), - rule_stmt.checks - ); - self.write_newline_without_fill(); - } - // Rule Stmt dedent - self.write_indentation(Indentation::Dedent); - } - - fn walk_quant_expr(&mut self, quant_expr: &'ctx ast::QuantExpr) -> Self::Result { - let in_one_line = false; - let quant_op_string: String = quant_expr.op.clone().into(); - self.write(&quant_op_string); - self.write_space(); - interleave!( - || self.write(COMMA_WHITESPACE), - |identifier: &ast::NodeRef| self.walk_identifier(&identifier.node), - quant_expr.variables - ); - self.write(" in "); - self.expr(&quant_expr.target); - self.write(" {"); - if !in_one_line { - self.write_indentation(Indentation::IndentWithNewline); - } - self.expr(&quant_expr.test); - if let Some(if_cond) = &quant_expr.if_cond { - self.write(" if "); - self.expr(if_cond); - } - if !in_one_line { - self.write_indentation(Indentation::DedentWithNewline) - } - self.write("}") - } - - fn walk_schema_attr(&mut self, schema_attr: &'ctx ast::SchemaAttr) -> Self::Result { - interleave!( - || self.write_newline(), - |expr: &ast::NodeRef| { - self.write("@"); - self.walk_call_expr(&expr.node) - }, - schema_attr.decorators - ); - if !schema_attr.decorators.is_empty() { - self.write_newline(); - } - self.write(&schema_attr.name.node); - if schema_attr.is_optional { - self.write("?"); - } - self.write(": "); - self.write(&schema_attr.type_str.node); - if let Some(op) = &schema_attr.op { - let symbol = match op { - ast::BinOrAugOp::Bin(bin_op) => bin_op.symbol(), - ast::BinOrAugOp::Aug(aug_op) => aug_op.symbol(), - }; - self.write_space(); - self.write(symbol); - self.write_space(); - } - if let Some(value) = &schema_attr.value { - self.expr(value); - } - self.write_newline_without_fill(); - } - - fn walk_if_expr(&mut self, if_expr: &'ctx ast::IfExpr) -> Self::Result { - self.expr(&if_expr.body); - self.write(" if "); - self.expr(&if_expr.cond); - self.write(" else "); - self.expr(&if_expr.orelse); - } - - fn walk_unary_expr(&mut self, unary_expr: &'ctx ast::UnaryExpr) -> Self::Result { - self.write(unary_expr.op.symbol()); - // Four forms: `+expr`, `-expr`, `~expr`, `not expr` - // `not expr` needs a space between `not` and `expr` - if matches!(unary_expr.op, ast::UnaryOp::Not) { - self.write_space(); - } - self.expr(&unary_expr.operand); - } - - fn walk_binary_expr(&mut self, binary_expr: &'ctx ast::BinaryExpr) -> Self::Result { - let symbol = match &binary_expr.op { - ast::BinOrCmpOp::Bin(bin_op) => bin_op.symbol(), - ast::BinOrCmpOp::Cmp(cmp_op) => cmp_op.symbol(), - }; - self.expr(&binary_expr.left); - self.write_space(); - self.write(symbol); - self.write_space(); - self.expr(&binary_expr.right); - } - - fn walk_selector_expr(&mut self, selector_expr: &'ctx ast::SelectorExpr) -> Self::Result { - self.expr(&selector_expr.value); - self.write(if selector_expr.has_question { - "?." - } else { - "." - }); - self.walk_identifier(&selector_expr.attr.node); - } - - fn walk_call_expr(&mut self, call_expr: &'ctx ast::CallExpr) -> Self::Result { - self.expr(&call_expr.func); - self.write("("); - self.write_args_and_kwargs(&call_expr.args, &call_expr.keywords); - self.write(")"); - } - - fn walk_subscript(&mut self, subscript: &'ctx ast::Subscript) -> Self::Result { - self.expr(&subscript.value); - if subscript.has_question { - self.write("?"); - } - self.write("["); - if let Some(index) = &subscript.index { - self.expr(index); - } else { - if let Some(lower) = &subscript.lower { - self.expr(lower); - } - self.write_token(TokenKind::Colon); - if let Some(upper) = &subscript.upper { - self.expr(upper); - } - self.write_token(TokenKind::Colon); - if let Some(step) = &subscript.step { - self.expr(step); - } - } - self.write("]"); - } - - fn walk_paren_expr(&mut self, paren_expr: &'ctx ast::ParenExpr) -> Self::Result { - self.write_token(TokenKind::OpenDelim(DelimToken::Paren)); - self.expr(&paren_expr.expr); - self.write_token(TokenKind::CloseDelim(DelimToken::Paren)); - } - - fn walk_list_expr(&mut self, list_expr: &'ctx ast::ListExpr) -> Self::Result { - let line_set = list_expr - .elts - .iter() - .map(|e| e.line) - .collect::>(); - let mut in_one_line = line_set.len() <= 1; - if let Some(elt) = list_expr.elts.first() { - if let ast::Expr::ListIfItem(_) = &elt.node { - in_one_line = false; - } - } - self.write_token(TokenKind::OpenDelim(DelimToken::Bracket)); - if !in_one_line { - self.write_indentation(Indentation::IndentWithNewline); - } - interleave!( - || if in_one_line { - self.write(COMMA_WHITESPACE); - } else { - self.write_newline(); - }, - |elt| self.expr(elt), - list_expr.elts - ); - if !in_one_line { - self.write_indentation(Indentation::DedentWithNewline); - } - self.write_token(TokenKind::CloseDelim(DelimToken::Bracket)); - } - - fn walk_list_comp(&mut self, list_comp: &'ctx ast::ListComp) -> Self::Result { - self.write_token(TokenKind::OpenDelim(DelimToken::Bracket)); - self.expr(&list_comp.elt); - for gen in &list_comp.generators { - self.walk_comp_clause(&gen.node); - } - self.write_token(TokenKind::CloseDelim(DelimToken::Bracket)); - } - - fn walk_list_if_item_expr( - &mut self, - list_if_item_expr: &'ctx ast::ListIfItemExpr, - ) -> Self::Result { - self.write("if "); - self.expr(&list_if_item_expr.if_cond); - self.write(":"); - self.write_indentation(Indentation::IndentWithNewline); - interleave!( - || self.write_newline(), - |expr| self.expr(expr), - list_if_item_expr.exprs - ); - self.write_indentation(Indentation::DedentWithNewline); - if let Some(orelse) = &list_if_item_expr.orelse { - match &orelse.node { - ast::Expr::List(list_expr) => { - self.write("else:"); - self.write_indentation(Indentation::IndentWithNewline); - interleave!( - || self.write_newline(), - |expr| self.expr(expr), - list_expr.elts - ); - self.write_indentation(Indentation::Dedent); - } - ast::Expr::ListIfItem(_) => { - self.write("el"); - self.expr(orelse); - } - _ => bug!("Invalid list if expr orelse node {:?}", orelse.node), - } - } - } - - fn walk_starred_expr(&mut self, starred_expr: &'ctx ast::StarredExpr) -> Self::Result { - self.write("*"); - self.expr(&starred_expr.value) - } - - fn walk_dict_comp(&mut self, dict_comp: &'ctx ast::DictComp) -> Self::Result { - self.write_token(TokenKind::OpenDelim(DelimToken::Brace)); - self.expr(match &dict_comp.entry.key { - Some(key) => key, - None => bug!("Invalid dict comp key"), - }); - if !matches!(dict_comp.entry.operation, ast::ConfigEntryOperation::Union) { - self.write_space(); - } - self.write(dict_comp.entry.operation.symbol()); - self.write_space(); - for gen in &dict_comp.generators { - self.walk_comp_clause(&gen.node); - } - self.write_token(TokenKind::CloseDelim(DelimToken::Brace)); - } - - fn walk_config_if_entry_expr( - &mut self, - config_if_entry_expr: &'ctx ast::ConfigIfEntryExpr, - ) -> Self::Result { - self.write("if "); - self.expr(&config_if_entry_expr.if_cond); - self.write_token(TokenKind::Colon); - self.write_indentation(Indentation::IndentWithNewline); - interleave!( - || self.write_newline(), - |entry: &ast::NodeRef| self.write_entry(entry), - config_if_entry_expr.items - ); - self.write_indentation(Indentation::DedentWithNewline); - if let Some(orelse) = &config_if_entry_expr.orelse { - match &orelse.node { - ast::Expr::Config(config_expr) => { - self.write("else:"); - self.write_indentation(Indentation::IndentWithNewline); - interleave!( - || self.write_newline(), - |entry: &ast::NodeRef| self.write_entry(entry), - config_expr.items - ); - self.write_indentation(Indentation::Dedent); - } - ast::Expr::ConfigIfEntry(_) => { - self.write("el"); - self.expr(orelse); - } - _ => bug!("Invalid config if expr orelse node {:?}", orelse.node), - } - } - } - - fn walk_comp_clause(&mut self, comp_clause: &'ctx ast::CompClause) -> Self::Result { - self.write(" for "); - interleave!( - || self.write(COMMA_WHITESPACE), - |target: &ast::NodeRef| self.walk_identifier(&target.node), - comp_clause.targets - ); - self.write(" in "); - self.expr(&comp_clause.iter); - for if_clause in &comp_clause.ifs { - self.write(" if "); - self.expr(if_clause); - } - } - - fn walk_schema_expr(&mut self, schema_expr: &'ctx ast::SchemaExpr) -> Self::Result { - self.walk_identifier(&schema_expr.name.node); - if !schema_expr.args.is_empty() || !schema_expr.kwargs.is_empty() { - self.write_token(TokenKind::OpenDelim(DelimToken::Paren)); - self.write_args_and_kwargs(&schema_expr.args, &schema_expr.kwargs); - self.write_token(TokenKind::CloseDelim(DelimToken::Paren)); - } - self.write_space(); - self.expr(&schema_expr.config) - } - - fn walk_config_expr(&mut self, config_expr: &'ctx ast::ConfigExpr) -> Self::Result { - let line_set: HashSet = config_expr.items.iter().map(|item| item.line).collect(); - let mut in_one_line = line_set.len() <= 1; - if let Some(item) = config_expr.items.first() { - if let ast::Expr::ConfigIfEntry(_) = &item.node.value.node { - in_one_line = false; - } - } - self.write_token(TokenKind::OpenDelim(DelimToken::Brace)); - if !config_expr.items.is_empty() { - if !in_one_line { - self.write_indentation(Indentation::IndentWithNewline); - } - interleave!( - || if in_one_line { - self.write(COMMA_WHITESPACE); - } else { - self.write_newline(); - }, - |entry: &ast::NodeRef| self.write_entry(entry), - config_expr.items - ); - if !in_one_line { - self.write_indentation(Indentation::DedentWithNewline); - } - } - self.write_token(TokenKind::CloseDelim(DelimToken::Brace)); - } - - fn walk_check_expr(&mut self, check_expr: &'ctx ast::CheckExpr) -> Self::Result { - self.expr(&check_expr.test); - if let Some(if_cond) = &check_expr.if_cond { - self.write(" if "); - self.expr(if_cond); - } - if let Some(msg) = &check_expr.msg { - self.write(COMMA_WHITESPACE); - self.expr(msg); - } - } - - fn walk_lambda_expr(&mut self, lambda_expr: &'ctx ast::LambdaExpr) -> Self::Result { - self.write("lambda"); - if let Some(args) = &lambda_expr.args { - self.write_space(); - self.walk_arguments(&args.node); - } - if let Some(ty_str) = &lambda_expr.return_type_str { - self.write_space(); - self.write_token(TokenKind::RArrow); - self.write_space(); - self.write(ty_str); - } - self.write_space(); - self.write_token(TokenKind::OpenDelim(DelimToken::Brace)); - self.write_newline(); - self.write_indentation(Indentation::Indent); - - // lambda body - self.stmts(&lambda_expr.body); - - self.write_indentation(Indentation::Dedent); - self.write_newline(); - self.write_token(TokenKind::CloseDelim(DelimToken::Brace)); - } - - fn walk_keyword(&mut self, keyword: &'ctx ast::Keyword) -> Self::Result { - self.walk_identifier(&keyword.arg.node); - if let Some(value) = &keyword.value { - self.write("="); - self.expr(value); - } - } - - fn walk_arguments(&mut self, arguments: &'ctx ast::Arguments) -> Self::Result { - let parameter_zip_list: Vec> = arguments - .args - .iter() - .zip(arguments.type_annotation_list.iter()) - .zip(arguments.defaults.iter()) - .collect(); - interleave!( - || self.write(COMMA_WHITESPACE), - |para: &ParameterType<'_>| { - let ((arg, ty_str), default) = para; - self.walk_identifier(&arg.node); - if let Some(ty_str) = ty_str { - self.write(&format!(": {}", ty_str.node)); - } - if let Some(default) = default { - self.write(" = "); - self.expr(default); - } - }, - parameter_zip_list - ); - } - - fn walk_compare(&mut self, compare: &'ctx ast::Compare) -> Self::Result { - self.expr(&compare.left); - for (op, expr) in compare.ops.iter().zip(compare.comparators.iter()) { - self.write_space(); - self.write(op.symbol()); - self.write_space(); - self.expr(expr); - } - } - - #[inline] - fn walk_identifier(&mut self, identifier: &'ctx ast::Identifier) -> Self::Result { - self.write(&identifier.get_name()); - } - - fn walk_number_lit(&mut self, number_lit: &'ctx ast::NumberLit) -> Self::Result { - match number_lit.value { - ast::NumberLitValue::Int(int_val) => self.write(&int_val.to_string()), - ast::NumberLitValue::Float(float_val) => self.write(&float_val.to_string()), - } - } - - fn walk_string_lit(&mut self, string_lit: &'ctx ast::StringLit) -> Self::Result { - if !string_lit.raw_value.is_empty() { - self.write(&string_lit.raw_value) - } else { - self.write(&format!("\"{}\"", string_lit.value.replace('\"', "\\\""))); - } - } - - #[inline] - fn walk_name_constant_lit( - &mut self, - name_constant_lit: &'ctx ast::NameConstantLit, - ) -> Self::Result { - self.write(name_constant_lit.value.symbol()); - } - - fn walk_joined_string(&mut self, joined_string: &'ctx ast::JoinedString) -> Self::Result { - self.write("\""); - for value in &joined_string.values { - match &value.node { - ast::Expr::StringLit(string_lit) => { - self.write(&string_lit.value.replace('\"', "\\\"")); - } - _ => self.expr(value), - } - } - self.write("\""); - } - - fn walk_formatted_value(&mut self, formatted_value: &'ctx ast::FormattedValue) -> Self::Result { - self.write("${"); - self.expr(&formatted_value.value); - if let Some(spec) = &formatted_value.format_spec { - self.write(&format!(": {}", spec)); - } - self.write("}"); - } - - fn walk_comment(&mut self, comment: &'ctx ast::Comment) -> Self::Result { - self.writeln(&comment.text); - self.fill(""); - } -} - -impl<'p> Printer<'p> { - pub fn write_args_and_kwargs( - &mut self, - args: &[ast::NodeRef], - kwargs: &[ast::NodeRef], - ) { - interleave!(|| self.write(COMMA_WHITESPACE), |arg| self.expr(arg), args); - if !args.is_empty() && !kwargs.is_empty() { - self.write(COMMA_WHITESPACE); - } - interleave!( - || self.write(COMMA_WHITESPACE), - |kwarg: &ast::NodeRef| self.walk_keyword(&kwarg.node), - kwargs - ); - } - - pub fn write_entry(&mut self, item: &ast::NodeRef) { - match &item.node.key { - Some(key) => { - let print_right_brace_count = self.write_config_key(key); - if item.node.insert_index >= 0 { - self.write(&format!("[{}]", item.node.insert_index)); - } - if !matches!(item.node.operation, ast::ConfigEntryOperation::Union) { - self.write_space(); - } - self.write(item.node.operation.symbol()); - self.write_space(); - self.expr(&item.node.value); - self.write(&"}".repeat(print_right_brace_count)); - } - None => { - if !matches!(&item.node.value.node, ast::Expr::ConfigIfEntry(_)) { - self.write("**"); - } - self.expr(&item.node.value) - } - }; - } - - fn write_config_key(&mut self, key: &ast::NodeRef) -> usize { - match &key.node { - ast::Expr::Identifier(identifier) => { - self.hook.pre(self, super::ASTNode::Expr(key)); - self.write_ast_comments(key); - // Judge contains string identifier, e.g., "x-y-z" - let names = &identifier.names; - - let re = fancy_regex::Regex::new(IDENTIFIER_REGEX).unwrap(); - let need_right_brace = !names.iter().all(|n| re.is_match(n).unwrap_or(false)); - let count = if need_right_brace { - self.write( - &names - .iter() - .map(|n| n.replace('\"', "\\\"")) - .collect::>() - .join(": {"), - ); - names.len() - 1 - } else { - self.expr(key); - 0 - }; - self.hook.post(self, super::ASTNode::Expr(key)); - count - } - _ => { - self.expr(key); - 0 - } - } - } -} - -impl<'p> Printer<'p> { - // ------------------------------ - // Expr and Stmt walker functions - // ------------------------------ - - pub fn expr(&mut self, expr: &ast::NodeRef) { - self.hook.pre(self, super::ASTNode::Expr(expr)); - self.write_ast_comments(expr); - self.walk_expr(&expr.node); - self.hook.post(self, super::ASTNode::Expr(expr)); - } - - pub fn stmt(&mut self, stmt: &ast::NodeRef) { - self.hook.pre(self, super::ASTNode::Stmt(stmt)); - self.fill(""); - self.write_ast_comments(stmt); - self.walk_stmt(&stmt.node); - self.hook.post(self, super::ASTNode::Stmt(stmt)); - } - - pub fn exprs(&mut self, exprs: &[ast::NodeRef]) { - for expr in exprs { - self.expr(expr); - } - } - - pub fn stmts(&mut self, stmts: &[ast::NodeRef]) { - for stmt in stmts { - self.stmt(stmt); - } - } -} diff --git a/kclvm/ast/src/printer/test_data/arguments.input b/kclvm/ast/src/printer/test_data/arguments.input deleted file mode 100644 index d356f83fb..000000000 --- a/kclvm/ast/src/printer/test_data/arguments.input +++ /dev/null @@ -1,6 +0,0 @@ -schema Config[nameVar, textVar: str, idVar: int = 1]: - name: str = nameVar - text: str = textVar - id?: int = idVar - -config = Config("test", "text") diff --git a/kclvm/ast/src/printer/test_data/arguments.output b/kclvm/ast/src/printer/test_data/arguments.output deleted file mode 100644 index d356f83fb..000000000 --- a/kclvm/ast/src/printer/test_data/arguments.output +++ /dev/null @@ -1,6 +0,0 @@ -schema Config[nameVar, textVar: str, idVar: int = 1]: - name: str = nameVar - text: str = textVar - id?: int = idVar - -config = Config("test", "text") diff --git a/kclvm/ast/src/printer/test_data/codelayout.input b/kclvm/ast/src/printer/test_data/codelayout.input deleted file mode 100644 index b8eeb768d..000000000 --- a/kclvm/ast/src/printer/test_data/codelayout.input +++ /dev/null @@ -1,76 +0,0 @@ - - - -import math as alias_math -schema Person ( Base): - name:str - age:int - check : - age>0 if age , "age must > 0" -person = Person{ - name:"Alice" - age:18 -} -if True: - a = 1 -elif True: - b = 2 -else: - c = 3 -d = 1 + 2 -e = ( 1 + 2 ) -f=[ 1, 2, 3 ] -g = { "key" : "value" } -print (1) -dct={"key": "value"} -lst=[1,2,3] -h = dct [ 'key' ] -i = lst [ 1 ] -x = 1 -y = 2 -long_variable = 3 -i = i+1 -submitted+=1 -x = x*2 - 1 -hypot2 = x*x + y*y -_c = (a+b) * (a-b) -_b=2 -_c= 3 -_d =4 - -_value = (1 + 2 * 3) -_value = (1+2*3) -_value =1+ - 2 * ~ 3 -_list = [1, 2, 3] -_list = [*_list, [4, 5 ,6]] -_list = [* _list, [4, 5 ,6]] - -_dict = {** {"k": "v"}, ** {"k": "v"}} -a = [1,2,3] -b = [ - 1,2,3, - 4,5,6, -] -_dict={ - "k1":"v1" - "k2" :"v2" - "k3": "v3" - "k4" : "v4" - "k5" : "v5" -} -foo=1 -if foo is not None: - _a = 1 - _dict|={} - hello = "world{}" . format( 1 )[2 : 4] . lower( ) - range_int = [ i for i in range( 10 ) ] -op = 1+2 - - 3 + (3 - 1) // 3 -op += 1 -op -= 12 + 23 -print( " " , end= '') -log = math. log(12) -aa = 1 -assert aa == 1,"message" -assert aa == 1 if aa,"message" -aaaa = (1 + 2 / 2) if _a == 2 + + 134.3 else ("a"*3) -bbbb = "{}". format(a) \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/codelayout.output b/kclvm/ast/src/printer/test_data/codelayout.output deleted file mode 100644 index 28fa41ccc..000000000 --- a/kclvm/ast/src/printer/test_data/codelayout.output +++ /dev/null @@ -1,79 +0,0 @@ -import math as alias_math -schema Person(Base): - name: str - age: int - - check: - age > 0 if age, "age must > 0" - -person = Person { - name: "Alice" - age: 18 -} - -if True: - a = 1 -elif True: - b = 2 -else: - c = 3 -d = 1 + 2 -e = (1 + 2) -f = [1, 2, 3] -g = {"key": "value"} -print(1) -dct = {"key": "value"} -lst = [1, 2, 3] -h = dct['key'] -i = lst[1] -x = 1 -y = 2 -long_variable = 3 -i = i + 1 -submitted += 1 -x = x * 2 - 1 -hypot2 = x * x + y * y -_c = (a + b) * (a - b) -_b = 2 -_c = 3 -_d = 4 -_value = (1 + 2 * 3) -_value = (1 + 2 * 3) -_value = 1 + -2 * ~3 -_list = [1, 2, 3] -_list = [*_list, [4, 5, 6]] -_list = [*_list, [4, 5, 6]] -_dict = {**{"k": "v"}, **{"k": "v"}} -a = [1, 2, 3] -b = [ - 1 - 2 - 3 - 4 - 5 - 6 -] -_dict = { - "k1": "v1" - "k2": "v2" - "k3": "v3" - "k4": "v4" - "k5": "v5" -} -foo = 1 -if foo is not None: - _a = 1 - _dict |= {} - hello = "world{}".format(1)[2:4:].lower() - range_int = [i for i in range(10)] - -op = 1 + 2 - -3 + (3 - 1) // 3 -op += 1 -op -= 12 + 23 -print(" ", end='') -log = math.log(12) -aa = 1 -assert aa == 1, "message" -assert aa == 1 if aa, "message" -aaaa = (1 + 2 / 2) if _a == 2 + +134.3 else ("a" * 3) -bbbb = "{}".format(a) diff --git a/kclvm/ast/src/printer/test_data/collection_if.input b/kclvm/ast/src/printer/test_data/collection_if.input deleted file mode 100644 index 080538c1c..000000000 --- a/kclvm/ast/src/printer/test_data/collection_if.input +++ /dev/null @@ -1,51 +0,0 @@ -schema Config: - name: str - env: str - data: [int] -env = "env" -data1 = Config { - if env == "env": - name: env - env: env - data += [0] - else: - name = "name" - env = "name" - data += [1] -} -data1 = Config { - if env == "env": - name: env - env: env - else: - name: "name" - env: "name" -} -data2 = Config { - if env != "env": - name: env - env: env - else: - name: "name" - env: "name" -} -data3 = { - if True: - key1: "value1" - elif True: - key2: "value2" - elif True: - key3: "value3" - else: - key4: "value4" -} -data4 = [ - if True: - "value1" - elif True: - "value2" - elif True: - "value3" - else: - "value4" -] diff --git a/kclvm/ast/src/printer/test_data/collection_if.output b/kclvm/ast/src/printer/test_data/collection_if.output deleted file mode 100644 index 009f8947a..000000000 --- a/kclvm/ast/src/printer/test_data/collection_if.output +++ /dev/null @@ -1,55 +0,0 @@ -schema Config: - name: str - env: str - data: [int] - -env = "env" -data1 = Config { - if env == "env": - name: env - env: env - data += [0] - else: - name = "name" - env = "name" - data += [1] -} - -data1 = Config { - if env == "env": - name: env - env: env - else: - name: "name" - env: "name" -} - -data2 = Config { - if env != "env": - name: env - env: env - else: - name: "name" - env: "name" -} - -data3 = { - if True: - key1: "value1" - elif True: - key2: "value2" - elif True: - key3: "value3" - else: - key4: "value4" -} -data4 = [ - if True: - "value1" - elif True: - "value2" - elif True: - "value3" - else: - "value4" -] diff --git a/kclvm/ast/src/printer/test_data/comment.input b/kclvm/ast/src/printer/test_data/comment.input deleted file mode 100644 index 681a69c31..000000000 --- a/kclvm/ast/src/printer/test_data/comment.input +++ /dev/null @@ -1,38 +0,0 @@ -# Comment One -schema Main: - name?: str - env?: [{str:}] - -# Comment Two -schema AppConfiguration: - appName: str - image: str - overQuota: bool = False - resource: {str:} - mainContainer?: Main - labels: {str:} - -# Comment Three -appConfiguration = AppConfiguration { - # Comment Four - appName: "kusion" - image: "test-image:v1" # Comment Five - resource: { - cpu: "4" - disk: "50Gi" - memory: "12Gi" - } - labels: { - key: { - key: 12 - } - } - # Comment Six - mainContainer: Main { - name: "kusion_override" - }# Comment Seven - - # Comment Eight - overQuota: True -} -# Comment Nine diff --git a/kclvm/ast/src/printer/test_data/comment.output b/kclvm/ast/src/printer/test_data/comment.output deleted file mode 100644 index bae5a376c..000000000 --- a/kclvm/ast/src/printer/test_data/comment.output +++ /dev/null @@ -1,34 +0,0 @@ -# Comment One -schema Main: - name?: str - env?: [{str:}] - -# Comment Two -schema AppConfiguration: - appName: str - image: str - overQuota: bool = False - resource: {str:} - mainContainer?: Main - labels: {str:} - -# Comment Three -appConfiguration = AppConfiguration { - # Comment Four - appName: "kusion" - # Comment Five - image: "test-image:v1" - resource: { - cpu: "4" - disk: "50Gi" - memory: "12Gi" - } - labels: {key: {key: 12}} - # Comment Six - mainContainer: Main {name: "kusion_override"} - # Comment Seven - # Comment Eight - overQuota: True -} - -# Comment Nine diff --git a/kclvm/ast/src/printer/test_data/empty.input b/kclvm/ast/src/printer/test_data/empty.input deleted file mode 100644 index fd40910d9..000000000 --- a/kclvm/ast/src/printer/test_data/empty.input +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/kclvm/ast/src/printer/test_data/empty.output b/kclvm/ast/src/printer/test_data/empty.output deleted file mode 100644 index e69de29bb..000000000 diff --git a/kclvm/ast/src/printer/test_data/if_stmt.input b/kclvm/ast/src/printer/test_data/if_stmt.input deleted file mode 100644 index 40aeb4d0a..000000000 --- a/kclvm/ast/src/printer/test_data/if_stmt.input +++ /dev/null @@ -1,16 +0,0 @@ -if True: - a = 1 -elif True: - b = 2 -else: - c = 3 - -if True: - if False: - d = 4 - elif True: - e = 5 - else: - f = 6 -else: - g = 7 diff --git a/kclvm/ast/src/printer/test_data/if_stmt.output b/kclvm/ast/src/printer/test_data/if_stmt.output deleted file mode 100644 index 8a20e1acd..000000000 --- a/kclvm/ast/src/printer/test_data/if_stmt.output +++ /dev/null @@ -1,15 +0,0 @@ -if True: - a = 1 -elif True: - b = 2 -else: - c = 3 -if True: - if False: - d = 4 - elif True: - e = 5 - else: - f = 6 -else: - g = 7 diff --git a/kclvm/ast/src/printer/test_data/import.input b/kclvm/ast/src/printer/test_data/import.input deleted file mode 100644 index c25142c17..000000000 --- a/kclvm/ast/src/printer/test_data/import.input +++ /dev/null @@ -1,4 +0,0 @@ -import path.to.pkg -import path.to.pkg as abs_pkg_alias -import .relative.path -import .relative.path as re_pkg_alias diff --git a/kclvm/ast/src/printer/test_data/import.output b/kclvm/ast/src/printer/test_data/import.output deleted file mode 100644 index c25142c17..000000000 --- a/kclvm/ast/src/printer/test_data/import.output +++ /dev/null @@ -1,4 +0,0 @@ -import path.to.pkg -import path.to.pkg as abs_pkg_alias -import .relative.path -import .relative.path as re_pkg_alias diff --git a/kclvm/ast/src/printer/test_data/index_sign.input b/kclvm/ast/src/printer/test_data/index_sign.input deleted file mode 100644 index 54d611873..000000000 --- a/kclvm/ast/src/printer/test_data/index_sign.input +++ /dev/null @@ -1,12 +0,0 @@ -schema Data: - [str]: any - -schema DataOther: - [...str]: str - id?: int - -schema DataMap: - [name: str]: str - check: - name in ["A", "B", "C"] - \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/index_sign.output b/kclvm/ast/src/printer/test_data/index_sign.output deleted file mode 100644 index 7da6687ac..000000000 --- a/kclvm/ast/src/printer/test_data/index_sign.output +++ /dev/null @@ -1,13 +0,0 @@ -schema Data: - [str]: any - -schema DataOther: - [...str]: str - id?: int - -schema DataMap: - [name: str]: str - - check: - name in ["A", "B", "C"] - diff --git a/kclvm/ast/src/printer/test_data/joined_str.input b/kclvm/ast/src/printer/test_data/joined_str.input deleted file mode 100644 index 8af336d4a..000000000 --- a/kclvm/ast/src/printer/test_data/joined_str.input +++ /dev/null @@ -1,3 +0,0 @@ -a = 1 -b = "${a}" -c = "a.${1}" diff --git a/kclvm/ast/src/printer/test_data/joined_str.output b/kclvm/ast/src/printer/test_data/joined_str.output deleted file mode 100644 index 8af336d4a..000000000 --- a/kclvm/ast/src/printer/test_data/joined_str.output +++ /dev/null @@ -1,3 +0,0 @@ -a = 1 -b = "${a}" -c = "a.${1}" diff --git a/kclvm/ast/src/printer/test_data/lambda.input b/kclvm/ast/src/printer/test_data/lambda.input deleted file mode 100644 index 5402976ca..000000000 --- a/kclvm/ast/src/printer/test_data/lambda.input +++ /dev/null @@ -1,20 +0,0 @@ -sumFunc1 = lambda x, y { - z = x + y - z + x -} -sumFunc2 = lambda x, y = 1 { - x + y - -} -sumFunc3 = lambda x = 1, y = 1 { - x + y - -} -sumFunc4 = lambda x: int = 1, y: int = 1 -> int { - x + y - -} -x0 = sumFunc1(1, 2) -x1 = sumFunc1(2, 3) -x2 = sumFunc1(3, 4) -x3 = sumFunc1(4, 5) diff --git a/kclvm/ast/src/printer/test_data/lambda.output b/kclvm/ast/src/printer/test_data/lambda.output deleted file mode 100644 index db23acee4..000000000 --- a/kclvm/ast/src/printer/test_data/lambda.output +++ /dev/null @@ -1,21 +0,0 @@ -sumFunc1 = lambda x, y { - z = x + y - z + x - -} -sumFunc2 = lambda x, y = 1 { - x + y - -} -sumFunc3 = lambda x = 1, y = 1 { - x + y - -} -sumFunc4 = lambda x: int = 1, y: int = 1 -> int { - x + y - -} -x0 = sumFunc1(1, 2) -x1 = sumFunc1(2, 3) -x2 = sumFunc1(3, 4) -x3 = sumFunc1(4, 5) diff --git a/kclvm/ast/src/printer/test_data/quant.input b/kclvm/ast/src/printer/test_data/quant.input deleted file mode 100644 index 23022c694..000000000 --- a/kclvm/ast/src/printer/test_data/quant.input +++ /dev/null @@ -1,8 +0,0 @@ -a = all x in [-1, 0, 1, 2, 3] { - x >= 1 if x > 0 -} -b = any x in {k1 = "v1", k2 = "v2"} {x in ["k1", "v2"]} -c = map x in {k1 = "v1", k2 = "v2"} {x} -d = filter x in [1, 2, 3] { - x > 1 -} \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/quant.output b/kclvm/ast/src/printer/test_data/quant.output deleted file mode 100644 index 4d35a3ba6..000000000 --- a/kclvm/ast/src/printer/test_data/quant.output +++ /dev/null @@ -1,12 +0,0 @@ -a = all x in [-1, 0, 1, 2, 3] { - x >= 1 if x > 0 -} -b = any x in {k1 = "v1", k2 = "v2"} { - x in ["k1", "v2"] -} -c = map x in {k1 = "v1", k2 = "v2"} { - x -} -d = filter x in [1, 2, 3] { - x > 1 -} diff --git a/kclvm/ast/src/printer/test_data/rule.input b/kclvm/ast/src/printer/test_data/rule.input deleted file mode 100644 index 662e8eec3..000000000 --- a/kclvm/ast/src/printer/test_data/rule.input +++ /dev/null @@ -1,19 +0,0 @@ -age = 1 - -schema MainProtocol: - """Protocol doc""" - var: int - -schema MainMixin for MainProtocol: - var: int - -@deprecated -rule Base: - """Rule doc""" - age > 0 - age < 10 - -rule Main[var](Base) for MainProtocol: - var - -Main(1) diff --git a/kclvm/ast/src/printer/test_data/rule.output b/kclvm/ast/src/printer/test_data/rule.output deleted file mode 100644 index 6d4543302..000000000 --- a/kclvm/ast/src/printer/test_data/rule.output +++ /dev/null @@ -1,16 +0,0 @@ -age = 1 -protocol MainProtocol: - """Protocol doc""" - var: int - -mixin MainMixin for MainProtocol: - var: int - -@deprecated() -rule Base: - """Rule doc""" - age > 0 - age < 10 -rule Main[var](Base) for MainProtocol: - var -Main(1) diff --git a/kclvm/ast/src/printer/test_data/type_alias.input b/kclvm/ast/src/printer/test_data/type_alias.input deleted file mode 100644 index 9924443d4..000000000 --- a/kclvm/ast/src/printer/test_data/type_alias.input +++ /dev/null @@ -1,18 +0,0 @@ -type Color = "Red" | "Yellow" | "Blue" - -colorRed: Color = "Red" -colorYellow: Color = "Yellow" -colorBlue: Color = "Blue" - -schema Data: - color: Color - -dataColorRed = Data { - color = "Red" -} -dataColorYellow = Data { - color = "Yellow" -} -dataColorBlue = Data { - color = "Blue" -} diff --git a/kclvm/ast/src/printer/test_data/type_alias.output b/kclvm/ast/src/printer/test_data/type_alias.output deleted file mode 100644 index d80ac1c1b..000000000 --- a/kclvm/ast/src/printer/test_data/type_alias.output +++ /dev/null @@ -1,13 +0,0 @@ -type Color = "Red"|"Yellow"|"Blue" -colorRed: Color = "Red" -colorYellow: Color = "Yellow" -colorBlue: Color = "Blue" -schema Data: - color: Color - -dataColorRed = Data {color = "Red"} - -dataColorYellow = Data {color = "Yellow"} - -dataColorBlue = Data {color = "Blue"} - diff --git a/kclvm/ast/src/printer/test_data/unary.input b/kclvm/ast/src/printer/test_data/unary.input deleted file mode 100644 index 613bcab7c..000000000 --- a/kclvm/ast/src/printer/test_data/unary.input +++ /dev/null @@ -1,6 +0,0 @@ -a = + 1 -b = - 1 -c = ~ 1 -d = not True -e = + 1 + + 1 -f = + 1 - - 1 diff --git a/kclvm/ast/src/printer/test_data/unary.output b/kclvm/ast/src/printer/test_data/unary.output deleted file mode 100644 index 552bdc5d0..000000000 --- a/kclvm/ast/src/printer/test_data/unary.output +++ /dev/null @@ -1,6 +0,0 @@ -a = +1 -b = -1 -c = ~1 -d = not True -e = +1 + +1 -f = +1 - -1 diff --git a/kclvm/ast/src/printer/test_data/unification.input b/kclvm/ast/src/printer/test_data/unification.input deleted file mode 100644 index 22d05d0bb..000000000 --- a/kclvm/ast/src/printer/test_data/unification.input +++ /dev/null @@ -1,5 +0,0 @@ -schema Config: - name: str -config: Config { - name = "name" -} \ No newline at end of file diff --git a/kclvm/ast/src/printer/test_data/unification.output b/kclvm/ast/src/printer/test_data/unification.output deleted file mode 100644 index 4db7bd2d5..000000000 --- a/kclvm/ast/src/printer/test_data/unification.output +++ /dev/null @@ -1,4 +0,0 @@ -schema Config: - name: str - -config: Config {name = "name"} diff --git a/kclvm/ast/src/printer/tests.rs b/kclvm/ast/src/printer/tests.rs deleted file mode 100644 index 26f971ec9..000000000 --- a/kclvm/ast/src/printer/tests.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::path::PathBuf; - -use super::print_ast_module; -use kclvm_parser::parse_file; -use pretty_assertions::assert_eq; - -const FILE_INPUT_SUFFIX: &str = ".input"; -const FILE_OUTPUT_SUFFIX: &str = ".output"; -const TEST_CASES: &[&'static str; 15] = &[ - "arguments", - "empty", - "if_stmt", - "import", - "unary", - "codelayout", - "collection_if", - "comment", - "index_sign", - "joined_str", - "lambda", - "quant", - "rule", - "type_alias", - "unification", -]; - -fn read_data(data_name: &str) -> (String, String) { - let mut filename = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - filename.push(&format!("src/test_data/{}{}", data_name, FILE_INPUT_SUFFIX)); - - let module = parse_file(filename.to_str().unwrap(), None); - - let mut filename_expect = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - filename_expect.push(&format!( - "src/test_data/{}{}", - data_name, FILE_OUTPUT_SUFFIX - )); - ( - print_ast_module(&module.unwrap()), - std::fs::read_to_string(filename_expect.to_str().unwrap()).unwrap(), - ) -} - -#[test] -fn test_ast_printer() { - for case in TEST_CASES { - let (data_input, data_output) = read_data(case); - assert_eq!(data_input, data_output, "Test failed on {}", case); - } -} diff --git a/kclvm/ast_pretty/Cargo.toml b/kclvm/ast_pretty/Cargo.toml index 6989dbe12..1fd2daa92 100644 --- a/kclvm/ast_pretty/Cargo.toml +++ b/kclvm/ast_pretty/Cargo.toml @@ -10,5 +10,9 @@ kclvm-parser = {path = "../parser", version = "0.1.0"} kclvm-error = {path = "../error", version = "0.1.0"} kclvm-ast = {path = "../ast", version = "0.1.0"} indexmap = "1.0" +<<<<<<< HEAD fancy-regex = "0.7.1" -pretty_assertions = "1.3.0" \ No newline at end of file +pretty_assertions = "1.3.0" +======= +fancy-regex = "0.7.1" +>>>>>>> b15d822 (mv query to ast_pretty) diff --git a/kclvm/ast_pretty/src/lib.rs b/kclvm/ast_pretty/src/lib.rs index cab3ebaf9..ca76b90cc 100644 --- a/kclvm/ast_pretty/src/lib.rs +++ b/kclvm/ast_pretty/src/lib.rs @@ -6,7 +6,18 @@ use kclvm_ast::{ }; use std::collections::VecDeque; +<<<<<<< HEAD use crate::{ast, token::TokenKind, walker::MutSelfTypedResultWalker}; +======= +<<<<<<<< HEAD:kclvm/ast/src/printer/mod.rs +<<<<<<<< HEAD:kclvm/ast_pretty/src/lib.rs +======== +use crate::{ast, token::TokenKind, walker::MutSelfTypedResultWalker}; + +>>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/mod.rs +======== +>>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/lib.rs +>>>>>>> b15d822 (mv query to ast_pretty) mod node; #[cfg(test)] diff --git a/kclvm/ast_pretty/src/node.rs b/kclvm/ast_pretty/src/node.rs index 00d354b3f..ef4f25062 100644 --- a/kclvm/ast_pretty/src/node.rs +++ b/kclvm/ast_pretty/src/node.rs @@ -1,5 +1,9 @@ use std::collections::HashSet; +<<<<<<< HEAD +======= +<<<<<<<< HEAD:kclvm/ast/src/printer/node.rs +>>>>>>> b15d822 (mv query to ast_pretty) <<<<<<<< HEAD:kclvm/ast_pretty/src/node.rs use kclvm_ast::{ ast::{self, CallExpr}, @@ -10,8 +14,28 @@ use kclvm_error::bug; ======== use kclvm_error::bug; +<<<<<<< HEAD use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; >>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs +======= +<<<<<<< HEAD +use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; +>>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs +======= +use crate::{ +======== +use kclvm_ast::{ +>>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/node.rs + ast::{self, CallExpr}, + token::{DelimToken, TokenKind}, + walker::MutSelfTypedResultWalker, +}; +<<<<<<<< HEAD:kclvm/ast/src/printer/node.rs +>>>>>>> 55680e6 (fmt) +======== +use kclvm_error::bug; +>>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/node.rs +>>>>>>> b15d822 (mv query to ast_pretty) use super::{Indentation, Printer}; diff --git a/kclvm/ast_pretty/src/tests.rs b/kclvm/ast_pretty/src/tests.rs index 26f971ec9..c4983fa86 100644 --- a/kclvm/ast_pretty/src/tests.rs +++ b/kclvm/ast_pretty/src/tests.rs @@ -1,8 +1,18 @@ use std::path::PathBuf; +<<<<<<< HEAD use super::print_ast_module; use kclvm_parser::parse_file; use pretty_assertions::assert_eq; +======= +<<<<<<<< HEAD:kclvm/ast/src/printer/tests.rs +use super::print_ast_module; +======== +>>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/tests.rs +use kclvm_parser::parse_file; + +use super::print_ast_module; +>>>>>>> b15d822 (mv query to ast_pretty) const FILE_INPUT_SUFFIX: &str = ".input"; const FILE_OUTPUT_SUFFIX: &str = ".output"; diff --git a/kclvm/parser/src/lib.rs b/kclvm/parser/src/lib.rs index ecfc34a32..be02086d2 100644 --- a/kclvm/parser/src/lib.rs +++ b/kclvm/parser/src/lib.rs @@ -70,6 +70,7 @@ pub fn parse_file(filename: &str, code: Option) -> Result Date: Sat, 8 Oct 2022 20:31:19 +0800 Subject: [PATCH 04/10] remove useless dependencies --- kclvm/Cargo.lock | 4 ---- kclvm/ast/Cargo.toml | 4 ---- kclvm/ast_pretty/Cargo.toml | 4 ++++ kclvm/parser/src/lib.rs | 1 - 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 915761b5b..a4e3ce81c 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -604,12 +604,8 @@ dependencies = [ name = "kclvm-ast" version = "0.1.0" dependencies = [ - "fancy-regex", - "indexmap", - "kclvm-error", "kclvm-parser", "kclvm-span", - "pretty_assertions", "rustc_span", "serde", "serde_json", diff --git a/kclvm/ast/Cargo.toml b/kclvm/ast/Cargo.toml index eeb9430da..46f689666 100644 --- a/kclvm/ast/Cargo.toml +++ b/kclvm/ast/Cargo.toml @@ -9,12 +9,8 @@ edition = "2021" rustc_span = { path = "../3rdparty/rustc_span" } serde = { version = "1", features = ["derive"] } serde_json = "1.0" -indexmap = "1.0" -fancy-regex = "0.7.1" kclvm-span = {path = "../span", version = "0.1.0"} -kclvm-error = {path = "../error", version = "0.1.0"} [dev-dependencies] kclvm-parser = {path = "../parser", version = "0.1.0"} -pretty_assertions = "1.2.1" diff --git a/kclvm/ast_pretty/Cargo.toml b/kclvm/ast_pretty/Cargo.toml index 1fd2daa92..9a8b295b9 100644 --- a/kclvm/ast_pretty/Cargo.toml +++ b/kclvm/ast_pretty/Cargo.toml @@ -11,8 +11,12 @@ kclvm-error = {path = "../error", version = "0.1.0"} kclvm-ast = {path = "../ast", version = "0.1.0"} indexmap = "1.0" <<<<<<< HEAD +<<<<<<< HEAD fancy-regex = "0.7.1" pretty_assertions = "1.3.0" ======= fancy-regex = "0.7.1" >>>>>>> b15d822 (mv query to ast_pretty) +======= +fancy-regex = "0.7.1" +>>>>>>> f9e4f7b (remove useless dependencies) diff --git a/kclvm/parser/src/lib.rs b/kclvm/parser/src/lib.rs index be02086d2..ecfc34a32 100644 --- a/kclvm/parser/src/lib.rs +++ b/kclvm/parser/src/lib.rs @@ -70,7 +70,6 @@ pub fn parse_file(filename: &str, code: Option) -> Result Date: Sat, 8 Oct 2022 20:37:04 +0800 Subject: [PATCH 05/10] add pretty_assertions --- kclvm/Cargo.lock | 4 ++++ kclvm/ast_pretty/Cargo.toml | 4 ++++ kclvm/ast_pretty/src/tests.rs | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index a4e3ce81c..7d7632fc8 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -620,10 +620,14 @@ dependencies = [ "kclvm-ast", "kclvm-error", "kclvm-parser", +<<<<<<< HEAD <<<<<<< HEAD "pretty_assertions", ======= >>>>>>> b15d822 (mv query to ast_pretty) +======= + "pretty_assertions", +>>>>>>> 925e86b (add pretty_assertions) ] [[package]] diff --git a/kclvm/ast_pretty/Cargo.toml b/kclvm/ast_pretty/Cargo.toml index 9a8b295b9..ded763da8 100644 --- a/kclvm/ast_pretty/Cargo.toml +++ b/kclvm/ast_pretty/Cargo.toml @@ -13,6 +13,7 @@ indexmap = "1.0" <<<<<<< HEAD <<<<<<< HEAD fancy-regex = "0.7.1" +<<<<<<< HEAD pretty_assertions = "1.3.0" ======= fancy-regex = "0.7.1" @@ -20,3 +21,6 @@ fancy-regex = "0.7.1" ======= fancy-regex = "0.7.1" >>>>>>> f9e4f7b (remove useless dependencies) +======= +pretty_assertions = "1.3.0" +>>>>>>> 925e86b (add pretty_assertions) diff --git a/kclvm/ast_pretty/src/tests.rs b/kclvm/ast_pretty/src/tests.rs index c4983fa86..9b628b94f 100644 --- a/kclvm/ast_pretty/src/tests.rs +++ b/kclvm/ast_pretty/src/tests.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; +<<<<<<< HEAD <<<<<<< HEAD use super::print_ast_module; use kclvm_parser::parse_file; @@ -13,6 +14,11 @@ use kclvm_parser::parse_file; use super::print_ast_module; >>>>>>> b15d822 (mv query to ast_pretty) +======= +use super::print_ast_module; +use kclvm_parser::parse_file; +use pretty_assertions::assert_eq; +>>>>>>> 925e86b (add pretty_assertions) const FILE_INPUT_SUFFIX: &str = ".input"; const FILE_OUTPUT_SUFFIX: &str = ".output"; From 76c67930fa7c41e0ace740ed7b12eb0622c95511 Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sun, 9 Oct 2022 10:02:47 +0800 Subject: [PATCH 06/10] refactor(kclvm-tools): move 'query' out of 'kclvm-tools'. move 'query' from 'kclvm-tools' to 'kclvm-query'. issue #67. --- kclvm/Cargo.lock | 18 +++++++++++++++++- kclvm/Cargo.toml | 4 +++- kclvm/capi/Cargo.toml | 3 ++- kclvm/capi/src/service/service.rs | 4 ++-- kclvm/query/Cargo.toml | 17 +++++++++++++++++ .../src/query/mod.rs => query/src/lib.rs} | 0 .../{tools/src/query => query/src}/override.rs | 1 + .../src/query => query/src}/test_data/config.k | 0 .../src}/test_data/import_paths.k | 0 .../src/query => query/src}/test_data/kcl.mod | 0 .../src/query => query/src}/test_data/simple.k | 0 kclvm/{tools/src/query => query/src}/tests.rs | 0 kclvm/{tools/src/query => query/src}/util.rs | 0 kclvm/runner/Cargo.toml | 2 +- kclvm/runner/src/lib.rs | 2 +- kclvm/sema/benches/my_benchmark.rs | 15 ++++++++++----- kclvm/src/lib.rs | 2 +- kclvm/tools/Cargo.toml | 1 + kclvm/tools/benches/benchmark.rs | 2 +- kclvm/tools/src/lib.rs | 1 - 20 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 kclvm/query/Cargo.toml rename kclvm/{tools/src/query/mod.rs => query/src/lib.rs} (100%) rename kclvm/{tools/src/query => query/src}/override.rs (99%) rename kclvm/{tools/src/query => query/src}/test_data/config.k (100%) rename kclvm/{tools/src/query => query/src}/test_data/import_paths.k (100%) rename kclvm/{tools/src/query => query/src}/test_data/kcl.mod (100%) rename kclvm/{tools/src/query => query/src}/test_data/simple.k (100%) rename kclvm/{tools/src/query => query/src}/tests.rs (100%) rename kclvm/{tools/src/query => query/src}/util.rs (100%) diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 7d7632fc8..0c704fc61 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -587,6 +587,7 @@ dependencies = [ "kclvm-config", "kclvm-error", "kclvm-parser", + "kclvm-query", "kclvm-runner", "kclvm-runtime", "kclvm-sema", @@ -637,6 +638,7 @@ dependencies = [ "criterion", "kclvm-ast", "kclvm-parser", + "kclvm-query", "kclvm-runner", "kclvm-runtime", "kclvm-tools", @@ -747,6 +749,19 @@ dependencies = [ "unicode_names2", ] +[[package]] +name = "kclvm-query" +version = "0.1.0" +dependencies = [ + "anyhow", + "kclvm-ast", + "kclvm-ast-pretty", + "kclvm-error", + "kclvm-parser", + "kclvm-sema", + "pretty_assertions", +] + [[package]] name = "kclvm-runner" version = "0.1.0" @@ -762,9 +777,9 @@ dependencies = [ "kclvm-config", "kclvm-error", "kclvm-parser", + "kclvm-query", "kclvm-runtime", "kclvm-sema", - "kclvm-tools", "kclvm-version", "libc", "libloading", @@ -846,6 +861,7 @@ dependencies = [ "kclvm-config", "kclvm-error", "kclvm-parser", + "kclvm-query", "kclvm-sema", "pretty_assertions", "serde_json", diff --git a/kclvm/Cargo.toml b/kclvm/Cargo.toml index 34f09e3b3..5fba0ea52 100644 --- a/kclvm/Cargo.toml +++ b/kclvm/Cargo.toml @@ -37,6 +37,7 @@ kclvm-sema = {path = "./sema", version = "0.1.0"} kclvm-tools = {path = "./tools", version = "0.1.0"} kclvm-version = {path = "./version", version = "0.1.0"} kclvm-error = {path = "./error", version = "0.1.0"} +kclvm-query = {path = "./query", version = "0.1.0"} [profile.release] rpath = true @@ -60,5 +61,6 @@ members = [ "sema", "span", "tools", - "version" + "version", + "query" ] diff --git a/kclvm/capi/Cargo.toml b/kclvm/capi/Cargo.toml index d8b85ef72..e08da0a8c 100644 --- a/kclvm/capi/Cargo.toml +++ b/kclvm/capi/Cargo.toml @@ -19,7 +19,8 @@ kclvm-runner = {path = "../runner", version = "0.1.0"} kclvm-parser = {path = "../parser", version = "0.1.0"} kclvm-ast = {path = "../ast", version = "0.1.0"} kclvm-runtime = {path = "../runtime", version = "0.1.0"} -kclvm-tools = {path = "../tools", version= "0.1.0" } +kclvm-tools = {path = "../tools", version = "0.1.0" } +kclvm-query = {path = "../query", version = "0.1.0"} [dev-dependencies] criterion = "0.3" diff --git a/kclvm/capi/src/service/service.rs b/kclvm/capi/src/service/service.rs index 079f1a8e6..a31b81075 100644 --- a/kclvm/capi/src/service/service.rs +++ b/kclvm/capi/src/service/service.rs @@ -4,8 +4,8 @@ use crate::model::gpyrpc::*; use kclvm::ValueRef; use kclvm_parser::load_program; -use kclvm_tools::query::apply_overrides; -use kclvm_tools::query::override_file; +use kclvm_query::apply_overrides; +use kclvm_query::override_file; use protobuf_json_mapping::print_to_string_with_options; use protobuf_json_mapping::PrintOptions; diff --git a/kclvm/query/Cargo.toml b/kclvm/query/Cargo.toml new file mode 100644 index 000000000..bb1229b0e --- /dev/null +++ b/kclvm/query/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "kclvm-query" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0" +kclvm-ast = {path = "../ast", version = "0.1.0"} +kclvm-ast-pretty = {path = "../ast_pretty", version = "0.1.0"} +kclvm-parser = {path = "../parser", version = "0.1.0"} +kclvm-sema = {path = "../sema", version = "0.1.0"} +kclvm-error = {path = "../error", version = "0.1.0"} + +[dev-dependencies] +pretty_assertions = "1.2.1" diff --git a/kclvm/tools/src/query/mod.rs b/kclvm/query/src/lib.rs similarity index 100% rename from kclvm/tools/src/query/mod.rs rename to kclvm/query/src/lib.rs diff --git a/kclvm/tools/src/query/override.rs b/kclvm/query/src/override.rs similarity index 99% rename from kclvm/tools/src/query/override.rs rename to kclvm/query/src/override.rs index 413c5c10a..216bf99b0 100644 --- a/kclvm/tools/src/query/override.rs +++ b/kclvm/query/src/override.rs @@ -7,6 +7,7 @@ use kclvm_ast::path::{get_attr_paths_from_config_expr, get_key_path}; use kclvm_ast::walker::MutSelfMutWalker; use kclvm_ast::{ast, walk_if_mut}; use kclvm_ast_pretty::print_ast_module; +use kclvm_error::bug; use kclvm_parser::parse_expr; use kclvm_sema::pre_process::{fix_config_expr_nest_attr, transform_multi_assign}; diff --git a/kclvm/tools/src/query/test_data/config.k b/kclvm/query/src/test_data/config.k similarity index 100% rename from kclvm/tools/src/query/test_data/config.k rename to kclvm/query/src/test_data/config.k diff --git a/kclvm/tools/src/query/test_data/import_paths.k b/kclvm/query/src/test_data/import_paths.k similarity index 100% rename from kclvm/tools/src/query/test_data/import_paths.k rename to kclvm/query/src/test_data/import_paths.k diff --git a/kclvm/tools/src/query/test_data/kcl.mod b/kclvm/query/src/test_data/kcl.mod similarity index 100% rename from kclvm/tools/src/query/test_data/kcl.mod rename to kclvm/query/src/test_data/kcl.mod diff --git a/kclvm/tools/src/query/test_data/simple.k b/kclvm/query/src/test_data/simple.k similarity index 100% rename from kclvm/tools/src/query/test_data/simple.k rename to kclvm/query/src/test_data/simple.k diff --git a/kclvm/tools/src/query/tests.rs b/kclvm/query/src/tests.rs similarity index 100% rename from kclvm/tools/src/query/tests.rs rename to kclvm/query/src/tests.rs diff --git a/kclvm/tools/src/query/util.rs b/kclvm/query/src/util.rs similarity index 100% rename from kclvm/tools/src/query/util.rs rename to kclvm/query/src/util.rs diff --git a/kclvm/runner/Cargo.toml b/kclvm/runner/Cargo.toml index 501819ca5..b21102952 100644 --- a/kclvm/runner/Cargo.toml +++ b/kclvm/runner/Cargo.toml @@ -27,7 +27,7 @@ kclvm-runtime = {path = "../runtime", version = "0.1.0"} kclvm-sema = {path = "../sema", version = "0.1.0"} kclvm-version = {path = "../version", version = "0.1.0"} kclvm-error = {path = "../error", version="0.1.0"} -kclvm-tools = {path = "../tools", version = "0.1.0"} +kclvm-query = {path = "../query", version="0.1.0"} [dev-dependencies] kclvm-parser = {path = "../parser", version = "0.1.0"} diff --git a/kclvm/runner/src/lib.rs b/kclvm/runner/src/lib.rs index 821789c9e..e2080cc03 100644 --- a/kclvm/runner/src/lib.rs +++ b/kclvm/runner/src/lib.rs @@ -5,8 +5,8 @@ use command::Command; use kclvm::ValueRef; use kclvm_ast::ast::Program; use kclvm_parser::load_program; +use kclvm_query::apply_overrides; use kclvm_sema::resolver::resolve_program; -use kclvm_tools::query::apply_overrides; pub use runner::ExecProgramArgs; use runner::{ExecProgramResult, KclvmRunner, KclvmRunnerOptions}; use tempfile::tempdir; diff --git a/kclvm/sema/benches/my_benchmark.rs b/kclvm/sema/benches/my_benchmark.rs index 5b0bc6fbf..aad5d526e 100644 --- a/kclvm/sema/benches/my_benchmark.rs +++ b/kclvm/sema/benches/my_benchmark.rs @@ -1,14 +1,19 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use std::rc::Rc; + +use criterion::{criterion_group, criterion_main, Criterion}; use kclvm_sema::ty::*; pub fn criterion_benchmark(c: &mut Criterion) { c.bench_function("sup", |b| { b.iter(|| { let types = vec![ - Type::int_lit(1), - Type::INT, - Type::union(&[Type::STR, Type::dict(Type::STR, Type::STR)]), - Type::dict(Type::ANY, Type::ANY), + Rc::new(Type::int_lit(1)), + Rc::new(Type::INT), + Rc::new(Type::union(&[ + Rc::new(Type::STR), + Rc::new(Type::dict(Rc::new(Type::STR), Rc::new(Type::STR))), + ])), + Rc::new(Type::dict(Rc::new(Type::ANY), Rc::new(Type::ANY))), ]; sup(&types); }) diff --git a/kclvm/src/lib.rs b/kclvm/src/lib.rs index 93793a089..472a7f087 100644 --- a/kclvm/src/lib.rs +++ b/kclvm/src/lib.rs @@ -1,9 +1,9 @@ extern crate serde; use kclvm_parser::load_program; +use kclvm_query::apply_overrides; use kclvm_runner::execute; use kclvm_runner::runner::*; -use kclvm_tools::query::apply_overrides; #[no_mangle] pub extern "C" fn kclvm_cli_run(args: *const i8, plugin_agent: *const i8) -> *const i8 { diff --git a/kclvm/tools/Cargo.toml b/kclvm/tools/Cargo.toml index 87333d124..2cef3ddaa 100644 --- a/kclvm/tools/Cargo.toml +++ b/kclvm/tools/Cargo.toml @@ -17,6 +17,7 @@ kclvm-parser = {path = "../parser", version = "0.1.0"} kclvm-sema = {path = "../sema", version = "0.1.0"} kclvm-config = {path = "../config", version = "0.1.0"} kclvm-ast-pretty = {path = "../ast_pretty", version = "0.1.0"} +kclvm-query = {path = "../query", version = "0.1.0"} serde_json = "1.0.85" serde_yaml = "0.9.13" diff --git a/kclvm/tools/benches/benchmark.rs b/kclvm/tools/benches/benchmark.rs index d23694f90..f9e7d64e6 100644 --- a/kclvm/tools/benches/benchmark.rs +++ b/kclvm/tools/benches/benchmark.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, Criterion}; +use kclvm_query::override_file; use kclvm_tools::format::{format, FormatOptions}; -use kclvm_tools::query::override_file; pub fn criterion_benchmark_override(c: &mut Criterion) { c.bench_function("override", |b| { diff --git a/kclvm/tools/src/lib.rs b/kclvm/tools/src/lib.rs index 37e1940b4..9037f496a 100644 --- a/kclvm/tools/src/lib.rs +++ b/kclvm/tools/src/lib.rs @@ -1,6 +1,5 @@ pub mod format; pub mod lint; -pub mod query; mod util; pub mod vet; From 48b032176e530d9e0089fae2a2e88effd5377960 Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sun, 9 Oct 2022 10:31:11 +0800 Subject: [PATCH 07/10] fix rebase conflicts --- kclvm/Cargo.lock | 460 +++++--- kclvm/ast_pretty/Cargo.toml | 12 - kclvm/ast_pretty/src/lib.rs | 13 - kclvm/ast_pretty/src/node.rs | 30 - kclvm/ast_pretty/src/tests.rs | 16 - kclvm/capi/src/model/gpyrpc.rs | 4 +- kclvm/runner/Cargo.lock | 1945 -------------------------------- 7 files changed, 274 insertions(+), 2206 deletions(-) delete mode 100644 kclvm/runner/Cargo.lock diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 0c704fc61..77d267cc3 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -15,13 +15,22 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "annotate-snippets" version = "0.8.0" @@ -30,9 +39,9 @@ checksum = "d78ea013094e5ea606b1c05fe35f1dd7ea1eb1ea259908d040b25bd5ec677ee5" [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "arrayvec" @@ -65,9 +74,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bit-set" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" dependencies = [ "bit-vec", ] @@ -95,9 +104,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -116,18 +125,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "cast" -version = "0.2.7" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" -dependencies = [ - "rustc_version", -] +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" @@ -149,14 +155,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ - "libc", + "iana-time-zone", + "js-sys", "num-integer", "num-traits", "time", + "wasm-bindgen", "winapi", ] @@ -195,20 +203,36 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] [[package]] name = "criterion" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" +checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", "cast", @@ -232,9 +256,9 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" +checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" dependencies = [ "cast", "itertools", @@ -242,9 +266,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -252,9 +276,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ "cfg-if 1.0.0", "crossbeam-epoch", @@ -263,33 +287,31 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.9" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" dependencies = [ "autocfg", "cfg-if 1.0.0", "crossbeam-utils", "memoffset", - "once_cell", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.10" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if 1.0.0", - "once_cell", ] [[package]] name = "crypto-common" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5999502d32b9c48d492abe66392408144895020ec4709e549e840799f3bb74c0" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", "typenum", @@ -319,10 +341,54 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "cxx" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f39818dcfc97d45b03953c1292efc4e80954e1583c4aa770bac1383e2310a4" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "3e580d70777c116df50c390d1211993f62d40302881e54d4b79727acb83d0199" dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56a46460b88d1cec95112c8c363f0e2c39afdb237f60583b0b36343bf627ea9c" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747b608fecf06b0d72d440f27acc99288207324b793be2c17991839f3d4995ea" +dependencies = [ + "proc-macro2", "quote", "syn", ] @@ -344,11 +410,11 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ - "block-buffer 0.10.2", + "block-buffer 0.10.3", "crypto-common", ] @@ -360,9 +426,9 @@ checksum = "8c97b9233581d84b8e1e689cdd3a47b6f69770084fc246e86a7f78b0d9c1d4a5" [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "ena" @@ -384,9 +450,9 @@ dependencies = [ [[package]] name = "expect-test" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dced95c9dcd4e3241f95841aad395f9c8d7933a3b0b524bdeb2440885c72a271" +checksum = "1d4661aca38d826eb7c72fe128e4238220616de4c0cc00db7bfc38e2e1364dd3" dependencies = [ "dissimilar", "once_cell", @@ -404,9 +470,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] @@ -441,9 +507,9 @@ checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", "version_check", @@ -474,9 +540,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "hashbrown" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hermit-abi" @@ -487,6 +553,30 @@ dependencies = [ "libc", ] +[[package]] +name = "iana-time-zone" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fde6edd6cef363e9359ed3c98ba64590ba9eecba2293eb5a723ab32aee8926aa" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "indexmap" version = "1.9.1" @@ -501,7 +591,7 @@ dependencies = [ [[package]] name = "inkwell" version = "0.1.0" -source = "git+https://github.com/TheDan64/inkwell?branch=master#25b9fc5870370211504e874e7c81dc53573bca79" +source = "git+https://github.com/TheDan64/inkwell?branch=master#27b8ab5623696709c8948fabfc62ce47d5a32edd" dependencies = [ "either", "inkwell_internals", @@ -514,7 +604,7 @@ dependencies = [ [[package]] name = "inkwell_internals" version = "0.5.0" -source = "git+https://github.com/TheDan64/inkwell?branch=master#25b9fc5870370211504e874e7c81dc53573bca79" +source = "git+https://github.com/TheDan64/inkwell?branch=master#27b8ab5623696709c8948fabfc62ce47d5a32edd" dependencies = [ "proc-macro2", "quote", @@ -532,9 +622,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] @@ -547,24 +637,24 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "jobserver" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.58" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -621,14 +711,7 @@ dependencies = [ "kclvm-ast", "kclvm-error", "kclvm-parser", -<<<<<<< HEAD -<<<<<<< HEAD - "pretty_assertions", -======= ->>>>>>> b15d822 (mv query to ast_pretty) -======= "pretty_assertions", ->>>>>>> 925e86b (add pretty_assertions) ] [[package]] @@ -685,7 +768,7 @@ dependencies = [ "ron", "rust-crypto", "serde", - "serde_yaml 0.8.24", + "serde_yaml 0.8.26", "toml", ] @@ -810,7 +893,7 @@ dependencies = [ "regex", "serde", "serde_json", - "serde_yaml 0.8.24", + "serde_yaml 0.8.26", "sha1", "sha2 0.9.9", "unic-ucd-bidi", @@ -890,9 +973,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "libloading" @@ -904,6 +987,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -912,22 +1004,22 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "llvm-sys" -version = "120.2.4" +version = "120.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b716322964966a62377cf86e64f00ca7043505fdf27bd2ec7d41ae6682d1e7" +checksum = "a1c9655eec036faf512507746ce70765bda72ed98e52b4328f0d7b93e970c6d8" dependencies = [ "cc", "lazy_static", "libc", "regex", - "semver 0.11.0", + "semver", ] [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -950,11 +1042,11 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "md-5" -version = "0.10.1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582" +checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -1029,9 +1121,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "oorandom" @@ -1091,10 +1183,11 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "pest" -version = "2.1.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +checksum = "dbc7bc69c062e492337d74d59b120c274fd3d261b6bf6d3207d499b4b379c41a" dependencies = [ + "thiserror", "ucd-trie", ] @@ -1160,9 +1253,9 @@ checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "plotters" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" dependencies = [ "num-traits", "plotters-backend", @@ -1173,15 +1266,15 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" [[package]] name = "plotters-svg" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" dependencies = [ "plotters-backend", ] @@ -1212,18 +1305,18 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "protobuf" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee4a7d8b91800c8f167a6268d1a1026607368e1adc84e98fe044aeb905302f7" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" dependencies = [ "once_cell", "protobuf-support", @@ -1232,9 +1325,9 @@ dependencies = [ [[package]] name = "protobuf-codegen" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b893e5e7d3395545d5244f8c0d33674025bd566b26c03bfda49b82c6dec45e" +checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901" dependencies = [ "anyhow", "once_cell", @@ -1247,9 +1340,9 @@ dependencies = [ [[package]] name = "protobuf-json-mapping" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be57102eab3e96da74543c6d4cb44b375d87497b4e8959c2fbdc637f2c92ea1a" +checksum = "ce19fee00c35e62179f79d622f440c27466c9f8dff68ca907d8f59dfc8a88adb" dependencies = [ "protobuf", "protobuf-support", @@ -1258,9 +1351,9 @@ dependencies = [ [[package]] name = "protobuf-parse" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1447dd751c434cc1b415579837ebd0411ed7d67d465f38010da5d7cd33af4d" +checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" dependencies = [ "anyhow", "indexmap", @@ -1274,9 +1367,9 @@ dependencies = [ [[package]] name = "protobuf-support" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca157fe12fc7ee2e315f2f735e27df41b3d97cdd70ea112824dac1ffb08ee1c" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" dependencies = [ "thiserror", ] @@ -1333,18 +1426,18 @@ checksum = "9653c3ed92974e34c5a6e0a510864dab979760481714c172e0a34e437cb98804" [[package]] name = "psm" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" dependencies = [ "cc", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -1380,7 +1473,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -1390,7 +1483,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -1410,9 +1503,9 @@ checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] @@ -1452,18 +1545,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.5.6" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", @@ -1478,9 +1571,9 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "remove_dir_all" @@ -1615,25 +1708,16 @@ dependencies = [ "rustc_data_structures", "scoped-tls", "sha-1", - "sha2 0.10.2", + "sha2 0.10.6", "tracing", "unicode-width", ] -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.12", -] - [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "same-file" @@ -1656,6 +1740,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + [[package]] name = "semver" version = "0.11.0" @@ -1665,12 +1755,6 @@ dependencies = [ "semver-parser", ] -[[package]] -name = "semver" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" - [[package]] name = "semver-parser" version = "0.10.2" @@ -1682,9 +1766,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.143" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] @@ -1701,9 +1785,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.143" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -1716,16 +1800,16 @@ version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ - "itoa 1.0.2", + "itoa 1.0.4", "ryu", "serde", ] [[package]] name = "serde_yaml" -version = "0.8.24" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc" +checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" dependencies = [ "indexmap", "ryu", @@ -1740,7 +1824,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8613d593412a0deb7bbd8de9d908efff5a0cb9ccd8f62c641e7b2ed2f57291d1" dependencies = [ "indexmap", - "itoa 1.0.2", + "itoa 1.0.4", "ryu", "serde", "unsafe-libyaml", @@ -1754,7 +1838,7 @@ checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -1787,13 +1871,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -1804,9 +1888,9 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "stable_deref_trait" @@ -1816,9 +1900,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stacker" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4" +checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" dependencies = [ "cc", "cfg-if 1.0.0", @@ -1835,9 +1919,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" dependencies = [ "proc-macro2", "quote", @@ -1906,18 +1990,18 @@ checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", @@ -1965,9 +2049,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -1977,9 +2061,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", @@ -1988,9 +2072,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", ] @@ -2003,9 +2087,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "ucd-trie" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unic-char-property" @@ -2079,21 +2163,21 @@ checksum = "623f59e6af2a98bdafeb93fa277ac8e1e40440973001ca15cf4ae1541cd16d56" [[package]] name = "unicode-ident" -version = "1.0.1" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "unicode-xid" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unicode_names2" @@ -2103,9 +2187,9 @@ checksum = "87d6678d7916394abad0d4b19df4d3802e1fd84abd7d701f39b75ee71b9e8cf1" [[package]] name = "unsafe-libyaml" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0" +checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" [[package]] name = "version_check" @@ -2138,9 +2222,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.81" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2148,13 +2232,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.81" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -2163,9 +2247,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.81" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2173,9 +2257,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.81" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -2186,15 +2270,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.81" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.58" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -2202,13 +2286,13 @@ dependencies = [ [[package]] name = "which" -version = "4.2.5" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] diff --git a/kclvm/ast_pretty/Cargo.toml b/kclvm/ast_pretty/Cargo.toml index ded763da8..d7ce2827b 100644 --- a/kclvm/ast_pretty/Cargo.toml +++ b/kclvm/ast_pretty/Cargo.toml @@ -10,17 +10,5 @@ kclvm-parser = {path = "../parser", version = "0.1.0"} kclvm-error = {path = "../error", version = "0.1.0"} kclvm-ast = {path = "../ast", version = "0.1.0"} indexmap = "1.0" -<<<<<<< HEAD -<<<<<<< HEAD fancy-regex = "0.7.1" -<<<<<<< HEAD pretty_assertions = "1.3.0" -======= -fancy-regex = "0.7.1" ->>>>>>> b15d822 (mv query to ast_pretty) -======= -fancy-regex = "0.7.1" ->>>>>>> f9e4f7b (remove useless dependencies) -======= -pretty_assertions = "1.3.0" ->>>>>>> 925e86b (add pretty_assertions) diff --git a/kclvm/ast_pretty/src/lib.rs b/kclvm/ast_pretty/src/lib.rs index ca76b90cc..bc4b4426b 100644 --- a/kclvm/ast_pretty/src/lib.rs +++ b/kclvm/ast_pretty/src/lib.rs @@ -5,19 +5,6 @@ use kclvm_ast::{ walker::MutSelfTypedResultWalker, }; use std::collections::VecDeque; - -<<<<<<< HEAD -use crate::{ast, token::TokenKind, walker::MutSelfTypedResultWalker}; -======= -<<<<<<<< HEAD:kclvm/ast/src/printer/mod.rs -<<<<<<<< HEAD:kclvm/ast_pretty/src/lib.rs -======== -use crate::{ast, token::TokenKind, walker::MutSelfTypedResultWalker}; - ->>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/mod.rs -======== ->>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/lib.rs ->>>>>>> b15d822 (mv query to ast_pretty) mod node; #[cfg(test)] diff --git a/kclvm/ast_pretty/src/node.rs b/kclvm/ast_pretty/src/node.rs index ef4f25062..c9db75b3f 100644 --- a/kclvm/ast_pretty/src/node.rs +++ b/kclvm/ast_pretty/src/node.rs @@ -1,41 +1,11 @@ use std::collections::HashSet; -<<<<<<< HEAD -======= -<<<<<<<< HEAD:kclvm/ast/src/printer/node.rs ->>>>>>> b15d822 (mv query to ast_pretty) -<<<<<<<< HEAD:kclvm/ast_pretty/src/node.rs use kclvm_ast::{ ast::{self, CallExpr}, token::{DelimToken, TokenKind}, walker::MutSelfTypedResultWalker, }; use kclvm_error::bug; -======== -use kclvm_error::bug; - -<<<<<<< HEAD -use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; ->>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs -======= -<<<<<<< HEAD -use crate::{ast::{self, CallExpr}, walker::MutSelfTypedResultWalker, token::{TokenKind, DelimToken}}; ->>>>>>>> b59824d (refactor(kclvm-tools): move 'printer' from 'kclvm-tools' to 'kclvm-ast'.):kclvm/ast/src/printer/node.rs -======= -use crate::{ -======== -use kclvm_ast::{ ->>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/node.rs - ast::{self, CallExpr}, - token::{DelimToken, TokenKind}, - walker::MutSelfTypedResultWalker, -}; -<<<<<<<< HEAD:kclvm/ast/src/printer/node.rs ->>>>>>> 55680e6 (fmt) -======== -use kclvm_error::bug; ->>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/node.rs ->>>>>>> b15d822 (mv query to ast_pretty) use super::{Indentation, Printer}; diff --git a/kclvm/ast_pretty/src/tests.rs b/kclvm/ast_pretty/src/tests.rs index 9b628b94f..26f971ec9 100644 --- a/kclvm/ast_pretty/src/tests.rs +++ b/kclvm/ast_pretty/src/tests.rs @@ -1,24 +1,8 @@ use std::path::PathBuf; -<<<<<<< HEAD -<<<<<<< HEAD use super::print_ast_module; use kclvm_parser::parse_file; use pretty_assertions::assert_eq; -======= -<<<<<<<< HEAD:kclvm/ast/src/printer/tests.rs -use super::print_ast_module; -======== ->>>>>>>> b15d822 (mv query to ast_pretty):kclvm/ast_pretty/src/tests.rs -use kclvm_parser::parse_file; - -use super::print_ast_module; ->>>>>>> b15d822 (mv query to ast_pretty) -======= -use super::print_ast_module; -use kclvm_parser::parse_file; -use pretty_assertions::assert_eq; ->>>>>>> 925e86b (add pretty_assertions) const FILE_INPUT_SUFFIX: &str = ".input"; const FILE_OUTPUT_SUFFIX: &str = ".output"; diff --git a/kclvm/capi/src/model/gpyrpc.rs b/kclvm/capi/src/model/gpyrpc.rs index 51beadfdf..54ed22dcd 100644 --- a/kclvm/capi/src/model/gpyrpc.rs +++ b/kclvm/capi/src/model/gpyrpc.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 3.1.0. Do not edit +// This file is generated by rust-protobuf 3.2.0. Do not edit // .proto file is parsed by protoc 3.19.4 // @generated @@ -23,7 +23,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_1_0; +const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_2_0; #[derive(PartialEq,Clone,Default,Debug)] // @@protoc_insertion_point(message:gpyrpc.CmdArgSpec) diff --git a/kclvm/runner/Cargo.lock b/kclvm/runner/Cargo.lock deleted file mode 100644 index 1479f00e1..000000000 --- a/kclvm/runner/Cargo.lock +++ /dev/null @@ -1,1945 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - -[[package]] -name = "annotate-snippets" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78ea013094e5ea606b1c05fe35f1dd7ea1eb1ea259908d040b25bd5ec677ee5" - -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - -[[package]] -name = "bit-set" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "block-buffer" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", - "serde", -] - -[[package]] -name = "bumpalo" -version = "3.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" - -[[package]] -name = "cast" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" -dependencies = [ - "rustc_version", -] - -[[package]] -name = "cc" -version = "1.0.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -dependencies = [ - "libc", - "num-integer", - "num-traits", - "time", - "winapi", -] - -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim", - "textwrap", - "unicode-width", - "vec_map", -] - -[[package]] -name = "cpufeatures" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" -dependencies = [ - "libc", -] - -[[package]] -name = "criterion" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" -dependencies = [ - "atty", - "cast", - "clap", - "criterion-plot", - "csv", - "itertools", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_cbor", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" -dependencies = [ - "cast", - "itertools", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" -dependencies = [ - "autocfg", - "cfg-if 1.0.0", - "crossbeam-utils", - "lazy_static", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" -dependencies = [ - "cfg-if 1.0.0", - "lazy_static", -] - -[[package]] -name = "crypto-common" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "csv" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" -dependencies = [ - "bstr", - "csv-core", - "itoa 0.4.8", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" -dependencies = [ - "memchr", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" -dependencies = [ - "block-buffer 0.10.2", - "crypto-common", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "ena" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" -dependencies = [ - "log", -] - -[[package]] -name = "enquote" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06c36cb11dbde389f4096111698d8b567c0720e3452fd5ac3e6b4e47e1939932" -dependencies = [ - "thiserror", -] - -[[package]] -name = "fancy-regex" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6b8560a05112eb52f04b00e5d3790c0dd75d9d980eb8a122fb23b92a623ccf" -dependencies = [ - "bit-set", - "regex", -] - -[[package]] -name = "fastrand" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" -dependencies = [ - "instant", -] - -[[package]] -name = "fixedbitset" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e" - -[[package]] -name = "fslock" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04412b8935272e3a9bae6f48c7bfff74c2911f60525404edfdd28e49884c3bfb" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - -[[package]] -name = "generic-array" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "half" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "indexmap" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" -dependencies = [ - "autocfg", - "hashbrown", - "rustc-rayon", -] - -[[package]] -name = "inkwell" -version = "0.1.0" -source = "git+https://github.com/TheDan64/inkwell?branch=master#bff378bee02bcbb5bed35f47e9ed69e6642e9188" -dependencies = [ - "either", - "inkwell_internals", - "libc", - "llvm-sys", - "once_cell", - "parking_lot", -] - -[[package]] -name = "inkwell_internals" -version = "0.5.0" -source = "git+https://github.com/TheDan64/inkwell?branch=master#bff378bee02bcbb5bed35f47e9ed69e6642e9188" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - -[[package]] -name = "itoa" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" - -[[package]] -name = "jobserver" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" -dependencies = [ - "libc", -] - -[[package]] -name = "js-sys" -version = "0.3.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "json_minimal" -version = "0.1.3" - -[[package]] -name = "kclvm-ast" -version = "0.1.0" -dependencies = [ - "kclvm-span", - "rustc_span", - "serde", - "serde_json", -] - -[[package]] -name = "kclvm-compiler" -version = "0.1.0" -dependencies = [ - "ahash", - "bit-set", - "bitflags", - "fancy-regex", - "indexmap", - "inkwell", - "kclvm-ast", - "kclvm-error", - "kclvm-runtime", - "kclvm-sema", - "once_cell", - "phf", - "time", - "unicode_names2", -] - -[[package]] -name = "kclvm-config" -version = "0.1.0" -dependencies = [ - "ahash", - "chrono", - "fslock", - "glob", - "indexmap", - "kclvm-version", - "pathdiff", - "ron", - "rust-crypto", - "serde", - "serde_yaml", - "toml", -] - -[[package]] -name = "kclvm-error" -version = "0.1.0" -dependencies = [ - "annotate-snippets", - "atty", - "indexmap", - "kclvm-runtime", - "kclvm-span", - "rustc_span", - "termcolor", - "termize", - "tracing", -] - -[[package]] -name = "kclvm-lexer" -version = "0.1.0" -dependencies = [ - "kclvm-error", - "rustc_lexer", - "unic-emoji-char", -] - -[[package]] -name = "kclvm-macros" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "kclvm-parser" -version = "0.1.0" -dependencies = [ - "bstr", - "either", - "enquote", - "kclvm-ast", - "kclvm-config", - "kclvm-error", - "kclvm-lexer", - "kclvm-runtime", - "kclvm-sema", - "kclvm-span", - "num-bigint", - "rustc_data_structures", - "rustc_lexer", - "rustc_span", - "serde", - "serde_json", - "tracing", - "unicode_names2", -] - -[[package]] -name = "kclvm-runner" -version = "0.1.0" -dependencies = [ - "chrono", - "clap", - "criterion", - "fslock", - "glob", - "indexmap", - "kclvm-ast", - "kclvm-compiler", - "kclvm-config", - "kclvm-error", - "kclvm-parser", - "kclvm-runtime", - "kclvm-sema", - "kclvm-tools", - "kclvm-version", - "libc", - "libloading", - "serde", - "serde_json", - "threadpool", - "walkdir", -] - -[[package]] -name = "kclvm-runtime" -version = "0.1.0" -dependencies = [ - "ahash", - "base64", - "bstr", - "chrono", - "fancy-regex", - "indexmap", - "itertools", - "json_minimal", - "kclvm_runtime_internal_macros", - "libc", - "md5", - "num-integer", - "phf", - "regex", - "serde", - "serde_json", - "serde_yaml", - "sha1", - "sha2 0.9.9", - "unic-ucd-bidi", - "unic-ucd-category", - "unicode-casing", -] - -[[package]] -name = "kclvm-sema" -version = "0.1.0" -dependencies = [ - "ahash", - "bit-set", - "bitflags", - "fancy-regex", - "indexmap", - "kclvm-ast", - "kclvm-error", - "kclvm-runtime", - "kclvm-span", - "once_cell", - "petgraph", - "phf", - "unicode_names2", -] - -[[package]] -name = "kclvm-span" -version = "0.1.0" -dependencies = [ - "kclvm-macros", - "rustc_span", - "scoped-tls", -] - -[[package]] -name = "kclvm-tools" -version = "0.1.0" -dependencies = [ - "fancy-regex", - "indexmap", - "kclvm-ast", - "kclvm-error", - "kclvm-parser", -] - -[[package]] -name = "kclvm-version" -version = "0.1.0" - -[[package]] -name = "kclvm_runtime_internal_macros" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.125" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" - -[[package]] -name = "libloading" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" -dependencies = [ - "cfg-if 1.0.0", - "winapi", -] - -[[package]] -name = "linked-hash-map" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" - -[[package]] -name = "llvm-sys" -version = "120.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b716322964966a62377cf86e64f00ca7043505fdf27bd2ec7d41ae6682d1e7" -dependencies = [ - "cc", - "lazy_static", - "libc", - "regex", - "semver 0.11.0", -] - -[[package]] -name = "lock_api" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - -[[package]] -name = "md-5" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582" -dependencies = [ - "digest 0.10.3", -] - -[[package]] -name = "md5" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memmap2" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" -dependencies = [ - "libc", -] - -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" - -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "parking_lot" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall", - "smallvec", - "windows-sys", -] - -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - -[[package]] -name = "petgraph" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a13a2fa9d0b63e5f22328828741e523766fff0ee9e779316902290dff3f824f" -dependencies = [ - "fixedbitset", - "indexmap", -] - -[[package]] -name = "phf" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ac8b67553a7ca9457ce0e526948cad581819238f4a9d1ea74545851fa24f37" -dependencies = [ - "phf_macros", - "phf_shared", - "proc-macro-hack", -] - -[[package]] -name = "phf_generator" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d43f3220d96e0080cc9ea234978ccd80d904eafb17be31bb0f76daaea6493082" -dependencies = [ - "phf_shared", - "rand 0.8.5", -] - -[[package]] -name = "phf_macros" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b706f5936eb50ed880ae3009395b43ed19db5bff2ebd459c95e7bf013a89ab86" -dependencies = [ - "phf_generator", - "phf_shared", - "proc-macro-hack", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "phf_shared" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68318426de33640f02be62b4ae8eb1261be2efbc337b60c54d845bf4484e0d9" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" - -[[package]] -name = "plotters" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" - -[[package]] -name = "plotters-svg" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" -dependencies = [ - "plotters-backend", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" - -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro2" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9027b48e9d4c9175fa2218adf3557f91c1137021739951d4932f5f8268ac48aa" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "psm" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" -dependencies = [ - "cc", -] - -[[package]] -name = "quote" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" -dependencies = [ - "libc", - "rand 0.4.6", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rand_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rayon" -version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" -dependencies = [ - "autocfg", - "crossbeam-deque", - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "redox_syscall" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" -dependencies = [ - "bitflags", -] - -[[package]] -name = "regex" -version = "1.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" - -[[package]] -name = "regex-syntax" -version = "0.6.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" - -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - -[[package]] -name = "ron" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b861ecaade43ac97886a512b360d01d66be9f41f3c61088b42cedf92e03d678" -dependencies = [ - "base64", - "bitflags", - "serde", -] - -[[package]] -name = "rust-crypto" -version = "0.2.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" -dependencies = [ - "gcc", - "libc", - "rand 0.3.23", - "rustc-serialize", - "time", -] - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustc-rayon" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9974ab223660e61c1b4e7b43b827379df286736ca988308ce7e16f59f2d89246" -dependencies = [ - "crossbeam-deque", - "either", - "rustc-rayon-core", -] - -[[package]] -name = "rustc-rayon-core" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "564bfd27be8db888d0fa76aa4335e7851aaed0c2c11ad1e93aeb9349f6b88500" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", - "lazy_static", - "num_cpus", -] - -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - -[[package]] -name = "rustc_data_structures" -version = "0.0.0" -dependencies = [ - "arrayvec", - "bitflags", - "cfg-if 0.1.10", - "ena", - "indexmap", - "jobserver", - "libc", - "memmap2", - "parking_lot", - "rustc-hash", - "rustc-rayon", - "rustc-rayon-core", - "stable_deref_trait", - "stacker", - "tempfile", - "tracing", - "winapi", -] - -[[package]] -name = "rustc_lexer" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c86aae0c77166108c01305ee1a36a1e77289d7dc6ca0a3cd91ff4992de2d16a5" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "rustc_span" -version = "0.0.0" -dependencies = [ - "cfg-if 0.1.10", - "md-5", - "rustc_data_structures", - "scoped-tls", - "sha-1", - "sha2 0.10.2", - "tracing", - "unicode-width", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.9", -] - -[[package]] -name = "ryu" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - -[[package]] -name = "serde" -version = "1.0.137" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_cbor" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" -dependencies = [ - "half", - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.137" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" -dependencies = [ - "itoa 1.0.1", - "ryu", - "serde", -] - -[[package]] -name = "serde_yaml" -version = "0.8.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc" -dependencies = [ - "indexmap", - "ryu", - "serde", - "yaml-rust", -] - -[[package]] -name = "sha-1" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.10.3", -] - -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "sha2" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.10.3", -] - -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - -[[package]] -name = "smallvec" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" - -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] -name = "stacker" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4" -dependencies = [ - "cc", - "cfg-if 1.0.0", - "libc", - "psm", - "winapi", -] - -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "syn" -version = "1.0.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] - -[[package]] -name = "tempfile" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" -dependencies = [ - "cfg-if 1.0.0", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "termize" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1706be6b564323ce7092f5f7e6b118a14c8ef7ed0e69c8c5329c914a9f101295" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thiserror" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi", - "winapi", -] - -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "tracing" -version = "0.1.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" -dependencies = [ - "cfg-if 1.0.0", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "typenum" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" - -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - -[[package]] -name = "unic-char-property" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" -dependencies = [ - "unic-char-range", -] - -[[package]] -name = "unic-char-range" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" - -[[package]] -name = "unic-common" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" - -[[package]] -name = "unic-emoji-char" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b07221e68897210270a38bde4babb655869637af0f69407f96053a34f76494d" -dependencies = [ - "unic-char-property", - "unic-char-range", - "unic-ucd-version", -] - -[[package]] -name = "unic-ucd-bidi" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1d568b51222484e1f8209ce48caa6b430bf352962b877d592c29ab31fb53d8c" -dependencies = [ - "unic-char-property", - "unic-char-range", - "unic-ucd-version", -] - -[[package]] -name = "unic-ucd-category" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8d4591f5fcfe1bd4453baaf803c40e1b1e69ff8455c47620440b46efef91c0" -dependencies = [ - "matches", - "unic-char-property", - "unic-char-range", - "unic-ucd-version", -] - -[[package]] -name = "unic-ucd-version" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" -dependencies = [ - "unic-common", -] - -[[package]] -name = "unicode-casing" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "623f59e6af2a98bdafeb93fa277ac8e1e40440973001ca15cf4ae1541cd16d56" - -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] -name = "unicode-xid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" - -[[package]] -name = "unicode_names2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87d6678d7916394abad0d4b19df4d3802e1fd84abd7d701f39b75ee71b9e8cf1" - -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "walkdir" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" -dependencies = [ - "same-file", - "winapi", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "wasm-bindgen" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" -dependencies = [ - "cfg-if 1.0.0", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" - -[[package]] -name = "web-sys" -version = "0.3.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] From c2e10691ffc23a3763ed281e537ea64ce606735a Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sun, 9 Oct 2022 10:41:25 +0800 Subject: [PATCH 08/10] remove useless imports --- kclvm/sema/benches/my_benchmark.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/kclvm/sema/benches/my_benchmark.rs b/kclvm/sema/benches/my_benchmark.rs index aad5d526e..34534ed9b 100644 --- a/kclvm/sema/benches/my_benchmark.rs +++ b/kclvm/sema/benches/my_benchmark.rs @@ -1,22 +1,18 @@ -use std::rc::Rc; - -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; use kclvm_sema::ty::*; pub fn criterion_benchmark(c: &mut Criterion) { c.bench_function("sup", |b| { b.iter(|| { let types = vec![ - Rc::new(Type::int_lit(1)), - Rc::new(Type::INT), - Rc::new(Type::union(&[ - Rc::new(Type::STR), - Rc::new(Type::dict(Rc::new(Type::STR), Rc::new(Type::STR))), - ])), - Rc::new(Type::dict(Rc::new(Type::ANY), Rc::new(Type::ANY))), + Type::int_lit(1), + Type::INT, + Type::union(&[Type::STR, Type::dict(Type::STR, Type::STR)]), + Type::dict(Type::ANY, Type::ANY), ]; sup(&types); }) + }); } From 936af8dc80a195e1a1705313c0280a0ad67e408b Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sun, 9 Oct 2022 10:42:20 +0800 Subject: [PATCH 09/10] fmt --- kclvm/sema/benches/my_benchmark.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/kclvm/sema/benches/my_benchmark.rs b/kclvm/sema/benches/my_benchmark.rs index 34534ed9b..5b0bc6fbf 100644 --- a/kclvm/sema/benches/my_benchmark.rs +++ b/kclvm/sema/benches/my_benchmark.rs @@ -12,7 +12,6 @@ pub fn criterion_benchmark(c: &mut Criterion) { ]; sup(&types); }) - }); } From e2cdaae8b5836f2c3fd10249b78bd6aa323354c8 Mon Sep 17 00:00:00 2001 From: zong-zhe Date: Sun, 9 Oct 2022 11:42:10 +0800 Subject: [PATCH 10/10] fix failed test cases --- kclvm/query/src/lib.rs | 2 +- kclvm/query/src/tests.rs | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/kclvm/query/src/lib.rs b/kclvm/query/src/lib.rs index 937f74df4..7e7e024ac 100644 --- a/kclvm/query/src/lib.rs +++ b/kclvm/query/src/lib.rs @@ -42,7 +42,7 @@ use self::r#override::parse_override_spec; /// # Examples /// /// ```no_run -/// use kclvm_tools::query::override_file; +/// use kclvm_query::override_file; /// /// let result = override_file( /// "test.k", diff --git a/kclvm/query/src/tests.rs b/kclvm/query/src/tests.rs index f244536d0..5199a52db 100644 --- a/kclvm/query/src/tests.rs +++ b/kclvm/query/src/tests.rs @@ -1,8 +1,12 @@ +use std::path::PathBuf; + use super::{r#override::apply_override_on_module, *}; use kclvm_ast::ast; use kclvm_parser::parse_file; use pretty_assertions::assert_eq; +const CARGO_FILE_PATH: &str = env!("CARGO_MANIFEST_DIR"); + /// Test override_file result. #[test] fn test_override_file_simple() { @@ -11,9 +15,14 @@ fn test_override_file_simple() { ":config.image=\"image/image:v1\"".to_string(), ":config.data={id=1,value=\"override_value\"}".to_string(), ]; + + let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH); + cargo_file_path.push("src/test_data/simple.k"); + let abs_path = cargo_file_path.to_str().unwrap(); + let import_paths = vec![]; assert_eq!( - override_file("./src/query/test_data/simple.k", &specs, &import_paths).unwrap(), + override_file(abs_path, &specs, &import_paths).unwrap(), true ) } @@ -27,13 +36,13 @@ fn test_override_file_import_paths() { "pkg.pkg as alias_pkg1".to_string(), "pkg.pkg as alias_pkg2".to_string(), ]; + + let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH); + cargo_file_path.push("src/test_data/import_paths.k"); + let abs_path = cargo_file_path.to_str().unwrap(); + assert_eq!( - override_file( - "./src/query/test_data/import_paths.k", - &specs, - &import_paths - ) - .unwrap(), + override_file(abs_path, &specs, &import_paths).unwrap(), true ) } @@ -60,7 +69,12 @@ fn test_override_file_config() { .filter_map(Result::ok) .collect::>(); let import_paths = vec![]; - let mut module = parse_file("./src/query/test_data/config.k", None).unwrap(); + + let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH); + 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(); for o in &overrides { apply_override_on_module(&mut module, o, &import_paths).unwrap(); }