22 releases

0.3.4 Jun 5, 2024
0.3.3 Oct 24, 2023
0.3.2 Aug 24, 2023
0.3.1 Jun 30, 2023
0.1.0 Dec 31, 2021

#12 in #solidity

Download history 38745/week @ 2024-06-21 32952/week @ 2024-06-28 31610/week @ 2024-07-05 34447/week @ 2024-07-12 36608/week @ 2024-07-19 37711/week @ 2024-07-26 36671/week @ 2024-08-02 41064/week @ 2024-08-09 39214/week @ 2024-08-16 36860/week @ 2024-08-23 37235/week @ 2024-08-30 39453/week @ 2024-09-06 38188/week @ 2024-09-13 37614/week @ 2024-09-20 38974/week @ 2024-09-27 38490/week @ 2024-10-04

159,873 downloads per month
Used in 55 crates (14 directly)

Apache-2.0

370KB
8K SLoC

Rust 7.5K SLoC // 0.0% comments LALRPOP 1K SLoC // 0.0% comments

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.22.

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.1–3.5MB
~57K SLoC