diff options
Diffstat (limited to 'tnslc/parse/parse.tnsl')
-rw-r--r-- | tnslc/parse/parse.tnsl | 56 |
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() ;/ |