feat: more ast elements and some sample syntax

This commit is contained in:
rvcas 2022-08-10 15:50:19 -04:00
parent 5a9ec708ee
commit 208f2e80ea
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
2 changed files with 110 additions and 2 deletions

View File

@ -1,5 +1,47 @@
pub struct Module {} pub struct Module {
pub name: Vec<String>,
pub docs: Vec<String>,
pub is_script: bool,
pub is_lib: bool,
pub is_policy: bool,
}
pub enum Decl {} pub enum Definition {
Fn {
arguments: Vec<String>,
body: Expr,
doc: Option<String>,
name: String,
public: bool,
return_annotation: Option<()>,
return_type: (),
},
TypeAlias {
alias: String,
annotation: (),
doc: Option<String>,
parameters: Vec<String>,
public: bool,
tipo: (),
},
DataType {
constructors: Vec<()>,
doc: Option<String>,
name: String,
opaque: bool,
parameters: Vec<String>,
public: bool,
typed_parameters: Vec<()>,
},
Use {
module: Vec<String>,
as_name: Option<String>,
// unqualified: Vec<UnqualifiedImport>,
// package: PackageName,
},
}
pub enum Expr {} pub enum Expr {}

66
syntax.txt Normal file
View File

@ -0,0 +1,66 @@
// imports
use std/address.Address as A // alias
use std/list.{map, foldl} // access module members in one import
// `///` used for document generation
// Records (single constructor `data` type)
pub type Datum {
signer: Address,
}
// above is suger for
pub type Datum {
Datum { signer: Address },
}
// type aliases
type A = Address
// multiple constructors and a `generic`
pub type Redeemer(a) {
// records wrapped in parens
Buy(Address, a),
// records wrapped in curlies
Sell { address: Address, some_thing: a },
}
pub fn main(datum: Datum, redeemer: Redeemer, ctx: ScriptContext) {
[1, 2, 3]
|> list.map(fn(x) -> x + 1)
}
// named and anonymous functions
fn(x) -> x + 1
fn add_one(x) -> x + 1
fn(x: Int) -> x + 1
fn add_one(label x: Int) -> x + 1
fn(x: Int) {
x + 1
}
fn(x: Int) -> Int {
x + 1
}
fn add_one(x: Int) -> Int {
x + 1
}
// can be curried
fn add(a, b) {
a + 1
}
let add_one = add(1)
// matching
when redeemer is {
Buyer(address, thing) -> do_stuff(),
Seller { address, some_thing } -> do_seller_stuff(),
}