summaryrefslogtreecommitdiff
path: root/tnslc/tokenizer.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-08-05 17:48:15 -0400
committerKyle Gunger <kgunger12@gmail.com>2023-08-05 17:48:15 -0400
commitadc97807daa20efd16fcc9ef82f773bdd23f63bd (patch)
tree80a248a90dedf3ebce92cd576cf0db70e359959c /tnslc/tokenizer.tnsl
parent6ee6814c269aa5a5c2ea8e031db3a335df2c1f2d (diff)
Fix issue with cf block conditionals
Diffstat (limited to 'tnslc/tokenizer.tnsl')
-rw-r--r--tnslc/tokenizer.tnsl77
1 files changed, 50 insertions, 27 deletions
diff --git a/tnslc/tokenizer.tnsl b/tnslc/tokenizer.tnsl
index ab22d7d..0ae71a1 100644
--- a/tnslc/tokenizer.tnsl
+++ b/tnslc/tokenizer.tnsl
@@ -180,39 +180,63 @@ struct Token {
return a || b || c
;/
-/; str_char_literal(uint8 start, ~Token tmp, ~void file_in)
- uint read_count = 0
+/; handle_comment (~void file_in)
uint8 buf = 0
-
- tmp`._type = TOKEN_TYPE.LITERAL
- tmp`.append(buf)
- /; loop (_read_byte(file_in, ~buf, ~read_count))
+ int read_count = 0
+ /; loop
+ _read_byte(file_in, ~buf, ~read_count)
+ /; if (buf == '\n' || read_count == 0)
+ break
+ ;/
+ read_count = 0
+ ;/
+;/
+
+/; handle_str (~void file_in, Token tmp, ~int line, column, uint8 first) [Token]
+ uint8 buf = first
+ int read_count = 0
+ tmp._type = TOKEN_TYPE.LITERAL
+ tmp.append(buf)
+ read_count = 0
+ log_one_nl(first)
+
+ /; loop
+ _read_byte(file_in, ~buf, ~read_count)
+ log_one_nl(buf)
+ log_num_nl(read_count)
+
/; if (read_count == 0)
- break
+ log_one_nl('b')
+ break
;/
-
+
/; if (buf == '\\')
- tmp`.append(buf)
+ log_one_nl('c')
+ tmp.append(buf)
read_count = 0
_read_byte(file_in, ~buf, ~read_count)
- column++
- tmp`.append(buf)
- ;; else if (buf == start)
- tmp`.append(buf)
+ column`++
+ tmp.append(buf)
+ ;; else if (buf == first)
+ log_one_nl('d')
+ tmp.append(buf)
break
;; else
- tmp`.append(buf)
+ log_one_nl('e')
+ tmp.append(buf)
;/
/; if (buf == '\n')
- line++
- column = 1
+ line`++
+ column` = 1
;; else
- column++
+ column`++
;/
read_count = 0
;/
+
+ return tmp
;/
/; tokenize_file (~void file_in, file_out)
@@ -226,10 +250,10 @@ struct Token {
int read_count = 0
int line = 1
int column = 1
- # Start reading at beginning of file
- _read_byte(file_in, ~buf, ~read_count)
+
# Read loop.
- /; loop (_read_byte(file_in, ~buf, ~read_count)) [column++]
+ /; loop [column++]
+ _read_byte(file_in, ~buf, ~read_count)
/; if (read_count == 0)
break
;/
@@ -237,20 +261,19 @@ struct Token {
/; if (buf == '#')
# Handle comment
- /; loop (_read_byte(file_in, ~buf, ~read_count))
- /; if (buf == '\n' || read_count == 0)
- break
- ;/
- ;/
+ handle_comment(file_in)
+ line++
;; else if (buf == '\'' || buf == '"')
# Handle char/string literal
- str_char_literal(buf, ~tmp, file_in)
-
+ tmp = handle_str(file_in, tmp, ~line, ~column, buf)
+
print_token(tmp, file_out)
tmp._del()
tmp.start()
+ tmp.line = line
+ tmp.column = column
;; else if (break_token(~tmp, buf) == true)