summaryrefslogtreecommitdiff
path: root/script/parser/tokens.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-24 15:08:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-24 15:08:02 +0800
commit4b085b8aea5f33ec114baa31d2b9d72341383c32 (patch)
treefe35a326408e762711a31d3e803464f0c1a8468d /script/parser/tokens.lua
parent0c8c6bbf23082d0b858646846a47a3001f718ae2 (diff)
parent35ce57976db3b4c42193279dd55972ea013fecad (diff)
downloadlua-language-server-4b085b8aea5f33ec114baa31d2b9d72341383c32.zip
Merge branch 'newparser'
Diffstat (limited to 'script/parser/tokens.lua')
-rw-r--r--script/parser/tokens.lua38
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