Skip to content

Commit 6b2dfb8

Browse files
committed
Update readme
1 parent 50d3344 commit 6b2dfb8

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "scilla-parser"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
edition = "2021"
55
description = "Scilla smart contract parser written in Rust"
66
license = "MIT"

README.md

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,79 @@ cargo add scilla_parser
1515
This will add the scilla_parser dependency to Cargo.toml as specified in the installation instructions above.
1616

1717
# Usage
18+
This library parses the s-expression of a contract. There are two options:
19+
1. Use `Contract::from_path` and pass a contract path. This function will automatically call `scilla-fmt` through docker to generate the s-expression needed to parsed the contract.
20+
2. Parse a string (slice) to a contract. The string is supposed to have the s-expression of a contract.
21+
1822
## To parse a Scilla file:
1923
```rust
2024
use std::{error::Error, path::PathBuf};
2125
use scilla_parser::{Contract, Field, FieldList, Transition, TransitionList, Type};
2226

23-
let contract_path = PathBuf::from("tests/contracts/chainid.scilla");
27+
let contract_path = PathBuf::from("tests/contracts/SendZil.scilla");
2428
let contract = Contract::from_path(&contract_path).unwrap();
2529

2630
assert_eq!(
2731
contract,
2832
Contract {
29-
name: "ChainId".to_string(),
30-
fields: FieldList::default(),
31-
init_params: FieldList::default(),
32-
transitions: TransitionList(vec![Transition::new(
33-
"EventChainID",
34-
FieldList::default()
35-
)])
33+
name: "SendZil".to_string(),
34+
init_params: FieldList(vec![]),
35+
fields: FieldList(vec![
36+
Field::new("test_field", Type::Uint256),
37+
Field::new("bool", Type::Bool),
38+
Field::new("empty_bool", Type::Option(Box::new(Type::Bool))),
39+
Field::new("some_int", Type::Option(Box::new(Type::Int32))),
40+
Field::new(
41+
"pair",
42+
Type::Pair(Box::new(Type::String), Box::new(Type::Uint32))
43+
),
44+
Field::new("list", Type::List(Box::new(Type::Int32))),
45+
]),
46+
transitions: TransitionList(vec![
47+
Transition::new_without_param("acceptZil"),
48+
Transition::new(
49+
"updateTestField",
50+
FieldList(vec![Field::new("val", Type::Uint256)])
51+
),
52+
Transition::new_without_param("dontAcceptZil"),
53+
Transition::new(
54+
"fundUserWithTag",
55+
FieldList(vec![
56+
Field::new("user", Type::ByStr(20)),
57+
Field::new("amount", Type::Uint128)
58+
])
59+
),
60+
Transition::new(
61+
"fundUser",
62+
FieldList(vec![
63+
Field::new("user", Type::ByStr(20)),
64+
Field::new("amount", Type::Uint128)
65+
])
66+
),
67+
Transition::new(
68+
"fundContract",
69+
FieldList(vec![
70+
Field::new("contract_address", Type::ByStr(20)),
71+
Field::new("amount", Type::Uint128)
72+
])
73+
),
74+
Transition::new(
75+
"callOtherContract",
76+
FieldList(vec![
77+
Field::new("contract_address", Type::ByStr(20)),
78+
Field::new("tag", Type::String),
79+
Field::new("value", Type::Uint256)
80+
])
81+
),
82+
])
3683
}
3784
);
3885
```
3986

40-
## To parse a string containing a scilla contract:
87+
## To parse a string containing the s-expression of a scilla contract:
4188
```rust
42-
let scilla_code: &str = "<A SCILLA CONTRACT>";
43-
let contract: Contract = scilla_code.parse().unwrap();
89+
let sexp: &str = "s-expression of the contract";
90+
let contract: Contract = sexp.parse().unwrap();
4491
```
4592

4693
For more examples, take a look at the [tests](./tests/test_parser.rs).

0 commit comments

Comments
 (0)