From 65eafdcefd5179eb767ce8886e19f30ea701385b Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sat, 30 Oct 2021 03:02:33 -0400 Subject: [AST] Bugfix 'void' Basic bugfix to get void types parsing. Hopefuly this fixes other bugs too. --- src/tparse/tree-list.go | 12 ------------ src/tparse/tree-value.go | 25 +++++++++++++------------ 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/tparse/tree-list.go b/src/tparse/tree-list.go index 9cfd55f..740c06a 100644 --- a/src/tparse/tree-list.go +++ b/src/tparse/tree-list.go @@ -33,9 +33,6 @@ func getClosing(start string) string { func parseValueList(tokens *[]Token, tok, max int) (Node, int) { out := Node{Data: Token{Type: 10, Data: "vlist"}, IsBlock: false} var tmp Node - - tmp, tok = parseValue(tokens, tok, max) - out.Sub = append(out.Sub, tmp) for ; tok < max; { @@ -48,8 +45,6 @@ func parseValueList(tokens *[]Token, tok, max int) (Node, int) { return out, tok case INLNSEP: tok++ - default: - errOut("Error: unexpected token when parsing a list of values", t) } tmp, tok = parseValue(tokens, tok, max) @@ -84,8 +79,6 @@ func parseParamList(tokens *[]Token, tok, max int) (Node, int) { return out, tok case INLNSEP: tok++ - default: - errOut("Error: unexpected token when parsing a list of values", t) } if isTypeThenValue(tokens, tok, max) { @@ -104,9 +97,6 @@ func parseParamList(tokens *[]Token, tok, max int) (Node, int) { func parseTypeList(tokens *[]Token, tok, max int) (Node, int) { out := Node{Data: Token{Type: 10, Data: "tlist"}, IsBlock: false} var tmp Node - - tmp, tok = parseType(tokens, tok, max, true) - out.Sub = append(out.Sub, tmp) for ; tok < max; { @@ -119,8 +109,6 @@ func parseTypeList(tokens *[]Token, tok, max int) (Node, int) { return out, tok case INLNSEP: tok++ - default: - errOut("Error: unexpected token when parsing a list of values", t) } tmp, tok = parseType(tokens, tok, max, true) diff --git a/src/tparse/tree-value.go b/src/tparse/tree-value.go index b9796c8..edca103 100644 --- a/src/tparse/tree-value.go +++ b/src/tparse/tree-value.go @@ -98,7 +98,7 @@ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { var tmp Node switch t.Data { case "{", "(": // Array or struct evaluation, parenthetical value - tmp, tok = parseValueList(tokens, tok, max) + tmp, tok = parseValueList(tokens, tok + 1, max) out.Sub = append(out.Sub, tmp) val = true default: @@ -132,14 +132,14 @@ func parseUnaryOps(tokens *[]Token, tok, max int) (Node) { var tmp Node switch t.Data { case "(": // Function call - tmp, tok = parseValueList(tokens, tok, max) + tmp, tok = parseValueList(tokens, tok + 1, max) + tmp.Data.Data = "call" case "[": // Typecasting - tmp, tok = parseTypeList(tokens, tok, max) + tmp, tok = parseTypeList(tokens, tok + 1, max) + tmp.Data.Data = "cast" case "{": // Array indexing - tmp = Node{Data: Token{Type: 10, Data: "index"}} - var tmp2 Node - tmp2, tok = parseValue(tokens, tok + 1, max) - tmp.Sub = append(tmp.Sub, tmp2) + tmp, tok = parseValueList(tokens, tok + 1, max) + tmp.Data.Data = "index" default: errOut("Unexpected delimiter when parsing value", t) } @@ -305,12 +305,14 @@ func parseTypeParams(tokens *[]Token, tok, max int) (Node, int) { case DELIMIT: if tok < max-1 { if t.Data == "(" { - tmp, tok = parseValueList(tokens, tok, max) + tmp, tok = parseTypeList(tokens, tok + 1, max) + tmp.Data.Data = "()" } else if t.Data == "[" { - tmp, tok = parseTypeList(tokens, tok, max) + tmp, tok = parseTypeList(tokens, tok + 1, max) + tmp.Data.Data = "[]" } else if t.Data == ")" || t.Data == "]" || t.Data == "}" { // End of type - tok-- + tok++ goto VOIDDONE } else { errOut("Error: unexpected delimeter when parsing type", t) @@ -321,7 +323,6 @@ func parseTypeParams(tokens *[]Token, tok, max int) (Node, int) { default: // End of type - tok-- goto VOIDDONE } @@ -386,7 +387,7 @@ func parseType(tokens *[]Token, tok, max int, param bool) (Node, int) { } else { // Constant length array. Parse value for length and increment var tmp2 Node - tmp2, tok = parseValue(tokens, tok + 1, max) + tmp2, tok = parseValueList(tokens, tok + 1, max) tmp.Sub = append(tmp.Sub, tmp2) } } else if t.Data == ")" || t.Data == "]" || t.Data == "}"{ -- cgit v1.2.3