-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelixir_lexer.moon
62 lines (54 loc) · 1.59 KB
/
elixir_lexer.moon
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
howl.util.lpeg_lexer ->
kw = capture 'keyword', word {
'cond','case', 'defmodule', 'defstruct', 'defmacro',
'defprotocol', 'defexception', 'defdelegate',
'defimpl', 'try','catch', 'do', 'end', 'after',
'if', 'else', 'unless', 'fn','defp','def',
'and', 'or', 'rescue', 'receive', 'alias', 'use',
'require', 'import', 'for', 'when'
}
comment = capture 'comment', '#' * scan_until(eol)
string = capture 'string', any {
'"""' * (P(1) - P('"""'))^0 * '"""',
span("'", "'", '\\'),
span('"', '"', '\\')
}
operator = capture 'operator', S('+-*!/%^#~=<>;,.&(){}[]|?')
hexadecimal_number = P'0' * S'xX' * xdigit^1 * (P'.' * xdigit^1)^0 * (S'pP' * S'-+'^0 * xdigit^1)^0
float = digit^1 * P'.' * digit^1
number = capture 'number', any({
hexadecimal_number * any('LL', 'll', 'ULL', 'ull')^-1,
digit^1 * any { 'LL', 'll', 'ULL', 'ull' },
(float + digit^1) * (S'eE' * P('-')^0 * digit^1)^0
})
ident = (alpha + '_')^1 * (alpha + digit + '_')^0 * S('!?')^-1
identifier = capture 'identifier', ident
module = capture 'class', upper^1 * any(alpha, '_', digit)^0
special = capture 'special', any {
'true',
'false',
'nil',
ident * P(':'),
P(':') * ident,
P('@') * ident,
P('~') * alpha * any {
span('/','/','\\'),
span('|','|','\\'),
span('"','"','\\'),
span('\'','\'','\\'),
span('(',')','\\'),
span('[',']','\\'),
span('{','}','\\'),
span('<','>','\\'),
} * lower^-1
}
any {
number,
string,
comment,
special,
kw,
module,
identifier,
operator
}