ui: add support for blink style attribute
[vis.git] / lexers / erlang.lua
bloba741d63418e4d5b97c6e242586c24a64648e8350
1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Erlang LPeg lexer.
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'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, '%' * l.nonnewline^0)
16 -- Strings.
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)
22 -- Numbers.
23 local number = token(l.NUMBER, l.float + l.integer)
25 -- Keywords.
26 local keyword = token(l.KEYWORD, word_match{
27 'after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if', 'let', 'of',
28 'query', 'receive', 'when',
29 -- Operators.
30 'div', 'rem', 'or', 'xor', 'bor', 'bxor', 'bsl', 'bsr', 'and', 'band', 'not',
31 'bnot',
32 'badarg', 'nocookie', 'false', 'true'
35 -- Functions.
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',
47 'whereis',
48 -- Others.
49 'atom', 'binary', 'constant', 'function', 'integer', 'list', 'number', 'pid',
50 'ports', 'port_close', 'port_info', 'reference', 'record',
51 -- Erlang:.
52 'check_process_code', 'delete_module', 'get_cookie', 'hash', 'math',
53 'module_loaded', 'preloaded', 'processes', 'purge_module', 'set_cookie',
54 'set_node',
55 -- Math.
56 'acos', 'asin', 'atan', 'atan2', 'cos', 'cosh', 'exp', 'log', 'log10', 'pi',
57 'pow', 'power', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
60 -- Identifiers.
61 local identifier = token(l.IDENTIFIER, l.word)
63 -- Operators.
64 local operator = token(l.OPERATOR, S('-<>.;=/|#+*:,?!()[]{}'))
66 -- Directives.
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',
70 'record', 'undef'
73 M._rules = {
74 {'whitespace', ws},
75 {'keyword', keyword},
76 {'function', func},
77 {'identifier', identifier},
78 {'directive', directive},
79 {'string', string},
80 {'comment', comment},
81 {'number', number},
82 {'operator', operator},
85 M._tokenstyles = {
86 directive = l.STYLE_PREPROCESSOR
89 M._foldsymbols = {
90 _patterns = {'[a-z]+', '[%(%)%[%]{}]', '%%'},
91 [l.KEYWORD] = {
92 case = 1, fun = 1, ['if'] = 1, query = 1, receive = 1, ['end'] = -1
94 [l.OPERATOR] = {
95 ['('] = 1, [')'] = -1, ['['] = 1, [']'] = -1, ['{'] = 1, ['}'] = -1
97 [l.COMMENT] = {['%'] = l.fold_line_comments('%')}
100 return M