mighty

The mighty programming language, compiler and tools (WIP)
Log | Files | Refs

commit 3b604da71a926ac862fb9cdc28e4755d162ef61e
parent 5ad660308555fa5341d9a7a64a75b74638010b65
Author: citbl <citbl@citbl.org>
Date:   Sun, 24 May 2026 21:18:44 +1000

basic string literal

Diffstat:
Mmtcl/lexer.lua | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/mtcl/lexer.lua b/mtcl/lexer.lua @@ -66,6 +66,24 @@ function read_number(start, src) return num, i, is_float end +function read_string_literal(start, src) + start = start + 1 -- consume leading dbl_quote + local str = "" + local i = start + local c = 0 + while i <= #src do + c = src:sub(i, i) + if c == '"' then + i = i - 1 + break + end + i = i + 1 + end + word = src:sub(start, i) + i = i + 1 -- consume trailing dbl_quote + return word, i +end + TK = { IDK = "UNKNOWN", COLON = "colon", @@ -83,6 +101,7 @@ TK = { SGL_QUOTE = "sgl quo", LIT_FLOAT = "a float", LIT_INT = "a int", + LIT_STRING = "a string", COMMA = "comma", } @@ -182,6 +201,11 @@ function lexer:lex(file, src) end self.col = self.col + #number i = i + 1 + elseif c == '"' then + str, i = read_string_literal(i, src) + self:add(TK.LIT_STRING, str) + self.col = self.col + #str + 2 + i = i + 1 elseif c == ":" then if next() == ":" then self:add(TK.COLONCOLON, "::")