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

nemerle.lua (2407B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Nemerle 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('nemerle')
  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. '_', 'abstract', 'and', 'array', 'as', 'base', 'catch', 'class', 'def', 'do', 'else', 'extends',
  12. 'extern', 'finally', 'foreach', 'for', 'fun', 'if', 'implements', 'in', 'interface', 'internal',
  13. 'lock', 'macro', 'match', 'module', 'mutable', 'namespace', 'new', 'out', 'override', 'params',
  14. 'private', 'protected', 'public', 'ref', 'repeat', 'sealed', 'static', 'struct', 'syntax', 'this',
  15. 'throw', 'try', 'type', 'typeof', 'unless', 'until', 'using', 'variant', 'virtual', 'when',
  16. 'where', 'while',
  17. -- Values.
  18. 'null', 'true', 'false'
  19. }))
  20. -- Types.
  21. lex:add_rule('type', token(lexer.TYPE, word_match{
  22. 'bool', 'byte', 'char', 'decimal', 'double', 'float', 'int', 'list', 'long', 'object', 'sbyte',
  23. 'short', 'string', 'uint', 'ulong', 'ushort', 'void'
  24. }))
  25. -- Strings.
  26. local sq_str = P('L')^-1 * lexer.range("'", true)
  27. local dq_str = P('L')^-1 * lexer.range('"', true)
  28. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  29. -- Identifiers.
  30. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  31. -- Comments.
  32. local line_comment = lexer.to_eol('//', true)
  33. local block_comment = lexer.range('/*', '*/')
  34. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  35. -- Numbers.
  36. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  37. -- Preprocessor.
  38. lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') * S('\t ')^0 * word_match{
  39. 'define', 'elif', 'else', 'endif', 'endregion', 'error', 'if', 'ifdef', 'ifndef', 'line',
  40. 'pragma', 'region', 'undef', 'using', 'warning'
  41. }))
  42. -- Operators.
  43. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}')))
  44. -- Fold points.
  45. lex:add_fold_point(lexer.PREPROCESSOR, 'region', 'endregion')
  46. lex:add_fold_point(lexer.PREPROCESSOR, 'if', 'endif')
  47. lex:add_fold_point(lexer.PREPROCESSOR, 'ifdef', 'endif')
  48. lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif')
  49. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  50. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  51. lexer.property['scintillua.comment'] = '//'
  52. return lex