Skip to content

Commit

Permalink
feat: more ast elements and some sample syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Aug 10, 2022
1 parent 1ba348e commit 25d6345
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 2 deletions.
46 changes: 44 additions & 2 deletions crates/lang/src/ast.rs
@@ -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 {}
66 changes: 66 additions & 0 deletions syntax.txt
@@ -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(),
}

0 comments on commit 25d6345

Please sign in to comment.