1 -- Copyright 2006-2015 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
= 'antlr'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local line_comment
= '//' * l
.nonnewline^
0
15 local block_comment
= '/*' * (l
.any
- '*/')^
0 * P('*/')^
-1
16 local comment
= token(l
.COMMENT
, line_comment
+ block_comment
)
19 local string = token(l
.STRING
, l
.delimited_range("'", true))
22 local keyword
= token(l
.KEYWORD
, word_match
{
23 'abstract', 'break', 'case', 'catch', 'continue', 'default', 'do', 'else',
24 'extends', 'final', 'finally', 'for', 'if', 'implements', 'instanceof',
25 'native', 'new', 'private', 'protected', 'public', 'return', 'static',
26 'switch', 'synchronized', 'throw', 'throws', 'transient', 'try', 'volatile',
27 'while', 'package', 'import', 'header', 'options', 'tokens', 'strictfp',
28 'false', 'null', 'super', 'this', 'true'
32 local type = token(l
.TYPE
, word_match
{
33 'boolean', 'byte', 'char', 'class', 'double', 'float', 'int', 'interface',
34 'long', 'short', 'void'
38 local func
= token(l
.FUNCTION
, 'assert')
41 local identifier
= token(l
.IDENTIFIER
, l
.word
)
44 local operator
= token(l
.OPERATOR
, S('$@:;|.=+*?~!^>-()[]{}'))
47 local action
= #P('{') * operator
* token('action', (1 - P('}'))^
0) *
48 (#P('}') * operator
)^
-1
55 {'identifier', identifier
},
59 {'operator', operator
},
63 action
= l
.STYLE_NOTHING
67 _patterns
= {'[:;%(%){}]', '/%*', '%*/', '//'},
69 [':'] = 1, [';'] = -1, ['('] = 1, [')'] = -1, ['{'] = 1, ['}'] = -1
71 [l
.COMMENT
] = {['/*'] = 1, ['*/'] = -1, ['//'] = l
.fold_line_comments('//')}