blob: c31e606aeb5f6fab3ec0d0ce089c1a9743ec46bf (
plain) (
blame)
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
|
local patok = require 'patok'
local lexer = patok {
keyword = {
'local',
'function',
'return',
'end',
},
equal = '=',
left_paren = '%(',
right_paren = '%)',
}{
identifier = '[%w_][%w%d_]*',
whitespace = { '%s+', drop = true },
number = '%d+',
op = '[+%-*/]',
}()
local source = [[
local function getSalary(hour)
return hour * 60 + 12
end
local bills = 40
local savings = getSalary(4) - bills
]]
lexer:reset(source)
local token = lexer:next()
while token ~= nil do
print(token.value)
token = lexer:next()
end
|