-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: xiarui.xr <xiarui1994@gmail.com>
- Loading branch information
1 parent
3f840da
commit 3a9d5b5
Showing
12 changed files
with
404 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use super::util::{invalid_symbol_selector_spec_error, split_field_path}; | ||
use anyhow::Result; | ||
use kclvm_ast::ast; | ||
|
||
/// Parse symbol selector string to symbol selector spec | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use kclvm_query::selector::parse_symbol_selector_spec; | ||
/// | ||
/// if let Ok(spec) = parse_symbol_selector_spec("", "alice.age") { | ||
/// assert_eq!(spec.pkgpath, "".to_string()); | ||
/// assert_eq!(spec.field_path, "alice.age".to_string()); | ||
/// } | ||
/// ``` | ||
pub fn parse_symbol_selector_spec( | ||
pkg_root: &str, | ||
symbol_path: &str, | ||
) -> Result<ast::SymbolSelectorSpec> { | ||
if let Ok((pkgpath, field_path)) = split_field_path(symbol_path) { | ||
Ok(ast::SymbolSelectorSpec { | ||
pkg_root: pkg_root.to_string(), | ||
pkgpath, | ||
field_path, | ||
}) | ||
} else { | ||
Err(invalid_symbol_selector_spec_error(symbol_path)) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_symbol_path_selector() { | ||
let spec = parse_symbol_selector_spec("", "pkg_name:alice.age").unwrap(); | ||
assert_eq!(spec.pkgpath, "pkg_name".to_string()); | ||
assert_eq!(spec.field_path, "alice.age".to_string()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.