summaryrefslogtreecommitdiff
path: root/script/parser/tokens.lua
blob: 958f292e26da44d45a6ece8055631e6073a7ce8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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