summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/parser/ast.lua43
-rw-r--r--server/src/parser/grammar.lua19
2 files changed, 41 insertions, 21 deletions
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 6a26f46b..8c5f7fe9 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -258,20 +258,51 @@ local defs = {
return obj
end,
Table = function (start, ...)
+ local args = {...}
+ local max = #args
+ local finish = args[max] - 1
local table = {
type = 'table',
start = start,
- ...,
+ finish = finish
}
- local max = #table
- local finish = table[max]
- table.finish = finish - 1
- table[max] = nil
+ start = start + 1
+ local wantField = true
+ for i = 1, max-1 do
+ local arg = args[i]
+ local isField = type(arg) == 'table'
+ if wantField and not isField then
+ pushError {
+ type = 'MISS_EXP',
+ start = start,
+ finish = arg - 1,
+ }
+ elseif not wantField and isField then
+ pushError {
+ type = 'MISS_SYMBOL',
+ start = start,
+ finish = arg.start-1,
+ info = {
+ symbol = ',',
+ }
+ }
+ end
+ if isField then
+ table[#table+1] = arg
+ wantField = false
+ start = arg.finish + 1
+ else
+ wantField = true
+ start = arg
+ end
+ end
return table
end,
NewField = function (key, value)
return {
type = 'pair',
+ start = key.start,
+ finish = value.finish,
key, value,
}
end,
@@ -279,6 +310,8 @@ local defs = {
key.index = true
return {
type = 'pair',
+ start = key.start,
+ finish = value.finish,
key, value,
}
end,
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index a840a7a0..18118ac6 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -313,25 +313,12 @@ AfterArg <- DOTS
/ MustName
-Table <- ({} TL TR {})
+Table <- Sp ({} TL TableFields DirtyTR {})
-> Table
- / ({} TL TableFields DirtyTR {})
- -> Table
- / ({} TL DirtyTR {})
- -> Table
-TableFields <- TableField
- (TableAfterF)*
- LastTableSep?
- / DirtyExp
- (TableAfterF)+
- LastTableSep?
-TableAfterF <- TableSep !TR TableField
- / Sp ({} {(!TR !COMMA !SEMICOLON !Word !BL .)+})
+TableFields <- (TableSep {} / TableField / DirtyField)*
+DirtyField <- Sp ({} {(!TR !COMMA !SEMICOLON !Word !BL .)+})
-> UnknownSymbol
TableSep <- COMMA / SEMICOLON
- / {}
- -> MissTableSep
-LastTableSep<- COMMA / SEMICOLON
TableField <- NewIndex / NewField / Exp
NewIndex <- (BL DirtyExp DirtyBR DirtyAssign DirtyExp)
-> NewIndex