summaryrefslogtreecommitdiff
path: root/script/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-22 15:57:47 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-22 15:57:47 +0800
commit92849eba811da2edc64ce352f711cabfebe23717 (patch)
tree57f7df5576b0118e176329a17b9ed3d95f0612c1 /script/parser
parent103b911a7827b6f6e169f38242b00f72e0507944 (diff)
downloadlua-language-server-92849eba811da2edc64ce352f711cabfebe23717.zip
#317 support nonstandard symbol
Diffstat (limited to 'script/parser')
-rw-r--r--script/parser/ast.lua123
-rw-r--r--script/parser/grammar.lua16
2 files changed, 107 insertions, 32 deletions
diff --git a/script/parser/ast.lua b/script/parser/ast.lua
index 34aa49ae..97fed9da 100644
--- a/script/parser/ast.lua
+++ b/script/parser/ast.lua
@@ -48,6 +48,13 @@ local VersionOp = {
['//'] = {'Lua 5.3', 'Lua 5.4'},
}
+local SymbolAlias = {
+ ['||'] = 'or',
+ ['&&'] = 'and',
+ ['!='] = '~=',
+ ['!'] = 'not',
+}
+
local function checkOpVersion(op)
local versions = VersionOp[op.type]
if not versions then
@@ -305,38 +312,54 @@ local Defs = {
end
end,
CLongComment = function (start1, finish1, start2, finish2)
- PushError {
- type = 'ERR_C_LONG_COMMENT',
+ if State.options.nonstandardSymbol and State.options.nonstandardSymbol['/**/'] then
+ else
+ PushError {
+ type = 'ERR_C_LONG_COMMENT',
+ start = start1,
+ finish = finish2 - 1,
+ fix = {
+ title = 'FIX_C_LONG_COMMENT',
+ {
+ start = start1,
+ finish = finish1 - 1,
+ text = '--[[',
+ },
+ {
+ start = start2,
+ finish = finish2 - 1,
+ text = '--]]'
+ },
+ }
+ }
+ end
+ return {
+ type = 'nonstandardSymbol.comment',
start = start1,
finish = finish2 - 1,
- fix = {
- title = 'FIX_C_LONG_COMMENT',
- {
- start = start1,
- finish = finish1 - 1,
- text = '--[[',
- },
- {
- start = start2,
- finish = finish2 - 1,
- text = '--]]'
- },
- }
}
end,
- CCommentPrefix = function (start, finish)
- PushError {
- type = 'ERR_COMMENT_PREFIX',
- start = start,
- finish = finish - 1,
- fix = {
- title = 'FIX_COMMENT_PREFIX',
- {
- start = start,
- finish = finish - 1,
- text = '--',
- },
+ CCommentPrefix = function (start, finish, commentFinish)
+ if State.options.nonstandardSymbol and State.options.nonstandardSymbol['//'] then
+ else
+ PushError {
+ type = 'ERR_COMMENT_PREFIX',
+ start = start,
+ finish = finish - 1,
+ fix = {
+ title = 'FIX_COMMENT_PREFIX',
+ {
+ start = start,
+ finish = finish - 1,
+ text = '--',
+ },
+ }
}
+ end
+ return {
+ type = 'nonstandardSymbol.comment',
+ start = start,
+ finish = commentFinish - 1,
}
end,
String = function (start, quote, str, finish)
@@ -642,6 +665,22 @@ local Defs = {
return call
end,
BinaryOp = function (start, op)
+ if SymbolAlias[op] then
+ PushError {
+ type = 'ERR_NONSTANDARD_SYMBOL',
+ start = start,
+ finish = start + #op - 1,
+ fix = {
+ title = 'FIX_NONSTANDARD_SYMBOL',
+ {
+ start = start,
+ finish = start + #op - 1,
+ text = SymbolAlias[op],
+ },
+ }
+ }
+ op = SymbolAlias[op]
+ end
return {
type = op,
start = start,
@@ -649,6 +688,22 @@ local Defs = {
}
end,
UnaryOp = function (start, op)
+ if SymbolAlias[op] then
+ PushError {
+ type = 'ERR_NONSTANDARD_SYMBOL',
+ start = start,
+ finish = start + #op - 1,
+ fix = {
+ title = 'FIX_NONSTANDARD_SYMBOL',
+ {
+ start = start,
+ finish = start + #op - 1,
+ text = SymbolAlias[op],
+ },
+ }
+ }
+ op = SymbolAlias[op]
+ end
return {
type = op,
start = start,
@@ -1356,6 +1411,20 @@ local Defs = {
}
return block
end,
+ RTContinue = function (_, pos, ...)
+ if State.options.nonstandardSymbol and State.options.nonstandardSymbol['continue'] then
+ return pos, ...
+ else
+ return false
+ end
+ end,
+ Continue = function (start, finish)
+ return {
+ type = 'nonstandardSymbol.continue',
+ start = start,
+ finish = finish - 1,
+ }
+ end,
Lua = function (start, actions, finish)
actions.type = 'main'
actions.start = start
diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua
index fb68d5b9..b5c02aef 100644
--- a/script/parser/grammar.lua
+++ b/script/parser/grammar.lua
@@ -124,6 +124,7 @@ NOT <- Sp 'not' Cut
OR <- Sp {'or'} Cut
RETURN <- Sp 'return' Cut
TRUE <- Sp 'true' Cut
+CONTINUE <- Sp 'continue' Cut
DO <- Sp {} 'do' {} Cut
/ Sp({} 'then' {} Cut) -> ErrDo
@@ -186,9 +187,9 @@ UnaryList <- NOT
/ '~' !'='
POWER <- Sp {'^'}
-BinaryOp <-( Sp {} {'or'} Cut
- / Sp {} {'and'} Cut
- / Sp {} {'<=' / '>=' / '<'!'<' / '>'!'>' / '~=' / '=='}
+BinaryOp <-( Sp {} {'or' / '||'} Cut
+ / Sp {} {'and' / '&&'} Cut
+ / Sp {} {'<=' / '>=' / '<'!'<' / '>'!'>' / '~=' / '==' / '!='}
/ Sp {} ({} '=' {}) -> ErrEQ
/ Sp {} ({} '!=' {}) -> ErrUEQ
/ Sp {} {'|'}
@@ -200,7 +201,7 @@ BinaryOp <-( Sp {} {'or'} Cut
/ Sp {} {'*' / '//' / '/' / '%'}
/ Sp {} {'^'}
)-> BinaryOp
-UnaryOp <-( Sp {} {'not' Cut / '#' / '~' !'=' / '-' !'-'}
+UnaryOp <-( Sp {} {'not' Cut / '#' / '~' !'=' / '-' !'-' / '!' !'='}
)-> UnaryOp
PL <- Sp '('
@@ -408,11 +409,12 @@ CrtAction <- Semicolon
/ LocalFunction
/ Local
/ Set
+ / Continue
/ Call
/ ExpInAction
UnkAction <- ({} {Word+})
-> UnknownAction
- / ({} '//' {} (LongComment / ShortComment))
+ / ({} '//' {} (LongComment / ShortComment) {})
-> CCommentPrefix
/ ({} {. (!Sps !CrtAction .)*})
-> UnknownAction
@@ -431,6 +433,10 @@ Do <- Sp ({}
Break <- Sp ({} BREAK {})
-> Break
+Continue <- Sp ({} CONTINUE {})
+ => RTContinue
+ -> Continue
+
Return <- Sp ({} RETURN ReturnExpList {})
-> Return
ReturnExpList