Compare commits
2 Commits
444a5590cd
...
b88cc3a85e
Author | SHA1 | Date |
---|---|---|
Starfflame | b88cc3a85e | |
Starfflame | 119da5673d |
|
@ -53,7 +53,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
function CoreHelpers.parseToken(state: Environment): string
|
function CoreHelpers.parseToken(state: Environment): string
|
||||||
local chr = state.activeInputStream:readCurrentCharacter()
|
local chr = ""
|
||||||
local token = ""
|
local token = ""
|
||||||
while(not CoreHelpers.isWhitespace(chr)) do
|
while(not CoreHelpers.isWhitespace(chr)) do
|
||||||
token = token..chr
|
token = token..chr
|
||||||
|
|
|
@ -3,7 +3,6 @@ local type InputStream = record
|
||||||
offset: number
|
offset: number
|
||||||
refill: function(): string
|
refill: function(): string
|
||||||
|
|
||||||
new: function(InputStream): InputStream
|
|
||||||
new: function(InputStream, function(): string): InputStream
|
new: function(InputStream, function(): string): InputStream
|
||||||
|
|
||||||
setRefill: function(InputStream, function(): string)
|
setRefill: function(InputStream, function(): string)
|
||||||
|
@ -19,28 +18,36 @@ function InputStream:_manageBuffer()
|
||||||
self.str = self.refill()
|
self.str = self.refill()
|
||||||
self.offset = 1
|
self.offset = 1
|
||||||
end
|
end
|
||||||
if self.offset > #self.str + 1 then
|
if self.offset > #self.str then
|
||||||
self.str = self.refill()
|
self.str = self.refill()
|
||||||
self.offset = 1
|
self.offset = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function initial_stream(): string
|
||||||
|
return "DUMMY"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- constructors
|
-- constructors
|
||||||
function InputStream:new(): InputStream
|
function InputStream:new(): InputStream
|
||||||
return setmetatable(
|
|
||||||
{
|
|
||||||
string = "",
|
|
||||||
offset = 1
|
|
||||||
} as InputStream,
|
|
||||||
istream_mt)
|
|
||||||
end
|
|
||||||
function InputStream:new(refill: function(): string): InputStream
|
|
||||||
local mt = setmetatable(
|
local mt = setmetatable(
|
||||||
{
|
{
|
||||||
string = "",
|
string = "",
|
||||||
offset = 1
|
offset = 1,
|
||||||
|
refill = initial_stream
|
||||||
|
} as InputStream,
|
||||||
|
istream_mt)
|
||||||
|
mt:setRefill(initial_stream)
|
||||||
|
return mt
|
||||||
|
end
|
||||||
|
function InputStream:new(refill: function(): string): InputStream
|
||||||
|
refill = refill or initial_stream
|
||||||
|
local mt = setmetatable(
|
||||||
|
{
|
||||||
|
string = "",
|
||||||
|
offset = 1,
|
||||||
|
refill = function(): string return "DUMMY" end
|
||||||
} as InputStream,
|
} as InputStream,
|
||||||
istream_mt)
|
istream_mt)
|
||||||
mt:setRefill(refill)
|
mt:setRefill(refill)
|
||||||
|
@ -53,6 +60,7 @@ end
|
||||||
-- setters/getters
|
-- setters/getters
|
||||||
function InputStream:setRefill(func: function(): string)
|
function InputStream:setRefill(func: function(): string)
|
||||||
self.refill = func
|
self.refill = func
|
||||||
|
self:_manageBuffer()
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -62,9 +70,10 @@ function InputStream:readCurrentCharacter(): string
|
||||||
end
|
end
|
||||||
|
|
||||||
function InputStream:advanceOffset(): string
|
function InputStream:advanceOffset(): string
|
||||||
self.offset = self.offset + 1
|
|
||||||
self:_manageBuffer()
|
self:_manageBuffer()
|
||||||
return self.str:sub(self.offset, self.offset)
|
local current_char = self.str:sub(self.offset, self.offset)
|
||||||
|
self.offset = self.offset + 1
|
||||||
|
return current_char
|
||||||
end
|
end
|
||||||
|
|
||||||
return InputStream
|
return InputStream
|
||||||
|
|
Loading…
Reference in New Issue