diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-10-31 20:42:37 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-10-31 20:42:37 -0400 |
commit | eb05a05ac4f10672c573dd53cb3aaa27deb4f6a3 (patch) | |
tree | 64eac6e24ee8540cb4a86cf4263b595744b6dce9 /src/tparse/tree-list.go | |
parent | c0a3940eb07abf13123c7190a5fa8a613bba9db0 (diff) |
[AST] Handle control flow blocks
+ Initial support for control flow blocks. Things will be fixed as I find bugs.
Diffstat (limited to 'src/tparse/tree-list.go')
-rw-r--r-- | src/tparse/tree-list.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/tparse/tree-list.go b/src/tparse/tree-list.go index 740c06a..d415594 100644 --- a/src/tparse/tree-list.go +++ b/src/tparse/tree-list.go @@ -120,27 +120,29 @@ func parseTypeList(tokens *[]Token, tok, max int) (Node, int) { func parseStatementList(tokens *[]Token, tok, max int) (Node, int) { out := Node{} - out.Data = Token{Type: 10, Data: "statement"} + out.Data = Token{Type: 10, Data: "slist"} var tmp Node - c := getClosing((*tokens)[tok].Data) + if (*tokens)[tok].Data == ")" || (*tokens)[tok].Data == "}" || (*tokens)[tok].Data == "]" { + return out, tok + } - tok++ + tmp, tok = parseStatement(tokens, tok, max) + out.Sub = append(out.Sub, tmp) - for ; tok < max; tok++ { + for ; tok < max; { t := (*tokens)[tok] - switch t.Data { - case c: + switch t.Type { + case DELIMIT: return out, tok - case ",": + case LINESEP: tok++ + tmp, tok = parseStatement(tokens, tok, max) + out.Sub = append(out.Sub, tmp) default: errOut("Error: unexpected token when parsing a list of statements", t) } - - tmp, tok = parseStatement(tokens, tok, max) - out.Sub = append(out.Sub, tmp) } return out, tok |