diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/config.lua | 1 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 8 | ||||
-rw-r--r-- | script/files.lua | 1 | ||||
-rw-r--r-- | script/parser/ast.lua | 123 | ||||
-rw-r--r-- | script/parser/grammar.lua | 16 |
5 files changed, 117 insertions, 32 deletions
diff --git a/script/config.lua b/script/config.lua index 74f2ff4e..f5e0f391 100644 --- a/script/config.lua +++ b/script/config.lua @@ -104,6 +104,7 @@ local ConfigTemplate = { special = {{}, Hash(String, String)}, meta = {'${version} ${language}', String}, unicodeName = {false, Boolean}, + nonstandardSymbol = {{}, Str2Hash ';'}, }, diagnostics = { enable = {true, Boolean}, diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 170bffa8..cd4a0086 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -120,6 +120,14 @@ Care['doc.type.name'] = function (source, results) end end +Care['nonstandardSymbol.comment'] = function (source, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.comment, + } +end + local function buildTokens(results, text, lines) local tokens = {} local lastLine = 0 diff --git a/script/files.lua b/script/files.lua index f5f2f1c5..3a8f93ad 100644 --- a/script/files.lua +++ b/script/files.lua @@ -248,6 +248,7 @@ function m.compileAst(uri, text) , { special = config.config.runtime.special, unicodeName = config.config.runtime.unicodeName, + alias = config.config.runtime.alias, } ) local passed = os.clock() - clock 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 |