21 releases

0.3.3 Oct 24, 2023
0.3.1 Jun 30, 2023
0.2.3 Mar 3, 2023
0.2.0 Dec 2, 2022
0.1.0 Dec 31, 2021

#1168 in Magic Beans

Download history 39997/week @ 2023-12-05 38052/week @ 2023-12-12 32105/week @ 2023-12-19 19389/week @ 2023-12-26 32122/week @ 2024-01-02 40277/week @ 2024-01-09 42491/week @ 2024-01-16 43337/week @ 2024-01-23 53128/week @ 2024-01-30 43664/week @ 2024-02-06 40253/week @ 2024-02-13 37585/week @ 2024-02-20 35967/week @ 2024-02-27 34080/week @ 2024-03-05 37162/week @ 2024-03-12 30852/week @ 2024-03-19

145,240 downloads per month
Used in 42 crates (10 directly)

Apache-2.0

310KB
7K SLoC

Hyperledger Solang Solidity parser

This crate is part of Hyperledger Solang. It contains the parser for Solidity, including the dialects used by Solang for Solana and Polkadot.

This parser is compatible with Ethereum Solidity v0.8.21.

solang-parser is still 0.*.*, so breaking changes may occur at any time. If you must depend on solang-parser, we recommend pinning to a specific version, i.e., =0.y.z.

use solang_parser::{pt::{SourceUnitPart, ContractPart}, parse};

let (tree, comments) = parse(r#"
contract flipper {
    bool private value;

    /// Constructor that initializes the `bool` value to the given `init_value`.
    constructor(bool initvalue) {
        value = initvalue;
    }

    /// A message that can be called on instantiated contracts.
    /// This one flips the value of the stored `bool` from `true`
    /// to `false` and vice versa.
    function flip() public {
        value = !value;
    }

    /// Simply returns the current value of our `bool`.
    function get() public view returns (bool) {
        return value;
    }
}
"#, 0).unwrap();

for part in &tree.0 {
    match part {
        SourceUnitPart::ContractDefinition(def) => {
            println!("found contract {:?}", def.name);
            for part in &def.parts {
                match part {
                    ContractPart::VariableDefinition(def) => {
                        println!("variable {:?}", def.name);
                    }
                    ContractPart::FunctionDefinition(def) => {
                        println!("function {:?}", def.name);
                    }
                    _ => (),
                }
            }
        }
        _ => (),
    }
}

Dependencies

~1.2–3.5MB
~56K SLoC