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

caml.lua (3120B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- OCaml 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('caml')
  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', 'incr', 'inherit', 'land', 'let', 'load', 'los', 'lsl', 'lsr', 'lxor',
  14. 'match', 'method', 'mod', 'module', 'mutable', 'new', 'not', 'of', 'open', 'option', 'or',
  15. 'parser', 'private', 'raise', 'rec', 'ref', 'regexp', 'sig', 'stderr', 'stdin', 'stdout',
  16. 'struct', 'then', 'to', 'true', 'try', 'type', 'val', 'virtual', 'when', 'while', 'with'
  17. }))
  18. -- Types.
  19. lex:add_rule('type', token(lexer.TYPE, word_match('bool char float int string unit')))
  20. -- Functions.
  21. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  22. 'abs', 'abs_float', 'acos', 'asin', 'atan', 'atan2', 'at_exit', 'bool_of_string', 'ceil',
  23. 'char_of_int', 'classify_float', 'close_in', 'close_in_noerr', 'close_out', 'close_out_noerr',
  24. 'compare', 'cos', 'cosh', 'decr', 'epsilon_float', 'exit', 'exp', 'failwith', 'float',
  25. 'float_of_int', 'float_of_string', 'floor', 'flush', 'flush_all', 'format_of_string', 'frexp',
  26. 'fst', 'ignore', 'in_channel_length', 'incr', 'infinity', 'input', 'input_binary_int',
  27. 'input_byte', 'input_char', 'input_line', 'input_value', 'int_of_char', 'int_of_float',
  28. 'int_of_string', 'invalid_arg', 'ldexp', 'log', 'log10', 'max', 'max_float', 'max_int', 'min',
  29. 'min_float', 'min_int', 'mod', 'modf', 'mod_float', 'nan', 'open_in', 'open_in_bin',
  30. 'open_in_gen', 'open_out', 'open_out_bin', 'open_out_gen', 'out_channel_length', 'output',
  31. 'output_binary_int', 'output_byte', 'output_char', 'output_string', 'output_value', 'pos_in',
  32. 'pos_out', 'pred', 'prerr_char', 'prerr_endline', 'prerr_float', 'prerr_int', 'prerr_newline',
  33. 'prerr_string', 'print_char', 'print_endline', 'print_float', 'print_int', 'print_newline',
  34. 'print_string', 'raise', 'read_float', 'read_int', 'read_line', 'really_input', 'seek_in',
  35. 'seek_out', 'set_binary_mode_in', 'set_binary_mode_out', 'sin', 'sinh', 'snd', 'sqrt', 'stderr',
  36. 'stdin', 'stdout', 'string_of_bool', 'string_of_float', 'string_of_format', 'string_of_int',
  37. 'succ', 'tan', 'tanh', 'truncate'
  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. lex:add_rule('comment', token(lexer.COMMENT, lexer.range('(*', '*)', false, false, true)))
  47. -- Numbers.
  48. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  49. -- Operators.
  50. lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+-*/.,:;~!#%^&|?[](){}')))
  51. lexer.property['scintillua.comment'] = '(*|*)'
  52. return lex