1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
8 local M
= {_NAME
= 'erlang'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local comment
= token(l
.COMMENT
, '%' * l
.nonnewline^
0)
17 local sq_str
= l
.delimited_range("'", true)
18 local dq_str
= l
.delimited_range('"')
19 local literal
= '$' * l
.any
* l
.alnum^
0
20 local string = token(l
.STRING
, sq_str
+ dq_str
+ literal
)
23 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
26 local keyword
= token(l
.KEYWORD
, word_match
{
27 'after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if', 'let', 'of',
28 'query', 'receive', 'when',
30 'div', 'rem', 'or', 'xor', 'bor', 'bxor', 'bsl', 'bsr', 'and', 'band', 'not',
32 'badarg', 'nocookie', 'false', 'true'
36 local func
= token(l
.FUNCTION
, word_match
{
37 'abs', 'alive', 'apply', 'atom_to_list', 'binary_to_list', 'binary_to_term',
38 'concat_binary', 'date', 'disconnect_node', 'element', 'erase', 'exit',
39 'float', 'float_to_list', 'get', 'get_keys', 'group_leader', 'halt', 'hd',
40 'integer_to_list', 'is_alive', 'length', 'link', 'list_to_atom',
41 'list_to_binary', 'list_to_float', 'list_to_integer', 'list_to_pid',
42 'list_to_tuple', 'load_module', 'make_ref', 'monitor_node', 'node', 'nodes',
43 'now', 'open_port', 'pid_to_list', 'process_flag', 'process_info', 'process',
44 'put', 'register', 'registered', 'round', 'self', 'setelement', 'size',
45 'spawn', 'spawn_link', 'split_binary', 'statistics', 'term_to_binary',
46 'throw', 'time', 'tl', 'trunc', 'tuple_to_list', 'unlink', 'unregister',
49 'atom', 'binary', 'constant', 'function', 'integer', 'list', 'number', 'pid',
50 'ports', 'port_close', 'port_info', 'reference', 'record',
52 'check_process_code', 'delete_module', 'get_cookie', 'hash', 'math',
53 'module_loaded', 'preloaded', 'processes', 'purge_module', 'set_cookie',
56 'acos', 'asin', 'atan', 'atan2', 'cos', 'cosh', 'exp', 'log', 'log10', 'pi',
57 'pow', 'power', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
61 local identifier
= token(l
.IDENTIFIER
, l
.word
)
64 local operator
= token(l
.OPERATOR
, S('-<>.;=/|#+*:,?!()[]{}'))
67 local directive
= token('directive', '-' * word_match
{
68 'author', 'compile', 'copyright', 'define', 'doc', 'else', 'endif', 'export',
69 'file', 'ifdef', 'ifndef', 'import', 'include_lib', 'include', 'module',
77 {'identifier', identifier
},
78 {'directive', directive
},
82 {'operator', operator
},
86 directive
= l
.STYLE_PREPROCESSOR
90 _patterns
= {'[a-z]+', '[%(%)%[%]{}]', '%%'},
92 case
= 1, fun
= 1, ['if'] = 1, query
= 1, receive
= 1, ['end'] = -1
95 ['('] = 1, [')'] = -1, ['['] = 1, [']'] = -1, ['{'] = 1, ['}'] = -1
97 [l
.COMMENT
] = {['%'] = l
.fold_line_comments('%')}