Crates.io | aidl-parser |
lib.rs | aidl-parser |
version | 0.12.3 |
source | src |
created_at | 2021-12-22 14:42:00.471562 |
updated_at | 2023-01-29 20:37:38.12153 |
description | Parse AIDL files, crate AST and diagnostics |
homepage | |
repository | https://github.com/bwalter/rust-aidl-parser |
max_upload_size | |
id | 501647 |
size | 189,153 |
Parse and validate AIDL files (or contents).
For each AIDL file, the parser will return:
The [traverse] module contains various helper functions to extract informations from the AST.
Add to Cargo.toml
:
[dependencies]
aidl-parser = "0.12.3"
Create parser, analyze results:
use aidl_parser::Parser;
use aidl_parser::traverse::{self, SymbolFilter};
// Parse AIDL contents
let mut parser = Parser::new();
parser.add_content("id1", "package test.pkg; interface MyInterface { void hello(String); }");
parser.add_content("id2", "package test.pkg; parcelable Parcelable { int myField; }");
let results = parser.validate();
// Display results
for (id, res) in &results {
println!("{}: AST = {:#?}", id, res.ast);
println!("{}: Diagnostics = {:#?}", id, res.diagnostics);
}
// Traverse AST
let ast1 = results["id1"].ast.as_ref().expect("missing AST");
traverse::walk_symbols(ast1, traverse::SymbolFilter::All, |s| println!("- Symbol: {:#?}", s));
// Filter symbols with closure
let symbols = traverse::filter_symbols(ast1, SymbolFilter::ItemsAndItemElements, |s| s.get_name().unwrap_or_default().contains("el"));
println!("Found symbols containing 'el': {:#?}", symbols);
// Find symbol with closure
if let Some(symbol) = traverse::find_symbol(ast1, SymbolFilter::All, |s| s.get_name().as_deref() == Some("myField")) {
println!("Found myField: {:#?}", symbol);
}
// Find symbol at given position
if let Some(symbol) = traverse::find_symbol_at_line_col(ast1, SymbolFilter::All, (0, 3)) {
println!("Found myField: {:#?}", symbol);
}
It is currently a best effort to provide good diagnostic and navigation based on the official AIDL documentation and AOSP implementation.
It is planned to gradually improve language support to cover all the AIDL functionalities. If you encounter any issue or missing functionality which is not mentioned in the README, it is considered as a bug (please submit an issue or a pull request!).
To get more insight on the current grammar and validation, please refer to:
Link to AOSP AIDL implementation: https://android.googlesource.com/platform/system/tools/aidl/+/refs/heads/master
This project is licensed under the MIT license.