From 2572cd049ee5e1e2685b1abe6bfcfbb8aa988a71 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 5 May 2022 16:14:01 -0400 Subject: Add methods to crash in a defined way --- tnslc/ast/statement.tnsl | 49 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'tnslc/ast/statement.tnsl') 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] -- cgit v1.2.3