diff --git a/example1.lua b/examples/example1.lua similarity index 100% rename from example1.lua rename to examples/example1.lua diff --git a/try_luaxp.lua b/examples/try_luaxp.lua similarity index 100% rename from try_luaxp.lua rename to examples/try_luaxp.lua diff --git a/luaxp.lua b/luaxp.lua index d1663d7..43a4314 100644 --- a/luaxp.lua +++ b/luaxp.lua @@ -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 @@ -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+$", "") @@ -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) diff --git a/rockspec/luaxp-1.0.1-1.rockspec b/rockspec/luaxp-1.0.1-1.rockspec new file mode 100644 index 0000000..943afbc --- /dev/null +++ b/rockspec/luaxp-1.0.1-1.rockspec @@ -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", + } +} \ No newline at end of file