Skip to content

Commit caf1127

Browse files
committed
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.
1 parent a2fcb6c commit caf1127

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/luasm.lua

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,33 @@ end
104104
local Tokenizer = {}
105105

106106
--- Abstract method that must be overridden by a concrete tokenizer.
107+
--- @return string|nil
107108
function Tokenizer.get_next_line()
108109
error("This function has to be implemented!")
109-
return false
110+
return nil
110111
end
111112

112113
--- @return boolean
113-
function Tokenizer:has_next_line()
114-
return false
114+
function Tokenizer:has_line()
115+
self.line = self:get_next_line()
116+
117+
return self.line ~= nil
115118
end
116119

117120
--- @return string|nil
118121
function Tokenizer:get_label()
119-
return nil
122+
if self.luasm.settings.label == nil then
123+
return nil
124+
end
125+
126+
local label, rest = self.line:match(self.settings.label)
127+
128+
if label ~= nil then
129+
self.line = rest
130+
self.cursor = self.cursor + #label
131+
end
132+
133+
return label
120134
end
121135

122136
--- Creates a new tokenizer without a specific implementation.
@@ -181,27 +195,6 @@ function LuASM:string_tokenizer(input)
181195
return line
182196
end
183197

184-
tokenizer.has_line = function()
185-
tokenizer.line = tokenizer.get_next_line()
186-
187-
return tokenizer.line ~= nil
188-
end
189-
190-
tokenizer.get_label = function()
191-
if self.settings.label == nil then
192-
return nil
193-
end
194-
195-
local label, rest = tokenizer.line:match(self.settings.label)
196-
197-
if label ~= nil then
198-
tokenizer.line = rest
199-
tokenizer.cursor = tokenizer.cursor + #label
200-
end
201-
202-
return label
203-
end
204-
205198
return tokenizer
206199
end
207200

0 commit comments

Comments
 (0)