start <- value:defs wsnl %eof env <- LBRACE value:defs RBRACE defs <- wsnl {{ @matches[:value] = Env.new }} (t:token COLON e:expr SEP {{ @matches[:value][@matches[:t]] = @matches[:e] }} / e:expr SEP {{ @matches[:value].code << @matches[:e] }} )* expr <- lamexpr lamexpr <- a:arg ARROW e:lamexpr {{ @matches[:value] = Lam.new(@matches[:a], @matches[:e]) }} / opexpr opexpr <- value:selexpr (o:OP b:selexpr {{ @matches[:value] = App.new(App.new(@matches[:o], @matches[:value]), @matches[:b]) }})* selexpr <- value:seltarget (s:raw_selector {{ @matches[:value] = App.new(@matches[:s], @matches[:value]) }})+ / value:appexpr appexpr <- value:primexpr (b:primexpr {{ @matches[:value] = App.new(@matches[:value], @matches[:b]) }})* primexpr <- value:literal / compound / var / LPAREN value:expr RPAREN seltarget <- raw_var arg <- value:var literal <- int / selector / string compound <- env / tuple / list ws <- [ \t]* "\\\n"? / comment wsnl <- ([ \t\n\r\f] / comment)* comment <- !selector "#" (![\r\n] . )* [\r\n] LBRACE <- "{" wsnl RBRACE <- "}" ws LPAREN <- "(" wsnl RPAREN <- ")" ws LBRACK <- "[" wsnl RBRACK <- "]" ws COLON <- ":" wsnl COMMA <- "," wsnl ARROW <- "->" wsnl SEP <- ";" wsnl / ws [\r\n] wsnl / !(!RBRACE) var <- value:raw_var ws raw_var <- i:ID {{ @matches[:value] = Var.new(@matches[:i]) }} selector <- value:raw_selector ws raw_selector <- "#" t:token {{ @matches[:value] = Sel.new(@matches[:t]) }} token <- TOKEN TOKEN <- ([a-zA-Z0-9_]+ ['!?]*) ID <- ([a-zA-Z_] [a-zA-Z0-9_]* ['!?]*) # add \ / OP <- o:([!$%&*+<=>?^~|-]+) ws {{ @matches[:value] = Sel.new(@matches[:o]) }} / "`" t:token "`" ws {{ @matches[:value] = Sel.new(@matches[:t]) }} int <- i:("-"? [0-9]+) ws {{ @matches[:value] = Int.new(@matches[:i].to_i) }} string <- "\"" value:((!"\"" .)*) "\"" ws tuple <- LPAREN RPAREN {{ @matches[:value] = [] }} / LPAREN e:expr {{ @matches[:value] = [@matches[:e]] }} (COMMA e:expr {{ @matches[:value] << @matches[:e] }} )+ RPAREN list <- LBRACK RBRACK {{ @matches[:value] = [] }} / LBRACK e:expr {{ @matches[:value] = [@matches[:e]] }} (COMMA e:expr {{ @matches[:value] << @matches[:e] }} )* RBRACK