Sean Young 53172f3ad3 v0.3.0 Venice (#1319) %!s(int64=2) %!d(string=hai) anos
..
src 1a47714956 `this` is not a keyword (#1317) %!s(int64=2) %!d(string=hai) anos
Cargo.toml 53172f3ad3 v0.3.0 Venice (#1319) %!s(int64=2) %!d(string=hai) anos
README.md a1e7ccade9 Use solc v0.8.20 testdata (#1310) %!s(int64=2) %!d(string=hai) anos
build.rs f2d5e6782a Add SPDX headers (#951) %!s(int64=3) %!d(string=hai) anos

README.md

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

This parser is compatible with Ethereum Solidity v0.8.20.

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);
                    }
                    _ => (),
                }
            }
        }
        _ => (),
    }
}