summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/definition.lua70
-rw-r--r--server/src/parser/grammar.lua24
-rw-r--r--server/test/definition/table.lua24
3 files changed, 98 insertions, 20 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua
index 09081cdb..a8f99a18 100644
--- a/server/src/matcher/definition.lua
+++ b/server/src/matcher/definition.lua
@@ -5,6 +5,7 @@ local defs = {}
local scopes
local result
local namePos
+local nameFinishPos
local colonPos
local DUMMY_TABLE = {}
@@ -100,8 +101,10 @@ end
local function checkName(obj)
local name = obj[1]
- local p = obj[2]
- if pos < p or pos > p + #name then
+ local start = obj[2]
+ local str = obj.string or name
+ local finish = obj[3] or (start + #str)
+ if pos < start or pos > finish then
return
end
result = {
@@ -118,8 +121,10 @@ local function checkSimple(simple)
local obj = simple[i]
if obj.type == 'name' then
local name = obj[1]
- local p = obj[2]
- if pos >= p and pos <= p + #name then
+ local start = obj[2]
+ local str = obj.string or name
+ local finish = obj[3] or (start + #str)
+ if pos >= start and pos <= finish then
result = {
type = 'simple',
table = scopeGetSimple(simple, i-1),
@@ -135,17 +140,48 @@ function defs.NamePos(p)
end
function defs.Name(str)
- local obj = {str, namePos, type = 'name'}
+ local obj = {'STRING|' .. str, namePos, string = str, type = 'name'}
checkName(obj)
return obj
end
+function defs.TRUE(p)
+ local obj = {'true', p, type = 'name'}
+ return obj
+end
+
+function defs.FALSE(p)
+ local obj = {'false', p, type = 'name'}
+ return obj
+end
+
+function defs.NumberPos(p)
+ namePos = p
+end
+
+function defs.Number(str)
+ local dump = ('%q'):format(tonumber(str))
+ local obj = {'NUMBER|' .. dump, namePos, string = str, type = 'name'}
+ return obj
+end
+
+function defs.String(start, str, finish)
+ local obj = {
+ 'STRING|' .. str,
+ start,
+ finish-1,
+ string = str,
+ type = 'name'
+ }
+ return obj
+end
+
function defs.DOTSPos(p)
namePos = p
end
-function defs.DOTS(str)
- local obj = {str, namePos, type = 'name'}
+function defs.DOTS()
+ local obj = {'...', namePos, type = 'name'}
checkName(obj)
return obj
end
@@ -206,7 +242,13 @@ function defs.FunctionDef(simple, args)
if #simple > 0 then
local name = simple[#simple]
if name.colon then
- scopeLocal {'self', name.colon, name.colon, type = 'name'}
+ scopeLocal {
+ 'STRING|self',
+ name.colon,
+ name.colon,
+ string = 'self',
+ type = 'name'
+ }
end
end
for _, arg in ipairs(args) do
@@ -229,7 +271,13 @@ function defs.FunctionLoc(simple, args)
if #simple > 0 then
local name = simple[#simple]
if name.colon then
- scopeLocal {'self', name.colon, name.colon, type = 'name'}
+ scopeLocal {
+ 'STRING|self',
+ name.colon,
+ name.colon,
+ string = 'self',
+ type = 'name'
+ }
end
end
for _, arg in ipairs(args) do
@@ -341,12 +389,12 @@ local function parseResult(callback)
return
end
- local name, start, finish = obj[1], obj[2], obj[3]
+ local str, start, finish = (obj.string or obj[1]), obj[2], obj[3]
if not start then
return
end
if not finish then
- finish = start + #name - 1
+ finish = start + #str - 1
end
callback(start, finish)
end
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index bf1758e3..22fe8f9c 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -76,7 +76,8 @@ DO <- Sp 'do' Cut
ELSE <- Sp 'else' Cut
ELSEIF <- Sp 'elseif' Cut
END <- Sp 'end' Cut
-FALSE <- Sp 'false' Cut
+FALSE <- Sp {} -> FALSE
+ 'false' Cut
FOR <- Sp 'for' Cut
FUNCTION <- Sp 'function' Cut
GOTO <- Sp 'goto' Cut
@@ -89,7 +90,8 @@ OR <- Sp 'or' Cut
REPEAT <- Sp 'repeat' Cut
RETURN <- Sp 'return' Cut
THEN <- Sp 'then' Cut
-TRUE <- Sp 'true' Cut
+TRUE <- Sp {} -> TRUE
+ 'true' Cut
UNTIL <- Sp 'until' Cut
WHILE <- Sp 'while' Cut
@@ -166,15 +168,17 @@ Boolean <- TRUE
]]
grammar 'String' [[
-String <- Sp StringDef
-StringDef <- '"' (Esc / !%nl !'"' .)* '"'
- / "'" (Esc / !%nl !"'" .)* "'"
- / '[' {:eq: '='* :} '[' StringClose
-StringClose <- ']' =eq ']' / . StringClose
+String <- Sp ({} StringDef {})
+ -> String
+StringDef <- '"' {(Esc / !%nl !'"' .)*} '"'
+ / "'" {(Esc / !%nl !"'" .)*} "'"
+ / '[' {:eq: '='* :} '[' {(!StringClose .)*} StringClose
+StringClose <- ']' =eq ']'
]]
grammar 'Number' [[
-Number <- Sp NumberDef
+Number <- Sp {} -> NumberPos
+ NumberDef -> Number
NumberDef <- Number16 / Number10
Number10 <- Integer10 Float10
@@ -233,7 +237,9 @@ ArgList <- (Arg (COMMA Arg)*)?
Arg <- DOTS
/ Exp
-Table <- TL TableFields? TR
+Table <- TL
+ TableFields?
+ TR
TableFields <- TableField (TableSep TableField)* TableSep?
TableSep <- COMMA / SEMICOLON
TableField <- NewIndex / NewField / Exp
diff --git a/server/test/definition/table.lua b/server/test/definition/table.lua
index 4f5d9095..addf0a66 100644
--- a/server/test/definition/table.lua
+++ b/server/test/definition/table.lua
@@ -25,3 +25,27 @@ local t
t.<!x!> = 1
t.<?x?>()
]]
+
+TEST [[
+local t
+t[<!1!>] = 1
+t[<?1?>]()
+]]
+
+TEST [[
+local t
+t[<!true!>] = 1
+t[<?true?>]()
+]]
+
+TEST [[
+local t
+t[<!"method"!>] = 1
+t[<?"method"?>]()
+]]
+
+TEST [[
+local t
+t[<!"method"!>] = 1
+t[<?[==[method]==]?>]()
+]]