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

rstats.lua (1609B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- R 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('rstats')
  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. 'break', 'else', 'for', 'if', 'in', 'next', 'repeat', 'return', 'switch', 'try', 'while', --
  12. 'Inf', 'NA', 'NaN', 'NULL', 'FALSE', 'TRUE', 'F', 'T',
  13. -- Frequently used operators.
  14. '|>', '%%', '%*%', '%/%', '%in%', '%o%', '%x%'
  15. }))
  16. -- Types.
  17. lex:add_rule('type', token(lexer.TYPE, word_match{
  18. 'array', 'character', 'closure', 'complex', 'data.frame', 'double', 'environment', 'expression',
  19. 'externalptr', 'factor', 'function', 'integer', 'list', 'logical', 'matrix', 'numeric',
  20. 'pairlist', 'promise', 'raw', 'symbol', 'vector'
  21. }))
  22. -- Identifiers.
  23. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  24. -- Strings.
  25. local sq_str = lexer.range("'", true)
  26. local dq_str = lexer.range('"', true)
  27. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  28. -- Comments.
  29. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
  30. -- Numbers.
  31. lex:add_rule('number', token(lexer.NUMBER, (lexer.number * P('i')^-1) * P('L')^-1))
  32. -- Operators.
  33. lex:add_rule('operator', token(lexer.OPERATOR, S('<->+*/^=.,:;|$()[]{}')))
  34. -- Folding
  35. lex:add_fold_point(lexer.OPERATOR, '(', ')')
  36. lex:add_fold_point(lexer.OPERATOR, '[', ']')
  37. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  38. lexer.property['scintillua.comment'] = '#'
  39. return lex