rule wrapped_expr(guid2) = ScopeEnter(e, guid3) <- guid3:guid2 e:expr; rule expr { group statement { GrammarDefine(b, guid, "_", g) <- guid:#guid "grammar" "{" g:grammar(wrapped_expr(guid)) "}" b:#adapt(g, expr); GrammarDefine(b, guid, n, g) <- guid:#guid "grammar" n:identifier "{" g:grammar(wrapped_expr(guid)) "}" b:expr; b <- "adapt" n:identifier ";" b:#adapt(n, expr); Let(n, v, b) <- "let" n:identifier "=" v:#next ";" b:#this; // todo: `t:#next` should be replaced by `t:expr.fndestruct` when the language supports it Let(n, TypeAssert(v, t), b) <- "let" n:identifier ":" t:#next "=" v:#next ";" b:#this; } group fnconstruct { fnconstruct(#this, #next); } group fntype { FnType(n, at, bt) <- "(" n:identifier ":" at:#this ")" "->" bt:#this; FnType("_", at, bt) <- at:#next "->" bt:#this; } group assert { TypeAssert(e, typ) <- e:#next ":" typ:#next; } group fndestruct { FnDestruct(f, a) <- f:#this " " a:#next; } group base { t <- "(" t:expr ")"; Type() <- "Type"; identifier; } } rule fnconstruct(this, next) { FnConstruct(n, Let("_", TypeAssert(n, t), r)) <- "(" n:identifier ":" t:next ")" r:#this; FnConstruct(n, r) <- n:identifier r:#this; FnConstruct(n, Let("_", TypeAssert(n, t), r)) <- "(" n:identifier ":" t:next ")" "=>" r:this; FnConstruct(n, r) <- n:identifier "=>" r:this; } rule layout { [' ' | '\n']; "//" [^'\n']* "\n"; } rule keyword { "Type"; "grammar"; } rule identifier { #[error("Identifier")] #[disable_layout] #[disable_recovery] n <- #neg(keyword #neg(['a'-'z' | 'A'-'Z' | '0'-'9' | '_' ])) n:#str([ 'a'-'z' | 'A'-'Z' | '_' ] ['a'-'z' | 'A'-'Z' | '0'-'9' | '_' ]*); }