commit
f24aad1d18
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2015 Benjamin Moir
|
Copyright (c) 2015 Benjamin Moir <bennyboy.private@hotmail.com.au>
|
||||||
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
--[[
|
--[[
|
||||||
|
|
||||||
Copyright (c) 2015 Benjamin Moir
|
Copyright (c) 2015 Benjamin Moir <bennyboy.private@hotmail.com.au>
|
||||||
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
@ -24,7 +24,7 @@ THE SOFTWARE.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local ffi = require("ffi")
|
local ffi = require("ffi")
|
||||||
local parser = {}
|
local tokenizer = {}
|
||||||
|
|
||||||
local loveToken = ffi.load("LoveToken")
|
local loveToken = ffi.load("LoveToken")
|
||||||
ffi.cdef([[
|
ffi.cdef([[
|
||||||
|
@ -66,16 +66,16 @@ LT_Token LT_GetToken();
|
||||||
|
|
||||||
local pReturn
|
local pReturn
|
||||||
|
|
||||||
function parser:init(initInfo, filePath)
|
function tokenizer:init(initInfo, filePath)
|
||||||
loveToken.LT_Init(initInfo)
|
loveToken.LT_Init(initInfo)
|
||||||
loveToken.LT_OpenFile(filePath)
|
loveToken.LT_OpenFile(filePath)
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:assert(assertion, str)
|
function tokenizer:assert(assertion, str)
|
||||||
return loveToken.LT_Assert(assertion, str)
|
return loveToken.LT_Assert(assertion, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:checkError()
|
function tokenizer:checkError()
|
||||||
ltAssertion = loveToken.LT_CheckAssert()
|
ltAssertion = loveToken.LT_CheckAssert()
|
||||||
|
|
||||||
if (ltAssertion.str == nil) then
|
if (ltAssertion.str == nil) then
|
||||||
|
@ -85,43 +85,50 @@ function parser:checkError()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:openFile(filePath)
|
function tokenizer:openFile(filePath)
|
||||||
pReturn = loveToken.LT_OpenFile(filePath)
|
pReturn = loveToken.LT_OpenFile(filePath)
|
||||||
parser:checkError()
|
tokenizer:checkError()
|
||||||
return pReturn
|
return pReturn
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:closeFile()
|
function tokenizer:closeFile()
|
||||||
loveToken.LT_CloseFile()
|
loveToken.LT_CloseFile()
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:quit()
|
function tokenizer:quit()
|
||||||
loveToken.LT_CloseFile()
|
loveToken.LT_CloseFile()
|
||||||
loveToken.LT_Quit()
|
loveToken.LT_Quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:readNumber()
|
function tokenizer:readNumber()
|
||||||
pReturn = loveToken.LT_ReadNumber()
|
pReturn = loveToken.LT_ReadNumber()
|
||||||
parser:checkError()
|
tokenizer:checkError()
|
||||||
return ffi.string(pReturn)
|
return ffi.string(pReturn)
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:readString(term)
|
function tokenizer:readString(term)
|
||||||
pReturn = loveToken.LT_ReadString(term)
|
pReturn = loveToken.LT_ReadString(term)
|
||||||
parser:checkError()
|
tokenizer:checkError()
|
||||||
return ffi.string(pReturn)
|
return ffi.string(pReturn)
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:escaper(str, pos, escape)
|
function tokenizer:escaper(str, pos, escape)
|
||||||
pReturn = loveToken.LT_Escaper(str, pos, escape)
|
pReturn = loveToken.LT_Escaper(str, pos, escape)
|
||||||
parser:checkError()
|
tokenizer:checkError()
|
||||||
return ffi.string(pReturn)
|
return ffi.string(pReturn)
|
||||||
end
|
end
|
||||||
|
|
||||||
function parser:getToken()
|
function tokenizer:getToken()
|
||||||
pReturn = loveToken.LT_GetToken()
|
pReturn = loveToken.LT_GetToken()
|
||||||
parser:checkError()
|
tokenizer:checkError()
|
||||||
return pReturn
|
local lt = {}
|
||||||
|
lt.token = ffi.string(pReturn.token)
|
||||||
|
lt.string = pReturn.string
|
||||||
|
lt.pos = pReturn.pos
|
||||||
|
if (pReturn.string ~= nil) then
|
||||||
|
lt.string = ffi.string(pReturn.string)
|
||||||
|
end
|
||||||
|
return lt
|
||||||
end
|
end
|
||||||
|
|
||||||
return parser
|
return tokenizer
|
2
src/lt.c
2
src/lt.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2015 Benjamin Moir
|
Copyright (c) 2015 Benjamin Moir <bennyboy.private@hotmail.com.au>
|
||||||
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
|
2
src/lt.h
2
src/lt.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2015 Benjamin Moir
|
Copyright (c) 2015 Benjamin Moir <bennyboy.private@hotmail.com.au>
|
||||||
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
|
Reference in New Issue
Block a user