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

reason.lua (3248B)


  1. -- Copyright 2018-2024 Hugo O. Rivera. See LICENSE.
  2. -- Reason (https://reasonml.github.io/) 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('reason')
  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. 'and', 'as', 'asr', 'begin', 'class', 'closed', 'constraint', 'do', 'done', 'downto', 'else',
  12. 'end', 'exception', 'external', 'failwith', 'false', 'flush', 'for', 'fun', 'function', 'functor',
  13. 'if', 'in', 'include', 'inherit', 'incr', 'land', 'let', 'load', 'los', 'lsl', 'lsr', 'lxor',
  14. 'method', 'mod', 'module', 'mutable', 'new', 'not', 'of', 'open', 'option', 'or', 'parser',
  15. 'private', 'ref', 'rec', 'raise', 'regexp', 'sig', 'struct', 'stdout', 'stdin', 'stderr',
  16. 'switch', 'then', 'to', 'true', 'try', 'type', 'val', 'virtual', 'when', 'while', 'with'
  17. }))
  18. -- Types.
  19. lex:add_rule('type', token(lexer.TYPE, word_match('int float bool char string unit')))
  20. -- Functions.
  21. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  22. 'raise', 'invalid_arg', 'failwith', 'compare', 'min', 'max', 'succ', 'pred', 'mod', 'abs',
  23. 'max_int', 'min_int', 'sqrt', 'exp', 'log', 'log10', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan',
  24. 'atan2', 'cosh', 'sinh', 'tanh', 'ceil', 'floor', 'abs_float', 'mod_float', 'frexp', 'ldexp',
  25. 'modf', 'float', 'float_of_int', 'truncate', 'int_of_float', 'infinity', 'nan', 'max_float',
  26. 'min_float', 'epsilon_float', 'classify_float', 'int_of_char', 'char_of_int', 'ignore',
  27. 'string_of_bool', 'bool_of_string', 'string_of_int', 'int_of_string', 'string_of_float',
  28. 'float_of_string', 'fst', 'snd', 'stdin', 'stdout', 'stderr', 'print_char', 'print_string',
  29. 'print_int', 'print_float', 'print_endline', 'print_newline', 'prerr_char', 'prerr_string',
  30. 'prerr_int', 'prerr_float', 'prerr_endline', 'prerr_newline', 'read_line', 'read_int',
  31. 'read_float', 'open_out', 'open_out_bin', 'open_out_gen', 'flush', 'flush_all', 'output_char',
  32. 'output_string', 'output', 'output_byte', 'output_binary_int', 'output_value', 'seek_out',
  33. 'pos_out', 'out_channel_length', 'close_out', 'close_out_noerr', 'set_binary_mode_out', 'open_in',
  34. 'open_in_bin', 'open_in_gen', 'input_char', 'input_line', 'input', 'really_input', 'input_byte',
  35. 'input_binary_int', 'input_value', 'seek_in', 'pos_in', 'in_channel_length', 'close_in',
  36. 'close_in_noerr', 'set_binary_mode_in', 'incr', 'decr', 'string_of_format', 'format_of_string',
  37. 'exit', 'at_exit'
  38. }))
  39. -- Identifiers.
  40. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  41. -- Strings.
  42. local sq_str = lexer.range("'", true)
  43. local dq_str = lexer.range('"', true)
  44. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  45. -- Comments.
  46. local line_comment = lexer.to_eol('//')
  47. local block_comment = lexer.range('/*', '*/', false, false, true)
  48. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  49. -- Numbers.
  50. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  51. -- Operators.
  52. lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+-*/.,:;~!#%^&|?[](){}')))
  53. lexer.property['scintillua.comment'] = '//'
  54. return lex