summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/parser/newparser.lua29
-rw-r--r--test.lua2
-rw-r--r--test/hover/init.lua12
-rw-r--r--test/type_inference/init.lua9
4 files changed, 27 insertions, 25 deletions
diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua
index 0e12ab45..9721526c 100644
--- a/script/parser/newparser.lua
+++ b/script/parser/newparser.lua
@@ -2340,17 +2340,26 @@ function parseExp(asAction, level)
if uop then
skipSpace()
local child = parseExp(asAction, uopLevel)
- exp = {
- type = 'unary',
- op = uop,
- start = uop.start,
- finish = child and child.finish or uop.finish,
- [1] = child,
- }
- if child then
- child.parent = exp
+ -- 预计算负数
+ if uop.type == '-'
+ and child
+ and (child.type == 'number' or child.type == 'integer') then
+ child.start = uop.start
+ child[1] = - child[1]
+ exp = child
else
- missExp()
+ exp = {
+ type = 'unary',
+ op = uop,
+ start = uop.start,
+ finish = child and child.finish or uop.finish,
+ [1] = child,
+ }
+ if child then
+ child.parent = exp
+ else
+ missExp()
+ end
end
else
exp = parseExpUnit()
diff --git a/test.lua b/test.lua
index 9e3e3125..d2e2c38a 100644
--- a/test.lua
+++ b/test.lua
@@ -10,7 +10,7 @@ ROOT = fs.path(rootPath)
TEST = true
DEVELOP = true
--FOOTPRINT = true
-TRACE = true
+--TRACE = true
LOGPATH = LOGPATH or (ROOT .. '/log')
METAPATH = METAPATH or (ROOT .. '/meta')
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 3f07ea30..c16e466d 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -1,7 +1,6 @@
local core = require 'core.hover'
-local findSource = require 'core.find-source'
-local getLabel = require 'core.hover.label'
local files = require 'files'
+local catch = require 'catch'
rawset(_G, 'TEST', true)
@@ -23,12 +22,9 @@ local accept = {
function TEST(script)
return function (expect)
files.removeAll()
- local start = script:find('<?', 1, true)
- local finish = script:find('?>', 1, true)
- local pos = (start + finish) // 2 + 1
- local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- files.setText('', new_script)
- local hover = core.byUri('', pos)
+ local newScript, catched = catch(script, '?')
+ files.setText('', newScript)
+ local hover = core.byUri('', catched['?'][1][1])
assert(hover)
expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
local label = tostring(hover):match('```lua[\r\n]*(.-)[\r\n]*```'):gsub('\r\n', '\n')
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index a20a96e9..286d47cb 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -1,8 +1,8 @@
local files = require 'files'
-local vm = require 'vm'
local guide = require 'parser.guide'
local infer = require 'core.infer'
local config = require 'config'
+local catch = require 'catch'
rawset(_G, 'TEST', true)
@@ -24,12 +24,9 @@ end
function TEST(wanted)
return function (script)
files.removeAll()
- local start = script:find('<?', 1, true)
- local finish = script:find('?>', 1, true)
- local pos = (start + finish) // 2 + 1
- local newScript = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
+ local newScript, catched = catch(script, '?')
files.setText('', newScript)
- local source = getSource(pos)
+ local source = getSource(catched['?'][1][1])
assert(source)
local result = infer.searchAndViewInfers(source)
if wanted ~= result then