summaryrefslogtreecommitdiff
path: root/script/parser/tokens.lua
blob: a4de7f88b1bf60ed4befe0be6b6aef90e658b9ca (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
39
40
41
42
43
44
45
46
47
48
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'--'
            -- non-standard:
            +  m.P'<<='
            +  m.P'>>='
            +  m.P'//='
            -- end non-standard
            +  m.P'<<'
            +  m.P'>>'
            +  m.P'<='
            +  m.P'>='
            +  m.P'//'
            +  m.P'...'
            +  m.P'..'
            +  m.P'::'
            -- non-standard:
            +  m.P'!='
            +  m.P'&&'
            +  m.P'||'
            +  m.P'/*'
            +  m.P'*/'
            +  m.P'+='
            +  m.P'-='
            +  m.P'*='
            +  m.P'%='
            +  m.P'&='
            +  m.P'|='
            +  m.P'^='
            +  m.P'/='
            -- end non-standard
            -- 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