Skip to content

Commit

Permalink
feat: override union and insert config (kcl-lang#1525)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Jul 30, 2024
1 parent a589e15 commit 2ed0c55
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 98 deletions.
16 changes: 16 additions & 0 deletions kclvm/ast/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ pub fn get_key_path(key: &Option<ast::NodeRef<ast::Expr>>) -> String {
}
}

/// Get config key parts from the AST key node and convert string-based AST nodes including
/// `ast::Expr::Identifier` and `ast::Expr::StringLit` to strings.
#[inline]
pub fn get_key_parts(key: &Option<ast::NodeRef<ast::Expr>>) -> Vec<&str> {
match key {
Some(key) => match &key.node {
ast::Expr::Identifier(identifier) => {
identifier.names.iter().map(|v| v.node.as_str()).collect()
}
ast::Expr::StringLit(string_lit) => vec![string_lit.value.as_str()],
_ => vec![],
},
None => vec![],
}
}

/// Get assign target path from the AST key node and convert string-based AST nodes including
/// `ast::Expr::Identifier` and `ast::Expr::StringLit` to strings.
///
Expand Down
Loading

0 comments on commit 2ed0c55

Please sign in to comment.