diff options
author | Kyle Gunger <corechg@gmail.com> | 2020-11-17 02:52:37 -0500 |
---|---|---|
committer | Kyle Gunger <corechg@gmail.com> | 2020-11-17 02:52:37 -0500 |
commit | a0435f61add1daa2cb645d05aafc694044e5efa8 (patch) | |
tree | 1c811880c591c7259f78089a7f4df00784b34c6d | |
parent | 9909931882ba57ae674130efccb8f82c603c24ae (diff) |
Write value list parser
-rw-r--r-- | src/tparse/tree.go | 43 | ||||
-rw-r--r-- | src/tparse/type.go | 7 |
2 files changed, 40 insertions, 10 deletions
diff --git a/src/tparse/tree.go b/src/tparse/tree.go index c0da5c2..ced25d7 100644 --- a/src/tparse/tree.go +++ b/src/tparse/tree.go @@ -23,13 +23,42 @@ import "fmt" func errOut(message string, token Token) { fmt.Println(message) fmt.Println(token) - panic(token) + panic("AST Error") } -// Parses a list of things as parameters -func parseList(tokens *[]Token, tok, max int, param bool) (Node, int) { +// Parse a list of values +func parseValueList(tokens *[]Token, tok, max int) (Node, int) { out := Node{} - out.Data = Token{Type: 10, Data: "list"} + out.Data = Token{Type: 9, Data: "list"} + + currentType := Node{} + currentType.Data = Token{Data: "undefined"} + + tok++ + + for ; tok < max; tok++ { + var tmp Node + tmp, tok = parseValue(tokens, tok, max) + makeParent(&out, tmp) + + t := (*tokens)[tok] + + switch t.Data { + case ")", "]", "}": + return out, tok + case ",": + default: + errOut("Error: unexpected token when parsing list, expected ',' or end of list", t) + } + } + + return out, tok +} + +// Parses a list of things +func parseDefList(tokens *[]Token, tok, max int) (Node, int) { + out := Node{} + out.Data = Token{Type: 9, Data: "list"} currentType := Node{} currentType.Data = Token{Data: "undefined"} @@ -39,8 +68,7 @@ func parseList(tokens *[]Token, tok, max int, param bool) (Node, int) { t1 := (*tokens)[tok+1] switch t1.Data { - case ")", "]", "}": - case ",": + case ")", "]", "}", ",": default: currentType, tok = parseType(tokens, tok, max, true) t0 = (*tokens)[tok] @@ -48,6 +76,7 @@ func parseList(tokens *[]Token, tok, max int, param bool) (Node, int) { } switch t0.Type { + case DEFWORD: var tmp Node if currentType.Data.Data == "undefined" { @@ -63,7 +92,7 @@ func parseList(tokens *[]Token, tok, max int, param bool) (Node, int) { makeParent(&out, typ) default: - errOut("Error: unexpected token when parsing list, expected user-defined variable", t0) + errOut("Error: unexpected token when parsing list, expected user-defined variable or ", t0) } switch t1.Data { diff --git a/src/tparse/type.go b/src/tparse/type.go index b66668c..ea8e6eb 100644 --- a/src/tparse/type.go +++ b/src/tparse/type.go @@ -52,7 +52,7 @@ var PREWORDS = []string{ "align", "if", "else", - "mark", + //"mark", } func checkPreWord(s string) int { @@ -116,8 +116,9 @@ var RESWORD = map[string]int{ "super": KEYWORD, "operator": KEYWORD, - "raw": KEYWORD, - "asm": KEYWORD, + "raw": KEYWORD, + "asm": KEYWORD, + "inline": KEYWORD, "true": LITERAL, "false": LITERAL, |