ink! intermediate representations (IRs) and abstractions for ink! analyzer.
This library implements types and abstractions for all ink! entities (e.g contracts, storage, events, topics, impls, constructors, messages, selectors, tests, trait definitions, chain extensions, storage items e.t.c).
It uses rust-analyzer's raapsyntax crate for generating the syntax tree of the ink! smart contract code that it then converts into ink! entity intermediate representations and abstractions.
It uses raapsyntax instead of other Rust parsing and syntax tree libraries because ink! analyzer has similar design goals to rust-analyzer. The most important being that parsing should be: - resilient (even if the input is invalid, parser tries to see as much syntax tree fragments in the input as it can). - lossless (even if the input is invalid, the tree produced by the parser represents it exactly).
It's the main dependency for the semantic analyzer crate.
Run the following Cargo command in your project directory
shell
cargo add ink-analyzer-ir
Generate an IR of ink! smart contract code.
```rust use inkanalyzerir::InkFile;
fn generateir() { let file = InkFile::parse(r#" #[ink::contract] mod mycontract {
#[ink(storage)]
pub struct MyContract {
value: bool,
}
#[ink(event)]
pub struct MyEvent {
#[ink(topic)]
value: bool,
}
// --snip--
}
"#);
dbg!(&file);
let contracts = file.contracts();
dbg!(&contracts);
if let Some(contract) = contracts.first() {
let events = contract.events();
dbg!(&events);
}
} ```
https://docs.rs/ink-analyzer-ir/latest/inkanalyzerir/
Or you can access documentation locally by running the following command from the project root
shell
cargo doc -p ink-analyzer-ir --open
You can run unit tests for all the core functionality by running the following command from the project root
shell
cargo test -p ink-analyzer-ir
Licensed under either MIT or Apache-2.0 license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.