logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

erlang.lua (3615B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Erlang LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('erlang')
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  11. 'after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if', 'let', 'of', 'query', 'receive',
  12. 'try', 'when',
  13. -- Operators.
  14. 'div', 'rem', 'or', 'xor', 'bor', 'bxor', 'bsl', 'bsr', 'and', 'band', 'not', 'bnot', 'badarg',
  15. 'nocookie', 'orelse', 'andalso', 'false', 'true'
  16. }))
  17. -- Functions.
  18. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  19. 'abs', 'alive', 'apply', 'atom_to_list', 'binary_to_list', 'binary_to_term', 'concat_binary',
  20. 'date', 'disconnect_node', 'element', 'erase', 'exit', 'float', 'float_to_list', 'get',
  21. 'get_keys', 'group_leader', 'halt', 'hd', 'integer_to_list', 'is_alive', 'is_record', 'length',
  22. 'link', 'list_to_atom', 'list_to_binary', 'list_to_float', 'list_to_integer', 'list_to_pid',
  23. 'list_to_tuple', 'load_module', 'make_ref', 'monitor_node', 'node', 'nodes', 'now', 'open_port',
  24. 'pid_to_list', 'process_flag', 'process_info', 'process', 'put', 'register', 'registered',
  25. 'round', 'self', 'setelement', 'size', 'spawn', 'spawn_link', 'split_binary', 'statistics',
  26. 'term_to_binary', 'throw', 'time', 'tl', 'trunc', 'tuple_to_list', 'unlink', 'unregister',
  27. 'whereis',
  28. -- Others.
  29. 'any', 'atom', 'binary', 'bitstring', 'byte', 'constant', 'function', 'integer', 'list', 'map',
  30. 'mfa', 'non_neg_integer', 'number', 'pid', 'ports', 'port_close', 'port_info', 'pos_integer',
  31. 'reference', 'record',
  32. -- Erlang.
  33. 'check_process_code', 'delete_module', 'get_cookie', 'hash', 'math', 'module_loaded', 'preloaded',
  34. 'processes', 'purge_module', 'set_cookie', 'set_node',
  35. -- Math.
  36. 'acos', 'asin', 'atan', 'atan2', 'cos', 'cosh', 'exp', 'log', 'log10', 'min', 'max', 'pi', 'pow',
  37. 'power', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
  38. }))
  39. -- Identifiers.
  40. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.lower * ('_' + lexer.alnum)^0))
  41. -- Variables.
  42. lex:add_rule('variable', token(lexer.VARIABLE, P('_')^0 * lexer.upper * ('_' + lexer.alnum)^0))
  43. -- Directives.
  44. lex:add_rule('directive', token(lexer.PREPROCESSOR, '-' * word_match{
  45. 'author', 'behaviour', 'behavior', 'compile', 'copyright', 'define', 'doc', 'else', 'endif',
  46. 'export', 'file', 'ifdef', 'ifndef', 'import', 'include', 'include_lib', 'module', 'record',
  47. 'spec', 'type', 'undef'
  48. }))
  49. -- Strings.
  50. local sq_str = lexer.range("'", true)
  51. local dq_str = lexer.range('"')
  52. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + '$' * lexer.any * lexer.alnum^0))
  53. -- Comments.
  54. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%')))
  55. -- Numbers.
  56. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  57. -- Operators.
  58. lex:add_rule('operator', token(lexer.OPERATOR, S('-<>.;=/|+*:,!()[]{}')))
  59. -- Preprocessor.
  60. lex:add_rule('preprocessor', token(lexer.TYPE, '?' * lexer.word))
  61. -- Records.
  62. lex:add_rule('type', token(lexer.TYPE, '#' * lexer.word))
  63. -- Fold points.
  64. lex:add_fold_point(lexer.KEYWORD, 'case', 'end')
  65. lex:add_fold_point(lexer.KEYWORD, 'fun', 'end')
  66. lex:add_fold_point(lexer.KEYWORD, 'if', 'end')
  67. lex:add_fold_point(lexer.KEYWORD, 'query', 'end')
  68. lex:add_fold_point(lexer.KEYWORD, 'receive', 'end')
  69. lex:add_fold_point(lexer.OPERATOR, '(', ')')
  70. lex:add_fold_point(lexer.OPERATOR, '[', ']')
  71. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  72. lexer.property['scintillua.comment'] = '%'
  73. return lex