Skip to content

Commit

Permalink
feat: impl query tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peefy committed Jun 7, 2022
1 parent 055aca3 commit 810627d
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 163 deletions.
12 changes: 3 additions & 9 deletions kclvm/ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,23 @@ impl TryInto<Node<SchemaExpr>> for Node<Expr> {
/// AST node type T
pub type NodeRef<T> = Box<Node<T>>;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ParseMode {
Null,
ParseComments,
}

/// KCL command line argument spec, e.g. `kcl main.k -D name=value`
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct CmdArgSpec {
pub name: String,
pub value: String,
}

/// KCL command line override spec, e.g. `kcl main.k -O pkgpath:path.to.field=field_value`
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct OverrideSpec {
pub pkgpath: String,
pub field_path: String,
pub field_value: String,
pub action: OverrideAction,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum OverrideAction {
CreateOrUpdate,
Delete,
Expand Down
10 changes: 5 additions & 5 deletions kclvm/tools/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! This package is mainly the implementation of the KCL query tool, mainly including
//! KCL code modification `override` and other implementations. We can call the `override_file`
//! function to modify the file. The main principle is to parse the AST according to the
//! input file name, and according to the ast: :OverrideSpec transforms the nodes in the
//! This package is mainly the implementation of the KCL query tool, mainly including
//! KCL code modification `override` and other implementations. We can call the `override_file`
//! function to modify the file. The main principle is to parse the AST according to the
//! input file name, and according to the ast::OverrideSpec transforms the nodes in the
//! AST, recursively modifying or deleting the values of the nodes in the AST.
pub mod r#override;

#[cfg(test)]
mod tests;

pub use r#override::{apply_overrides, override_file, spec_str_to_override};
pub use r#override::{apply_overrides, override_file, parse_override_spec, split_field_path};
Loading

0 comments on commit 810627d

Please sign in to comment.