summaryrefslogtreecommitdiff
path: root/tnslc/parse/parse.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-05-02 02:57:49 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-05-02 02:57:49 -0400
commit46aa6b65376ea62deb1d5ea1611b59dc222a5141 (patch)
treee92b26bc2d2653b9009a230ee1d6b7ed1185e3a0 /tnslc/parse/parse.tnsl
parent9478e157ec2cfe4de704b3bd78b07aee8824774f (diff)
[TNSLC] AST Updates
- Change how string_equate works - Call AST Node generator from main - Flush out ast.tnsl - Add a few initial methods to AST - Move some code from token.tnsl to parse.tnsl
Diffstat (limited to 'tnslc/parse/parse.tnsl')
-rw-r--r--tnslc/parse/parse.tnsl56
1 files changed, 54 insertions, 2 deletions
diff --git a/tnslc/parse/parse.tnsl b/tnslc/parse/parse.tnsl
index 5d3bfa5..9927d56 100644
--- a/tnslc/parse/parse.tnsl
+++ b/tnslc/parse/parse.tnsl
@@ -14,12 +14,64 @@
EXPRESS OR IMPLIED
#/
-/; module parse
+/; export module parse
:include "parse/token.tnsl"
:include "parse/tokenizer.tnsl"
;/
-/; print_tokens(~{}parse.Token dat)
+/# The various types of tokens #/
+; enum TOKEN_TYPE [int] {
+ LINESEP = 0,
+ INLNSEP = 1,
+ DELIMIT = 2,
+ AUGMENT = 3,
+ LITERAL = 4,
+ KEYTYPE = 5,
+ PREWORD = 6,
+ KEYWORD = 7,
+ DEFWORD = 8
+}
+
+/# Token struct definition #/
+; struct Token {
+ int
+ token_type,
+ line,
+ col,
+
+ ~{}charp
+ data
+}
+
+/; method Token
+
+ /; print
+ ;tnsl.io.print("{ ")
+ ;tnsl.io.print(self.token_type)
+ ;tnsl.io.print(" ")
+ ;tnsl.io.print(self.data`)
+ ;tnsl.io.print(" ")
+ ;tnsl.io.print(self.line)
+ ;tnsl.io.print(" ")
+ ;tnsl.io.print(self.col)
+ ;tnsl.io.print(" } ")
+ ;/
+
+ /; operator delete
+ ;delete self.data
+ ;/
+
+ /; add_char (~{}charp part)
+ # ;uint l = len self.data`
+ # ;realloc self.data, l + len part
+ /;loop (int i = 0; i < len part`) [i++]
+ # ;self.data`{l + i} = part{i}
+ ;self.data`.append(part`{i})
+ ;/
+ ;/
+;/
+
+/; print_tokens(~{}Token dat)
/;loop (int i = 0; i < len dat`) [i++]
;dat`{i}.print()
;/