AIDL parser for Rust
Parse and validate AIDL files (or contents).
For each AIDL file, the parser will return:
- the AST (Abstract Syntax Tree)
- diagnostics (errors and warnings)
The [traverse] module contains various helper functions to extract informations from the AST.
Usage
Add to Cargo.toml
:
[]
= "0.5.0"
Create parser, analyze results:
use ;
// Parse AIDL contents
let mut parser = new;
parser.add_content;
parser.add_content;
let results = parser.validate;
// Display results
for in &results
// Traverse AST
let ast1 = results.ast.as_ref.expect;
walk_symbols;
AIDL language support
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 while 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:
- grammar (lalrpop): https://github.com/bwalter/rust-aidl-parser/blob/main/src/aidl.lalrpop
- unit-tests for grammar: https://github.com/bwalter/rust-aidl-parser/blob/main/src/rules.rs
- validation incl. unit-tests: https://github.com/bwalter/rust-aidl-parser/blob/main/src/validation.rs
Link to AOSP AIDL implementation: https://android.googlesource.com/platform/system/tools/aidl/+/refs/heads/master
TODO
- Document how to display diagnostics (e.g. with CodeSpan)
- Annotation attached to primitive type
- union (Android 12)
- nested types (Android T)
- Parcelable declaration(= forward declaration), with optional annotations
- Allow annotations for list/map parameters?
- Android types: ParcelableHolder, IBinder, FileDescriptor, ParcelFileDescriptor,
- Ignore Java-like imports: "android.os.IInterface", "android.os.IBinder", "android.os.Parcelable", "android.os.Parcel", "android.content.Context", "java.lang.String", "java.lang.CharSequence" (but add a warning)
- Const values with arithmetic (e.g.: const int HELLO = 3 * 4)
- Allow array of parcelable/interface? and check for enums in List or Map
- validate:
- file name matching item name
- ParcelableHolder cannot (currently) be given as an argument?
- ParcelableFileDescriptor cannot be out (because it is not default-constructible)
License
This project is licensed under the MIT license.