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

groovy.lua (2827B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Groovy 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('groovy')
  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', 'break', 'case', 'catch', 'continue', 'default', 'do', 'else', 'extends', 'final',
  12. 'finally', 'for', 'if', 'implements', 'instanceof', 'native', 'new', 'private', 'protected',
  13. 'public', 'return', 'static', 'switch', 'synchronized', 'throw', 'throws', 'transient', 'try',
  14. 'volatile', 'while', 'strictfp', 'package', 'import', 'as', 'assert', 'def', 'mixin', 'property',
  15. 'test', 'using', 'in', 'false', 'null', 'super', 'this', 'true', 'it'
  16. }))
  17. -- Functions.
  18. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  19. 'abs', 'any', 'append', 'asList', 'asWritable', 'call', 'collect', 'compareTo', 'count', 'div',
  20. 'dump', 'each', 'eachByte', 'eachFile', 'eachLine', 'every', 'find', 'findAll', 'flatten',
  21. 'getAt', 'getErr', 'getIn', 'getOut', 'getText', 'grep', 'immutable', 'inject', 'inspect',
  22. 'intersect', 'invokeMethods', 'isCase', 'join', 'leftShift', 'minus', 'multiply',
  23. 'newInputStream', 'newOutputStream', 'newPrintWriter', 'newReader', 'newWriter', 'next', 'plus',
  24. 'pop', 'power', 'previous', 'print', 'println', 'push', 'putAt', 'read', 'readBytes', 'readLines',
  25. 'reverse', 'reverseEach', 'round', 'size', 'sort', 'splitEachLine', 'step', 'subMap', 'times',
  26. 'toInteger', 'toList', 'tokenize', 'upto', 'waitForOrKill', 'withPrintWriter', 'withReader',
  27. 'withStream', 'withWriter', 'withWriterAppend', 'write', 'writeLine'
  28. }))
  29. -- Types.
  30. lex:add_rule('type', token(lexer.TYPE, word_match(
  31. 'boolean byte char class double float int interface long short void')))
  32. -- Identifiers.
  33. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  34. -- Comments.
  35. local line_comment = lexer.to_eol('//', true)
  36. local block_comment = lexer.range('/*', '*/')
  37. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  38. -- Strings.
  39. local sq_str = lexer.range("'")
  40. local dq_str = lexer.range('"')
  41. local tq_str = lexer.range("'''") + lexer.range('"""')
  42. local string = token(lexer.STRING, tq_str + sq_str + dq_str)
  43. local regex_str = lexer.after_set('=~|!<>+-*?&,:;([{', lexer.range('/', true))
  44. local regex = token(lexer.REGEX, regex_str)
  45. lex:add_rule('string', string + regex)
  46. -- Numbers.
  47. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  48. -- Operators.
  49. lex:add_rule('operator', token(lexer.OPERATOR, S('=~|!<>+-/*?&.,:;()[]{}')))
  50. -- Fold points.
  51. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  52. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  53. lexer.property['scintillua.comment'] = '//'
  54. return lex