Skip to content

Scilla Parser


rs-scilla-parser

rs-scilla-parser is a Rust-based library to parse scilla contracts.

The current version of the library parses a given contract and extract:

  • The contract name
  • Initial parameters needed to deploy the contract
  • The contract's fields
  • The contract's transitions

Source Code

The Github repository can be found at Zilliqa/rs-scilla-parser

Documentation

The official documentation can be found at docs.rs

Installation

Run the following command to add rs-scilla-parser to your Rust based project:

cargo add rs-scilla-parser

Examples

To parse HelloWorld.scilla contract:

    use scilla_parser::{Contract, Field, FieldList, Transition, TransitionList, Type};

    let contract_path = PathBuf::from("tests/contracts/HelloWorld.scilla");
    let contract = Contract::parse(&contract_path).unwrap();

    assert_eq!(
        contract,
        Contract {
            name: "HelloWorld".to_string(),
            init_params: FieldList(vec![Field::new("owner", Type::ByStr(20))]),
            fields: FieldList(vec![Field::new("welcome_msg", Type::String)]),
            transitions: TransitionList(vec![
                Transition::new("setHello", FieldList(vec![Field::new("msg", Type::String)])),
                Transition::new_without_param("getHello")
            ])
        }
    );

For more examples, take a look at the project's tests.