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 May 30, 2022
1 parent c3362b8 commit 055aca3
Show file tree
Hide file tree
Showing 14 changed files with 687 additions and 48 deletions.
8 changes: 8 additions & 0 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions kclvm/ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub struct CmdArgSpec {

/// KCL command line override spec, e.g. `kcl main.k -O pkgpath:path.to.field=field_value`
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CmdOverrideSpec {
pub struct OverrideSpec {
pub pkgpath: String,
pub field_path: String,
pub field_value: String,
Expand All @@ -201,7 +201,7 @@ pub struct Program {
pub main: String,
pub pkgs: HashMap<String, Vec<Module>>,
pub cmd_args: Vec<CmdArgSpec>,
pub cmd_overrides: Vec<CmdOverrideSpec>,
pub cmd_overrides: Vec<OverrideSpec>,
}

impl Program {
Expand Down
2 changes: 1 addition & 1 deletion kclvm/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub struct LoadProgramOptions {
pub k_code_list: Vec<String>,

pub cmd_args: Vec<ast::CmdArgSpec>,
pub cmd_overrides: Vec<ast::CmdOverrideSpec>,
pub cmd_overrides: Vec<ast::OverrideSpec>,

pub _mode: Option<ParseMode>,
pub _load_packages: bool,
Expand Down
2 changes: 1 addition & 1 deletion kclvm/runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct ExecProgramArgs {
pub k_code_list: Vec<String>,

pub args: Vec<ast::CmdArgSpec>,
pub overrides: Vec<ast::CmdOverrideSpec>,
pub overrides: Vec<ast::OverrideSpec>,

pub disable_yaml_result: bool,
pub print_override_ast: bool,
Expand Down
4 changes: 3 additions & 1 deletion kclvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ pub fn kclvm_cli_run_unsafe(args: *const i8, plugin_agent: *const i8) -> Result<

// load ast
let mut program = load_program(&files, Some(opts))?;
apply_overrides(&mut program, &args.overrides, &[]);
if let Err(msg) = apply_overrides(&mut program, &args.overrides, &[]) {
return Err(msg.to_string());
}
let scope = resolve_program(&mut program);
scope.check_scope_diagnostics();
// gen bc or ll file
Expand Down
28 changes: 28 additions & 0 deletions kclvm/tools/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions kclvm/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ edition = "2021"
[dependencies]
indexmap = "1.0"
fancy-regex = "0.7.1"
walkdir = "2"
anyhow = "1.0"

kclvm-ast = {path = "../ast", version = "0.1.0"}
kclvm-error = {path = "../error", version = "0.1.0"}
Expand Down
10 changes: 9 additions & 1 deletion kclvm/tools/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +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
//! AST, recursively modifying or deleting the values of the nodes in the AST.
pub mod r#override;

pub use r#override::apply_overrides;
#[cfg(test)]
mod tests;

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

0 comments on commit 055aca3

Please sign in to comment.