1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
8 local M
= {_NAME
= 'groovy'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local line_comment
= '//' * l
.nonnewline_esc^
0
15 local block_comment
= '/*' * (l
.any
- '*/')^
0 * P('*/')^
-1
16 local comment
= token(l
.COMMENT
, line_comment
+ block_comment
)
19 local sq_str
= l
.delimited_range("'")
20 local dq_str
= l
.delimited_range('"')
21 local triple_sq_str
= "'''" * (l
.any
- "'''")^
0 * P("'''")^
-1
22 local triple_dq_str
= '"""' * (l
.any
- '"""')^
0 * P('"""')^
-1
23 local regex_str
= #P('/') * l
.last_char_includes('=~|!<>+-*?&,:;([{') *
24 l
.delimited_range('/', true)
25 local string = token(l
.STRING
, triple_sq_str
+ triple_dq_str
+ sq_str
+
27 token(l
.REGEX
, regex_str
)
30 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
33 local keyword
= token(l
.KEYWORD
, word_match
{
34 'abstract', 'break', 'case', 'catch', 'continue', 'default', 'do', 'else',
35 'extends', 'final', 'finally', 'for', 'if', 'implements', 'instanceof',
36 'native', 'new', 'private', 'protected', 'public', 'return', 'static',
37 'switch', 'synchronized', 'throw', 'throws', 'transient', 'try', 'volatile',
38 'while', 'strictfp', 'package', 'import', 'as', 'assert', 'def', 'mixin',
39 'property', 'test', 'using', 'in',
40 'false', 'null', 'super', 'this', 'true', 'it'
44 local func
= token(l
.FUNCTION
, word_match
{
45 'abs', 'any', 'append', 'asList', 'asWritable', 'call', 'collect',
46 'compareTo', 'count', 'div', 'dump', 'each', 'eachByte', 'eachFile',
47 'eachLine', 'every', 'find', 'findAll', 'flatten', 'getAt', 'getErr', 'getIn',
48 'getOut', 'getText', 'grep', 'immutable', 'inject', 'inspect', 'intersect',
49 'invokeMethods', 'isCase', 'join', 'leftShift', 'minus', 'multiply',
50 'newInputStream', 'newOutputStream', 'newPrintWriter', 'newReader',
51 'newWriter', 'next', 'plus', 'pop', 'power', 'previous', 'print', 'println',
52 'push', 'putAt', 'read', 'readBytes', 'readLines', 'reverse', 'reverseEach',
53 'round', 'size', 'sort', 'splitEachLine', 'step', 'subMap', 'times',
54 'toInteger', 'toList', 'tokenize', 'upto', 'waitForOrKill', 'withPrintWriter',
55 'withReader', 'withStream', 'withWriter', 'withWriterAppend', 'write',
60 local type = token(l
.TYPE
, word_match
{
61 'boolean', 'byte', 'char', 'class', 'double', 'float', 'int', 'interface',
62 'long', 'short', 'void'
66 local identifier
= token(l
.IDENTIFIER
, l
.word
)
69 local operator
= token(l
.OPERATOR
, S('=~|!<>+-/*?&.,:;()[]{}'))
76 {'identifier', identifier
},
80 {'operator', operator
},
84 _patterns
= {'[{}]', '/%*', '%*/', '//'},
85 [l
.OPERATOR
] = {['{'] = 1, ['}'] = -1},
86 [l
.COMMENT
] = {['/*'] = 1, ['*/'] = -1, ['//'] = l
.fold_line_comments('//')}