Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
13 changes: 11 additions & 2 deletions luaxp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ local TNUL = 'null'
local NULLATOM = { __type=TNUL }
setmetatable( NULLATOM, { __tostring=function() return "null" end } )

local charmap = { t = "\t", r = "\r", n = "\n" }
local charmap = { t = "\t", r = "\r", n = "\n",
["\\"] = "\\", ["'"] = "'", ['"'] = '"' }

local reservedWords = {
['false']=false, ['true']=true
Expand Down Expand Up @@ -440,6 +441,14 @@ local function xp_mktime( yy, mm, dd, hours, mins, secs )
return os.time(pt)
end

local function xp_enquote(s, q)
if base.type(s) ~= "string" then evalerror("String required") end
if q ~= "'" and q ~= '"' then evalerror("Illegal quotation mark") end
s = s:gsub("\\", "\\\\")
s = s:gsub(q, "\\" .. q)
return q .. s .. q
end

local function xp_rtrim(s)
if base.type(s) ~= "string" then evalerror("String required") end
return s:gsub("%s+$", "")
Expand Down Expand Up @@ -747,7 +756,7 @@ local function scan_fref( expr, index, name )
-- Start of string?
local qq = ch
index, ch = scan_string( expr, index )
subexp = subexp .. qq .. ch.value .. qq
subexp = subexp .. xp_enquote(ch.value, qq)
elseif ch == ',' and parenLevel == 1 then -- completed subexpression
subexp = xp_trim( subexp )
D("scan_fref: handling argument=%1", subexp)
Expand Down
21 changes: 21 additions & 0 deletions rockspec/luaxp-1.0.1-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package = "luaxp"
version = "1.0.1-1"
source = {
url = "git://github.com/toggledbits/luaxp",
}
description = {
summary = "Luaxp is a simple arithmetic expression parser for Lua.",
detailed = [[Luaxp supports simple mathemtical expressions for addition, subtraction,
multiplication, division, modulus, bitwise operations, and logical operations.]],
homepage = "http://www.toggledbits.com/luaxp",
license = "MIT",
}
dependencies = {
"lua >= 5.1",
}
build = {
type="builtin",
modules = {
luaxp = "luaxp.lua",
}
}