mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Spoiler alert: Anselme run ~1.5x slower in LuaJIT than Lua 5.3/5.4. I didn't expected LuaJIT to be able to optimize anything with my super performant and cache friendly AST walker interpreter, but being this much slower is kinda impressive.
39 lines
856 B
Lua
39 lines
856 B
Lua
local class = require("class")
|
|
local utf8 = utf8 or require("lua-utf8")
|
|
|
|
local Source
|
|
Source = class {
|
|
name = "?",
|
|
line = -1,
|
|
position = -1,
|
|
|
|
init = function(self, name, line, position)
|
|
self.name = name
|
|
self.line = line
|
|
self.position = position
|
|
end,
|
|
increment = function(self, n, ...)
|
|
self.position = self.position + n
|
|
end,
|
|
count = function(self, capture, ...)
|
|
self:increment(utf8.len(capture))
|
|
return capture, ...
|
|
end,
|
|
consume = function(self, capture, ...)
|
|
self:increment(utf8.len(capture))
|
|
return ...
|
|
end,
|
|
|
|
clone = function(self)
|
|
return Source:new(self.name, self.line, self.position)
|
|
end,
|
|
set = function(self, other)
|
|
self.name, self.line, self.position = other.name, other.line, other.position
|
|
end,
|
|
|
|
__tostring = function(self)
|
|
return ("%s:%s:%s"):format(self.name, self.line, self.position)
|
|
end
|
|
}
|
|
|
|
return Source
|