1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
3 -- Modified by Brian Schott.
5 local l
= require('lexer')
6 local token
, word_match
= l
.token
, l
.word_match
7 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
9 local M
= {_NAME
= 'java'}
12 local ws
= token(l
.WHITESPACE
, l
.space^
1)
15 local line_comment
= '//' * l
.nonnewline_esc^
0
16 local block_comment
= '/*' * (l
.any
- '*/')^
0 * P('*/')^
-1
17 local comment
= token(l
.COMMENT
, line_comment
+ block_comment
)
20 local sq_str
= l
.delimited_range("'", true)
21 local dq_str
= l
.delimited_range('"', true)
22 local string = token(l
.STRING
, sq_str
+ dq_str
)
25 local number = token(l
.NUMBER
, (l
.float
+ l
.integer
) * S('LlFfDd')^
-1)
28 local keyword
= token(l
.KEYWORD
, word_match
{
29 'abstract', 'assert', 'break', 'case', 'catch', 'class', 'const', 'continue',
30 'default', 'do', 'else', 'enum', 'extends', 'final', 'finally', 'for', 'goto',
31 'if', 'implements', 'import', 'instanceof', 'interface', 'native', 'new',
32 'package', 'private', 'protected', 'public', 'return', 'static', 'strictfp',
33 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient',
34 'try', 'while', 'volatile',
36 'true', 'false', 'null'
40 local type = token(l
.TYPE
, word_match
{
41 'boolean', 'byte', 'char', 'double', 'float', 'int', 'long', 'short', 'void',
42 'Boolean', 'Byte', 'Character', 'Double', 'Float', 'Integer', 'Long', 'Short',
47 local identifier
= token(l
.IDENTIFIER
, l
.word
)
50 local operator
= token(l
.OPERATOR
, S('+-/*%<>!=^&|?~:;.()[]{}'))
53 local annotation
= token('annotation', '@' * l
.word
)
56 local func
= token(l
.FUNCTION
, l
.word
) * #P('(')
59 local class_sequence
= token(l
.KEYWORD
, P('class')) * ws^
1 *
60 token(l
.CLASS
, l
.word
)
64 {'class', class_sequence
},
68 {'identifier', identifier
},
72 {'annotation', annotation
},
73 {'operator', operator
},
77 annotation
= l
.STYLE_PREPROCESSOR
81 _patterns
= {'[{}]', '/%*', '%*/', '//'},
82 [l
.OPERATOR
] = {['{'] = 1, ['}'] = -1},
83 [l
.COMMENT
] = {['/*'] = 1, ['*/'] = -1, ['//'] = l
.fold_line_comments('//')}