Struct aidl_parser::parser::Parser
source · Expand description
A parser instance which receives the individual AIDL files via Parser::add_content() or Parser::add_file(). Once all the files have been added, call Parser::parser() to trigger the validation and access the results.
The ID of the files added to the parser are used to uniquely identify the results returned by the parser. It can be any value used as a key (e.g. number of string) or the location of the content (e.g. PathBuf or Uri).
The content added to the parser can be removed or replaced before or after the parsing.
Example:
use aidl_parser::{Parser, ParseFileResult};
let mut parser = Parser::new();
// Add files via ID + content
parser.add_content("id1", "<content of AIDL file #1>");
parser.add_content("id2", "<content of AIDL file #2>");
parser.add_content("id3", "<content of AIDL file #3>");
// Parse and get results
let results = parser.validate();
assert_eq!(results.len(), 3);
assert!(results.contains_key("id1"));
assert!(results.contains_key("id2"));
assert!(results.contains_key("id3"));
// Add/replace/remove files
parser.add_content("id2", "<updated content of AIDL file #2>");
parser.add_content("id4", "<content of AIDL file #4>");
parser.add_content("id5", "<content of AIDL file #5>");
parser.remove_content("id3");
// Parse again and get updated results
let results = parser.validate();
assert_eq!(results.len(), 4);
assert!(results.contains_key("id1"));
assert!(results.contains_key("id2"));
assert!(!results.contains_key("id3")); // removed
assert!(results.contains_key("id4"));
assert!(results.contains_key("id5"));
Implementations§
source§impl<ID> Parser<ID>where
ID: Eq + Hash + Clone + Debug,
impl<ID> Parser<ID>where
ID: Eq + Hash + Clone + Debug,
sourcepub fn add_content(&mut self, id: ID, content: &str)
pub fn add_content(&mut self, id: ID, content: &str)
Add a file content and its key to the parser.
This will parse the individual content and store the result internally.
Note: if a content with the same id already exists, the old content will be replaced.
sourcepub fn remove_content(&mut self, id: ID)
pub fn remove_content(&mut self, id: ID)
Remove the file with the given key
sourcepub fn validate(&self) -> HashMap<ID, ParseFileResult<ID>>
pub fn validate(&self) -> HashMap<ID, ParseFileResult<ID>>
Validate the results of all files previously added to the parser and return the collected results (AST + diagnostics)