summaryrefslogtreecommitdiff
path: root/tnslc/compile
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-30 02:46:04 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-30 02:46:04 -0400
commit59aabd4ed77ff3ede1df368ad134c56a6f8787c0 (patch)
tree0dc74f277fa35eb7ec9d72cc793da094b18b4686 /tnslc/compile
parenta282af0b8fd4102778d6d8781c29f1c0202e13ee (diff)
in_csv function
Diffstat (limited to 'tnslc/compile')
-rw-r--r--tnslc/compile/generator.tnsl10
-rw-r--r--tnslc/compile/tokenizer.tnsl53
2 files changed, 63 insertions, 0 deletions
diff --git a/tnslc/compile/generator.tnsl b/tnslc/compile/generator.tnsl
index 239b0c3..5d71a05 100644
--- a/tnslc/compile/generator.tnsl
+++ b/tnslc/compile/generator.tnsl
@@ -1,3 +1,13 @@
/; generate (utils.File fin, fout)
+ ~uint8 fa = fin.path.to_cstr('/')
+ ~uint8 fb = fout.path.to_cstr('/')
+
+ _printf(fa)
+ _printf(newline)
+ _printf(fb)
+ _printf(newline)
+
+ _delete(fa)
+ _delete(fb)
;/
diff --git a/tnslc/compile/tokenizer.tnsl b/tnslc/compile/tokenizer.tnsl
index e69de29..428815f 100644
--- a/tnslc/compile/tokenizer.tnsl
+++ b/tnslc/compile/tokenizer.tnsl
@@ -0,0 +1,53 @@
+struct Token {
+ ~uint8 data,
+ int
+ _type,
+ line,
+ col
+}
+
+/; method Token
+ /; eq (Token tok) [bool]
+ return utils.strcmp(self.data, tok.data)
+ ;/
+
+ /; eq_str(~uint8 str) [bool]
+ return utils.strcmp(self.data, str)
+ ;/
+;/
+
+/; _is_space(uint8 char) [bool]
+ /; if (char == '\t' || char == '\n' || char == '\r' || char == ' ')
+ return true
+ ;/
+ return false
+;/
+
+/; _in_csv (~uint8 csv, ~uint8 str) [bool]
+ int along = 0
+
+ /; loop (csv` !== 0) [csv++]
+ /; if (csv` == ',')
+ /; if (along !< 0 && str{along} == 0)
+ return true
+ ;/
+ along = 0
+ ;; else if (along !< 0 && str{along} == csv`)
+ along++
+ ;; else
+ along = 0
+ along--
+ ;/
+ ;/
+
+ return along !< 0 && str{along} == 0
+;/
+
+/; tokenize(utils.File fin) [utils.Vector]
+ Token tok
+
+ utils.Vector out
+ out.init(len tok)
+
+ return out
+;/