travis: try to fix build by using local built dependencies
[vis.git] / lexers / groovy.lua
blob92013a7fbd894d7fe9f70a5eedd2271a4f4e04d0
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Groovy LPeg lexer.
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'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
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)
18 -- Strings.
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 +
26 dq_str) +
27 token(l.REGEX, regex_str)
29 -- Numbers.
30 local number = token(l.NUMBER, l.float + l.integer)
32 -- Keywords.
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'
43 -- Functions.
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',
56 'writeLine'
59 -- Types.
60 local type = token(l.TYPE, word_match{
61 'boolean', 'byte', 'char', 'class', 'double', 'float', 'int', 'interface',
62 'long', 'short', 'void'
65 -- Identifiers.
66 local identifier = token(l.IDENTIFIER, l.word)
68 -- Operators.
69 local operator = token(l.OPERATOR, S('=~|!<>+-/*?&.,:;()[]{}'))
71 M._rules = {
72 {'whitespace', ws},
73 {'keyword', keyword},
74 {'function', func},
75 {'type', type},
76 {'identifier', identifier},
77 {'comment', comment},
78 {'string', string},
79 {'number', number},
80 {'operator', operator},
83 M._foldsymbols = {
84 _patterns = {'[{}]', '/%*', '%*/', '//'},
85 [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
86 [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')}
89 return M