diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-24 15:08:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-24 15:08:02 +0800 |
commit | 4b085b8aea5f33ec114baa31d2b9d72341383c32 (patch) | |
tree | fe35a326408e762711a31d3e803464f0c1a8468d /script/parser/tokens.lua | |
parent | 0c8c6bbf23082d0b858646846a47a3001f718ae2 (diff) | |
parent | 35ce57976db3b4c42193279dd55972ea013fecad (diff) | |
download | lua-language-server-4b085b8aea5f33ec114baa31d2b9d72341383c32.zip |
Merge branch 'newparser'
Diffstat (limited to 'script/parser/tokens.lua')
-rw-r--r-- | script/parser/tokens.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/script/parser/tokens.lua b/script/parser/tokens.lua new file mode 100644 index 00000000..958f292e --- /dev/null +++ b/script/parser/tokens.lua @@ -0,0 +1,38 @@ +local m = require 'lpeglabel' + +local Sp = m.S' \t' +local Nl = m.P'\r\n' + m.S'\r\n' +local Number = m.R'09'^1 +local Word = m.R('AZ', 'az', '__', '\x80\xff') * m.R('AZ', 'az', '09', '__', '\x80\xff')^0 +local Symbol = m.P'==' + + m.P'~=' + + m.P'--' + + m.P'<<' + + m.P'>>' + + m.P'<=' + + m.P'>=' + + m.P'//' + + m.P'...' + + m.P'..' + + m.P'::' + -- incorrect + + m.P'!=' + + m.P'&&' + + m.P'||' + + m.P'/*' + + m.P'*/' + + m.P'+=' + + m.P'-=' + + m.P'*=' + + m.P'/=' + -- singles + + m.S'+-*/!#%^&()={}[]|\\\'":;<>,.?~`' +local Unknown = (1 - Number - Word - Symbol - Sp - Nl)^1 +local Token = m.Cp() * m.C(Nl + Number + Word + Symbol + Unknown) + +local Parser = m.Ct((Sp^1 + Token)^0) + +return function (lua) + local results = Parser:match(lua) + return results +end |