From 83ddc2f1a6a2f05efba92eb9fb453032a2fb987d Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sun, 31 Oct 2021 20:59:45 -0400 Subject: [AST] Add initial operator and module cases + Modules at least mostly parse properly. ~ I'm mostly just working tword a minimum viable program at this point. --- src/tparse/tree-statement.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/tparse/tree-statement.go b/src/tparse/tree-statement.go index 277cd95..546c833 100644 --- a/src/tparse/tree-statement.go +++ b/src/tparse/tree-statement.go @@ -60,6 +60,16 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) { errOut("Unexpected keyword, the block has already been given a name or keyword.", t) } switch t.Data { + case "operator": + name = true + if (*tokens)[tok+1].Type != AUGMENT { + errOut("You must supply an operator to overload.", t) + } else if (*tokens)[tok+1].Data == "`" || (*tokens)[tok+1].Data == "~" { + errOut("You may not overload the following operators: '~', '`'.", t) + } + tmp.Data = (*tokens)[tok+1] + def.Sub = append(def.Sub, tmp) + tok += 2 case "else": name = true sparse = true @@ -76,6 +86,17 @@ func parseBlock(tokens *[]Token, tok, max int) (Node, int) { case "export", "inline", "raw", "override": tmp.Data = t def.Sub = append(def.Sub, tmp) + case "module": + if (*tokens)[tok+1].Type != DEFWORD && !name { + errOut("You must provide a name for a module.", t) + } else if !name { + tmp.Sub = append(tmp.Sub, Node{(*tokens)[tok+1], false, []Node{}}) + tok++ + } + tmp.Data = t + def.Sub = append(def.Sub, tmp) + tok++ + goto BREAK default: errOut("Unexpected keyword in block definition.", t) } -- cgit v1.2.3