summaryrefslogtreecommitdiff
path: root/tnslc/ast/statement.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-05-05 16:14:01 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-05-05 16:14:01 -0400
commit2572cd049ee5e1e2685b1abe6bfcfbb8aa988a71 (patch)
treeb191126f961c6befc6da2c65c28d5bef69077579 /tnslc/ast/statement.tnsl
parent5cf518362e6bc08eb44eb8d6ed74a0a23c2c3a5f (diff)
Add methods to crash in a defined way
Diffstat (limited to 'tnslc/ast/statement.tnsl')
-rw-r--r--tnslc/ast/statement.tnsl49
1 files changed, 48 insertions, 1 deletions
diff --git a/tnslc/ast/statement.tnsl b/tnslc/ast/statement.tnsl
index d8b4877..6023de2 100644
--- a/tnslc/ast/statement.tnsl
+++ b/tnslc/ast/statement.tnsl
@@ -21,10 +21,57 @@
string_equate(word, "delete")
;/
-/; is_definition (~{}Token tokens, ~int i) [bool] ;/
+/; is_closing (Token t) [bool]
+ /; if (t.token_type == TOKEN_TYPE.DELIMIT)
+ ;return string_equate(t.data`, ")") || string_equate(t.data`, "]") || string_equate(t.data`, "}")
+ ;/
+ ;return false
+;/
+
+/; get_closing (~{}Token tokens, int i) [int]
+ ;{}charp end = ")"
+ /; if (string_equate(tokens`{i}.data`, "["))
+ ;end = "]"
+ ;; else if (string_equate(tokens`{i}.data`, "{"))
+ ;end = "}"
+ ;/
+
+ ;int delims = 0
+
+ /; loop (i++; i < len tokens`) [i++]
+ /; if (is_closing(tokens`{i}))
+ /; if (delims > 0)
+ ;delims--
+ ;; else if (string_equate(end, tokens`{i}.data`))
+ ;return i
+ ;; else
+ ;return -1
+ ;/
+ ;; else if (tokens`{i}.token_type == TOKEN_TYPE.DELIMIT)
+ ;delims++
+ ;/
+ ;/
+
+ ;return -1
+;/
+
+
+/; is_definition (~{}Token tokens, ~int i) [bool]
+
+ /; loop (int j = i`; j < len tokens`) [j++]
+ /; if (tokens`{j}.token_type == TOKEN_TYPE.KEYTYPE)
+
+ ;; else if ()
+ ;/
+ ;/
+ ;return false
+;/
/; tree_keyword_statement (~{}Token tokens, ~int i) [Node]
+ ;Token def_tok = {TOKEN_TYPE.KEYWORD, 0, 0, ~CNULL}
+ ;{}Node def_sub = {}
+ ;return {def_tok, ~def_sub}
;/
/; tree_statement (~{}Token tokens, ~int i) [Node]