parse.ha (1060B)
1 use spl::lexer::*; 2 3 export type unexpectedeof = !void; 4 export type unexpectedtoken = !void; 5 export type error = !(unexpectedeof | unexpectedtoken); 6 7 8 export type ty = struct { 9 basic: str 10 }; 11 12 // TODO add modifier option here to allow for const, static, etc 13 export type assign = struct { 14 name: str, 15 ty: ty, 16 value: expr 17 }; 18 19 export type reassign = struct { 20 name: str, 21 value: expr 22 }; 23 24 export type binop = struct { 25 ty: lexer::ttype, 26 // TODO replace int with litteral type that can store floats as well 27 left: (int | expr), 28 right: (int | expr), 29 }; 30 31 export type fcall = struct { 32 name: str, 33 args: []expr 34 }; 35 36 // TODO add modifier option here to allow for pub, priv, etc 37 export type fdec = struct { 38 name: str, 39 body: []node, 40 args: []assign 41 }; 42 43 // functions as right hand side expression 44 // fcall is for fcalls 45 // binop is for maths 46 // expr is for bracketed expressions 47 export type expr = (*(fcall | binop | expr), ty); 48 // functions as left hand side expression 49 export type node = (reassign | assign | fcall | fdec); 50 51 export fn parse(l: *lexer) node = { 52 53 };