diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-14 16:59:55 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-14 16:59:55 +0800 |
commit | 2a29458c86628a2af20da4ebeb39a8f81d4ea53a (patch) | |
tree | 92d337224429ab516ec2271b117319c5d5916452 /script/parser/tokens.lua | |
parent | 321fc84cabff0252f25e94df14746b8e9cb3d190 (diff) | |
download | lua-language-server-2a29458c86628a2af20da4ebeb39a8f81d4ea53a.zip |
update parser
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 |