Struct aidl_parser::parser::Parser

source ·
pub struct Parser<ID>where
    ID: Eq + Hash + Clone + Debug,
{ /* private fields */ }
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§

Create a new, empty parser

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.

Remove the file with the given key

Validate the results of all files previously added to the parser and return the collected results (AST + diagnostics)

Add a file to the parser and use its path as key.

If a file with the same path already exists, the old file will be replaced.

Trait Implementations§

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.