From a2e776f669b454652ed7724ede78a432508ae61d Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Wed, 3 Sep 2025 21:36:16 +0200 Subject: [PATCH 01/10] Rename `token` variable to `line` --- src/luasm.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/luasm.lua b/src/luasm.lua index 60f9505..1841700 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -222,16 +222,16 @@ function LuASM:parse(tokenizer) parsed_lines = 0 } - local token + local line repeat - token = tokenizer:get_next_line() + line = tokenizer:get_next_line() parse_data.parsed_lines = parse_data.parsed_lines + 1 - if token ~= nil then + if line ~= nil then -- Remove comments if self.settings.comment ~= nil then - token = token:gsub(self.settings.comment, "") + line = line:gsub(self.settings.comment, "") end --[[ @@ -260,18 +260,18 @@ function LuASM:parse(tokenizer) location = parse_data.parsed_lines } - token = trim(rest) + line = trim(rest) end end + if line == "" then + goto continue -- Rest is empty + end + local elements = {} - string.gsub(token, self.settings.separator, + string.gsub(line, self.settings.separator, function(value) elements[#elements + 1] = value end) - if #elements == 0 then - goto continue -- empty line (or comment) - end - local errors = {} for _, instr in ipairs(self.instructions) do if instr.name ~= elements[1] then From 372975bb66581d7f4dbaf5291b1e3db12a751e82 Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Wed, 3 Sep 2025 21:41:59 +0200 Subject: [PATCH 02/10] Fixing the issues stated by luacheck --- src/luasm.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/luasm.lua b/src/luasm.lua index 1841700..0d4e2ba 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -245,7 +245,7 @@ function LuASM:parse(tokenizer) -- LABEL PROCESSING (very basic, one‑label per line) -- ------------------------------------------------- if self.settings.label ~= nil then - local label, rest = token:match(self.settings.label) + local label, rest = line:match(self.settings.label) if label ~= nil then -- Detect duplicate label definitions. if parse_data.labels[label] ~= nil then @@ -308,7 +308,7 @@ function LuASM:parse(tokenizer) ::continue:: end - until token == nil -- EOF + until line == nil -- EOF return parse_data, nil end From 262133799bcd3fa431df7ccad084d296c6925893 Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Mon, 8 Sep 2025 17:19:20 +0200 Subject: [PATCH 03/10] Revamp parsing strategy --- src/luasm.lua | 130 ++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 74 deletions(-) diff --git a/src/luasm.lua b/src/luasm.lua index 0d4e2ba..3115c82 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -222,93 +222,75 @@ function LuASM:parse(tokenizer) parsed_lines = 0 } - local line - repeat - line = tokenizer:get_next_line() + while tokenizer:has_next_line() do + tokenizer:goto_next_line() -- Maybe there should be an error if not everything was parsed + parse_data.parsed_lines = parse_data.parsed_lines + 1 - if line ~= nil then + local label = tokenizer:get_label() - -- Remove comments - if self.settings.comment ~= nil then - line = line:gsub(self.settings.comment, "") - end + --[[ + This is very basic label processing as labels could be + nested and there could be priorities assigned with labels. - --[[ - This is very basic label processing as labels could be - nested and there could be priorities assigned with labels. - - But here all the labels are just a simple reference to a line. - ]] - - -- ------------------------------------------------- - -- LABEL PROCESSING (very basic, one‑label per line) - -- ------------------------------------------------- - if self.settings.label ~= nil then - local label, rest = line:match(self.settings.label) - if label ~= nil then - -- Detect duplicate label definitions. - if parse_data.labels[label] ~= nil then - return parse_data, { - errors = { "The label '" .. label .. "' was found twice." }, - line = parse_data.parsed_lines - } - end - - parse_data.labels[label] = { - name = label, - location = parse_data.parsed_lines - } - - line = trim(rest) - end + But here all the labels are just a simple reference to a line. + --]] + if label ~= nil then + if parse_data.labels[label] ~= nil then + return parse_data, { + errors = { "The label '" .. label .. "' was found twice." }, + line = parse_data.parsed_lines + } end - if line == "" then - goto continue -- Rest is empty - end + parse_data.labels[label] = { + name = label, + location = #parse_data.instructions + 1 + } + end + + if tokenizer:end_of_line() then + goto continue + end + + local mnemonic = tokenizer:get_mnemonic() - local elements = {} - string.gsub(line, self.settings.separator, - function(value) elements[#elements + 1] = value end) - - local errors = {} - for _, instr in ipairs(self.instructions) do - if instr.name ~= elements[1] then - goto inline_continue - end - - local result = instr:parse(elements, self) - if type(result) == "table" then - parse_data.instructions[#parse_data.instructions + 1] = result - goto continue -- go to the outer `continue` label - else - errors[#errors + 1] = result - end - - ::inline_continue:: + local errors = {} + for _, instr in ipairs(self.instructions) do + if instr.name ~= mnemonic then + goto inner end - ------------------------------------------------- - -- NO INSTRUCTION MATCHED - ------------------------------------------------- - if #errors == 0 then - -- No instruction with that mnemonic exists. - return parse_data, { - errors = { "There is no instruction with the name '" .. elements[1] .. "'" }, - line = parse_data.parsed_lines - } + local result = instr:parse(tokenizer, self) + if type(result) == "table" then + parse_data.instructions[#parse_data.instructions + 1] = result + goto continue -- go to the outer `continue` label else - -- At least one instruction matched the name but rejected the operands. - return parse_data, { - errors = errors, - line = parse_data.parsed_lines - } + errors[#errors + 1] = result end - ::continue:: + ::inner:: + end + + ------------------------------------------------- + -- NO INSTRUCTION MATCHED + ------------------------------------------------- + if #errors == 0 then + -- No instruction with that mnemonic exists. + return parse_data, { + errors = { "There is no instruction with the name '" .. mnemonic .. "'" }, + line = parse_data.parsed_lines + } + else + -- At least one instruction matched the name but rejected the operands. + return parse_data, { + errors = errors, + line = parse_data.parsed_lines + } end - until line == nil -- EOF + + ::continue:: + end return parse_data, nil end From a2fcb6cc2fb254962830cefa5b1acaef8527a0e3 Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Mon, 8 Sep 2025 17:47:46 +0200 Subject: [PATCH 04/10] Add additional functionality to tokenizer --- examples/01_inline_parsing.lua | 2 +- examples/02_file_parsing.lua | 2 +- examples/03_custom_arguments.lua | 2 +- examples/05_comments.lua | 2 +- examples/06_custom_comments.lua | 2 +- src/luasm.lua | 52 +++++++++++++++++++++++++++----- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/examples/01_inline_parsing.lua b/examples/01_inline_parsing.lua index be26886..95ca189 100644 --- a/examples/01_inline_parsing.lua +++ b/examples/01_inline_parsing.lua @@ -17,7 +17,7 @@ start: mov 10 r0 add r0 r1 jmp start ]] -local tokenizer = LuASM.string_tokenizer(src) +local tokenizer = LuASM:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/02_file_parsing.lua b/examples/02_file_parsing.lua index aa6cf2c..5c11f30 100644 --- a/examples/02_file_parsing.lua +++ b/examples/02_file_parsing.lua @@ -12,7 +12,7 @@ local instructions = { local asm = LuASM:new(instructions, {}) -- 3. Tokenize a source string -local tokenizer = LuASM.file_tokenizer("./data/02_data.lasm") +local tokenizer = LuASM:file_tokenizer("./data/02_data.lasm") -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/03_custom_arguments.lua b/examples/03_custom_arguments.lua index 554345f..a69a08f 100644 --- a/examples/03_custom_arguments.lua +++ b/examples/03_custom_arguments.lua @@ -20,7 +20,7 @@ local src = [[ mov reg0, reg1 print "Hello" ]] -local tokenizer = LuASM.string_tokenizer(src) +local tokenizer = LuASM:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/05_comments.lua b/examples/05_comments.lua index ab35a9c..a1cd135 100644 --- a/examples/05_comments.lua +++ b/examples/05_comments.lua @@ -17,7 +17,7 @@ start: mov 10 r0 # This is a comment add r0 r1 ; This is another comment jmp start ]] -local tokenizer = LuASM.string_tokenizer(src) +local tokenizer = LuASM:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/06_custom_comments.lua b/examples/06_custom_comments.lua index 0356909..3469ab8 100644 --- a/examples/06_custom_comments.lua +++ b/examples/06_custom_comments.lua @@ -19,7 +19,7 @@ start: mov 10 r0 = My custom comment add r0 r1 = This just works jmp start ]] -local tokenizer = LuASM.string_tokenizer(src) +local tokenizer = LuASM:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/src/luasm.lua b/src/luasm.lua index 3115c82..9d86113 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -109,11 +109,23 @@ function Tokenizer.get_next_line() return false end +--- @return boolean +function Tokenizer:has_next_line() + return false +end + +--- @return string|nil +function Tokenizer:get_label() + return nil +end + --- Creates a new tokenizer without a specific implementation. --- @return table A tokenizer instance (needs a concrete `get_next_line` implementation). -function Tokenizer:new() +function Tokenizer:new(luasm) local obj = {} + obj.luasm = luasm + setmetatable(obj, self) self.__index = self @@ -123,13 +135,13 @@ end --- Reads in a file and returns a tokenizer for that file. --- @param path string Path to the file to read. --- @return table|nil Tokenizer instance or `nil` if the file cannot be opened. -function LuASM.file_tokenizer(path) +function LuASM:file_tokenizer(path) local file = io.open(path, "r") if file == nil then return nil end - local tokenizer = LuASM.string_tokenizer(file:read("*a")) + local tokenizer = self:string_tokenizer(file:read("*a")) file:close() @@ -139,13 +151,15 @@ end --- Reads in a string of the asm and returns a tokenizer for that file. --- @param input string The complete ASM source as a string. --- @return table Tokenizer instance. -function LuASM.string_tokenizer(input) +function LuASM:string_tokenizer(input) local tokenizer = Tokenizer:new() tokenizer.input = input tokenizer.cursor = 1 -- byte index inside `input` tokenizer.current_line = 1 -- line counter (1‑based) + tokenizer.line = nil + -- Concrete implementation of `get_next_line` for a string source. tokenizer.get_next_line = function() if #tokenizer.input <= tokenizer.cursor then @@ -156,12 +170,38 @@ function LuASM.string_tokenizer(input) local line = trim(string.sub(tokenizer.input, tokenizer.cursor, endIndex)) + -- Remove comment from the line + if self.settings.comment ~= nil then + line = line:gsub(self.settings.comment, "") + end + tokenizer.cursor = endIndex + 1 tokenizer.current_line = tokenizer.current_line + 1 return line end + tokenizer.has_line = function() + tokenizer.line = tokenizer.get_next_line() + + return tokenizer.line ~= nil + end + + tokenizer.get_label = function() + if self.settings.label == nil then + return nil + end + + local label, rest = tokenizer.line:match(self.settings.label) + + if label ~= nil then + tokenizer.line = rest + tokenizer.cursor = tokenizer.cursor + #label + end + + return label + end + return tokenizer end @@ -222,9 +262,7 @@ function LuASM:parse(tokenizer) parsed_lines = 0 } - while tokenizer:has_next_line() do - tokenizer:goto_next_line() -- Maybe there should be an error if not everything was parsed - + while tokenizer:has_line() do parse_data.parsed_lines = parse_data.parsed_lines + 1 local label = tokenizer:get_label() From caf1127cc9dc2e97b404152e8831708e79b2da5d Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Mon, 8 Sep 2025 23:40:24 +0200 Subject: [PATCH 05/10] Move the implementation of tokenizer functions The functions are being moved as these can be used by many different implementations of the tokenizer. So it does not make any sense if they only apply to one implementation of that tokenizer. --- src/luasm.lua | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/luasm.lua b/src/luasm.lua index 9d86113..2694d20 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -104,19 +104,33 @@ end local Tokenizer = {} --- Abstract method that must be overridden by a concrete tokenizer. +--- @return string|nil function Tokenizer.get_next_line() error("This function has to be implemented!") - return false + return nil end --- @return boolean -function Tokenizer:has_next_line() - return false +function Tokenizer:has_line() + self.line = self:get_next_line() + + return self.line ~= nil end --- @return string|nil function Tokenizer:get_label() - return nil + if self.luasm.settings.label == nil then + return nil + end + + local label, rest = self.line:match(self.settings.label) + + if label ~= nil then + self.line = rest + self.cursor = self.cursor + #label + end + + return label end --- Creates a new tokenizer without a specific implementation. @@ -181,27 +195,6 @@ function LuASM:string_tokenizer(input) return line end - tokenizer.has_line = function() - tokenizer.line = tokenizer.get_next_line() - - return tokenizer.line ~= nil - end - - tokenizer.get_label = function() - if self.settings.label == nil then - return nil - end - - local label, rest = tokenizer.line:match(self.settings.label) - - if label ~= nil then - tokenizer.line = rest - tokenizer.cursor = tokenizer.cursor + #label - end - - return label - end - return tokenizer end From dc10532b4f3f429c545a4ba61528428a91a3d718 Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Wed, 10 Sep 2025 17:23:27 +0200 Subject: [PATCH 06/10] Fix some mistakes --- src/luasm.lua | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/luasm.lua b/src/luasm.lua index 2694d20..b5bc052 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -35,9 +35,10 @@ LuASM.version = "0.0.1" function LuASM:new(instructions, settings) -- Default settings setmetatable(settings, { __index = { - separator = "[^,%s]+", + separator = "^[ ,]+", label = "^([%a]+):%s*(.*)", comment = "[;#].*$", + mnemonic = "^([%a]+)(.*)", syntax = { imm = "^[%d]+", reg = "^%a[%w]*", @@ -110,6 +111,10 @@ function Tokenizer.get_next_line() return nil end +function Tokenizer:eol() + return self.line:len() == 0 +end + --- @return boolean function Tokenizer:has_line() self.line = self:get_next_line() @@ -123,16 +128,28 @@ function Tokenizer:get_label() return nil end - local label, rest = self.line:match(self.settings.label) + local label, rest = self.line:match(self.luasm.settings.label) if label ~= nil then - self.line = rest + self.line = trim(rest) self.cursor = self.cursor + #label end return label end +--- @return boolean +function Tokenizer:get_mnemonic() + local mnemonic, rest = self.line:match(self.luasm.settings.mnemonic) + + if mnemonic ~= nil then + self.line = trim(rest) + self.cursor = self.cursor + #mnemonic + end + + return mnemonic +end + --- Creates a new tokenizer without a specific implementation. --- @return table A tokenizer instance (needs a concrete `get_next_line` implementation). function Tokenizer:new(luasm) @@ -166,7 +183,7 @@ end --- @param input string The complete ASM source as a string. --- @return table Tokenizer instance. function LuASM:string_tokenizer(input) - local tokenizer = Tokenizer:new() + local tokenizer = Tokenizer:new(self) tokenizer.input = input tokenizer.cursor = 1 -- byte index inside `input` @@ -186,7 +203,7 @@ function LuASM:string_tokenizer(input) -- Remove comment from the line if self.settings.comment ~= nil then - line = line:gsub(self.settings.comment, "") + line = trim(line:gsub(self.settings.comment, "")) end tokenizer.cursor = endIndex + 1 @@ -280,7 +297,7 @@ function LuASM:parse(tokenizer) } end - if tokenizer:end_of_line() then + if tokenizer:eol() then goto continue end From f9f54775ac1983c70af1319464b0304400c27175 Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Wed, 10 Sep 2025 17:24:47 +0200 Subject: [PATCH 07/10] Implement the rest of the parsing --- src/luasm.lua | 102 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/src/luasm.lua b/src/luasm.lua index b5bc052..800fba6 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -150,6 +150,57 @@ function Tokenizer:get_mnemonic() return mnemonic end +local ArgumentTokenizer = {} + +function ArgumentTokenizer:get_next(argument_type) + local argument_regex = self.luasm.settings.syntax[argument_type] + + local matched = self.line:match(argument_regex, self.position) + + if matched ~= nil then + self.position = self.position + matched:len() + end + + return matched +end + +function ArgumentTokenizer:skip_separator() + local matched = self.line:match(self.luasm.settings.separator, self.position) + + if matched == nil then + return false + end + + self.position = self.position + matched:len() + + return true +end + +function ArgumentTokenizer:reset() + self.position = 1 +end + +function ArgumentTokenizer:eol() + return self.position > self.line:len() +end + +--- Creates an argument tokenizer based upon the current state +--- of the creating tokenizer. +--- +--- @return table The argument tokenizer +function Tokenizer:argument_tokenizer() + local obj = {} + + obj.line = self.line + obj.luasm = self.luasm + obj.position = 1 + + setmetatable(obj, ArgumentTokenizer) + ArgumentTokenizer.__index = ArgumentTokenizer + + return obj +end + --- Creates a new tokenizer without a specific implementation. --- @return table A tokenizer instance (needs a concrete `get_next_line` implementation). function Tokenizer:new(luasm) @@ -220,37 +271,46 @@ end --- `{ op = opcode, args = args, line = current line }` --- --- If the parsing has errored out, it returns a string with the error message. ---- @param elements table Token list where `elements[1]` is the mnemonic. ---- @param luasm table The LuASM instance (provides settings, etc.). +--- @param arguments table Token list where `elements[1]` is the mnemonic. +--- @param luasm table The LuASM instance (provides settings, etc.). --- @return table|string On success a table `{op, args, line, run}`; on failure a string error message. -function instruction:parse(elements, luasm) +function instruction:parse(arguments, luasm) -- `elements[1]` is the mnemonic, the rest are raw operands local opcode = self.name local expected = self.structure -- e.g. {"imm","reg"} - if #elements - 1 ~= #expected then - local err = string.format( - "Wrong number of operands for %s (expected %d, got %d)", - opcode, #expected, #elements - 1) - return err - end local args = {} - for i = 2, #elements do - local pattern = luasm.settings.syntax[expected[i - 1]] - if pattern == nil then - error("The pattern with the name of '" .. expected[i - 1] .. "' does not exist.", 2) - return "Pattern not found" + for index, value in ipairs(expected) do + if index ~= 1 then + if not arguments:skip_separator() then + local err = string.format( + "Expected separator after the argument number %d (for %s)", + index - 1, opcode + ) + return err + end end - local arg = elements[i]:match(pattern) + local arg = arguments:get_next(value) + if arg == nil then local err = string.format( - "Could not match argument '%s' (expected %s)", - elements[i], expected[i - 1]) + "Wrong number of operands for %s (expected %d but got less)", + opcode, #expected + ) return err end - args[i - 1] = arg + + args[#args + 1] = arg + end + + if not arguments:eol() then + local err = string.format( + "Wrong number of operands for %s (expected %d but got more)", + opcode, #expected + ) + return err end return { @@ -304,12 +364,16 @@ function LuASM:parse(tokenizer) local mnemonic = tokenizer:get_mnemonic() local errors = {} + local argument_tokenizer = tokenizer:argument_tokenizer() + for _, instr in ipairs(self.instructions) do if instr.name ~= mnemonic then goto inner end - local result = instr:parse(tokenizer, self) + local result = instr:parse(argument_tokenizer, self) + argument_tokenizer:reset() + if type(result) == "table" then parse_data.instructions[#parse_data.instructions + 1] = result goto continue -- go to the outer `continue` label From 3be262da46104a405ab9c8558b432f2e00afa237 Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Wed, 10 Sep 2025 17:32:48 +0200 Subject: [PATCH 08/10] Add documentation --- src/luasm.lua | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/luasm.lua b/src/luasm.lua index 800fba6..a3148f9 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -105,24 +105,29 @@ end local Tokenizer = {} --- Abstract method that must be overridden by a concrete tokenizer. ---- @return string|nil +--- @return string|nil The next line function Tokenizer.get_next_line() error("This function has to be implemented!") return nil end +--- Checks if the parser is at the end of the line +--- @return boolean If it is at the end of the line function Tokenizer:eol() return self.line:len() == 0 end ---- @return boolean +--- Gets the next line and checks if it exist. +--- This method moves the tokenizer to the next line. +--- @return boolean If the next line exists function Tokenizer:has_line() self.line = self:get_next_line() return self.line ~= nil end ---- @return string|nil +--- Returns the label that is in this line +--- @return string|nil The label function Tokenizer:get_label() if self.luasm.settings.label == nil then return nil @@ -138,7 +143,8 @@ function Tokenizer:get_label() return label end ---- @return boolean +--- Returns the mnemonic of the line +--- @return string|nil The mnemonic that is being parsed function Tokenizer:get_mnemonic() local mnemonic, rest = self.line:match(self.luasm.settings.mnemonic) @@ -152,6 +158,9 @@ end local ArgumentTokenizer = {} +--- Returns the next argument based on the argument type +--- @param argument_type string The argument type that should be parsed +--- @return string|nil The parsed result function ArgumentTokenizer:get_next(argument_type) local argument_regex = self.luasm.settings.syntax[argument_type] @@ -164,6 +173,8 @@ function ArgumentTokenizer:get_next(argument_type) return matched end +--- Skips the separator part of the line +--- @return boolean If a separator existed function ArgumentTokenizer:skip_separator() local matched = self.line:match(self.luasm.settings.separator, self.position) @@ -176,17 +187,20 @@ function ArgumentTokenizer:skip_separator() return true end +--- Resets the argument tokenizer function ArgumentTokenizer:reset() self.position = 1 end +--- Checks if the tokenizer is at the end of the line +--- @return boolean If the end of line is reached function ArgumentTokenizer:eol() return self.position > self.line:len() end --- Creates an argument tokenizer based upon the current state --- of the creating tokenizer. ---- +--- --- @return table The argument tokenizer function Tokenizer:argument_tokenizer() local obj = {} From 49d7324c56d1307c28c3e998d587055c6d46ef4e Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Wed, 10 Sep 2025 17:34:00 +0200 Subject: [PATCH 09/10] Fix linting error --- src/luasm.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/luasm.lua b/src/luasm.lua index a3148f9..d552ec0 100644 --- a/src/luasm.lua +++ b/src/luasm.lua @@ -117,7 +117,7 @@ function Tokenizer:eol() return self.line:len() == 0 end ---- Gets the next line and checks if it exist. +--- Gets the next line and checks if it exist. --- This method moves the tokenizer to the next line. --- @return boolean If the next line exists function Tokenizer:has_line() From 578ae92a89b79c3afdc488e2678e395355b9613a Mon Sep 17 00:00:00 2001 From: QuickWrite <54590845+QuickWrite@users.noreply.github.com> Date: Wed, 10 Sep 2025 17:36:08 +0200 Subject: [PATCH 10/10] Migrate examples to new system --- examples/01_inline_parsing.lua | 2 +- examples/02_file_parsing.lua | 2 +- examples/03_custom_arguments.lua | 2 +- examples/04_interpreter.lua | 2 +- examples/05_comments.lua | 2 +- examples/06_custom_comments.lua | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/01_inline_parsing.lua b/examples/01_inline_parsing.lua index 95ca189..8d7a431 100644 --- a/examples/01_inline_parsing.lua +++ b/examples/01_inline_parsing.lua @@ -17,7 +17,7 @@ start: mov 10 r0 add r0 r1 jmp start ]] -local tokenizer = LuASM:string_tokenizer(src) +local tokenizer = asm:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/02_file_parsing.lua b/examples/02_file_parsing.lua index 5c11f30..00ec858 100644 --- a/examples/02_file_parsing.lua +++ b/examples/02_file_parsing.lua @@ -12,7 +12,7 @@ local instructions = { local asm = LuASM:new(instructions, {}) -- 3. Tokenize a source string -local tokenizer = LuASM:file_tokenizer("./data/02_data.lasm") +local tokenizer = asm:file_tokenizer("./data/02_data.lasm") -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/03_custom_arguments.lua b/examples/03_custom_arguments.lua index a69a08f..9b811aa 100644 --- a/examples/03_custom_arguments.lua +++ b/examples/03_custom_arguments.lua @@ -20,7 +20,7 @@ local src = [[ mov reg0, reg1 print "Hello" ]] -local tokenizer = LuASM:string_tokenizer(src) +local tokenizer = asm:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/04_interpreter.lua b/examples/04_interpreter.lua index be97657..64f8fd1 100644 --- a/examples/04_interpreter.lua +++ b/examples/04_interpreter.lua @@ -23,7 +23,7 @@ print "Hello" print "World" print "Message" ]] -local tokenizer = LuASM.string_tokenizer(src) +local tokenizer = asm:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/05_comments.lua b/examples/05_comments.lua index a1cd135..c1cc4b7 100644 --- a/examples/05_comments.lua +++ b/examples/05_comments.lua @@ -17,7 +17,7 @@ start: mov 10 r0 # This is a comment add r0 r1 ; This is another comment jmp start ]] -local tokenizer = LuASM:string_tokenizer(src) +local tokenizer = asm:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer) diff --git a/examples/06_custom_comments.lua b/examples/06_custom_comments.lua index 3469ab8..eb729fb 100644 --- a/examples/06_custom_comments.lua +++ b/examples/06_custom_comments.lua @@ -19,7 +19,7 @@ start: mov 10 r0 = My custom comment add r0 r1 = This just works jmp start ]] -local tokenizer = LuASM:string_tokenizer(src) +local tokenizer = asm:string_tokenizer(src) -- 4. Parse local result = asm:parse(tokenizer)