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
= 'gap'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local comment
= token(l
.COMMENT
, '#' * l
.nonnewline^
0)
17 local sq_str
= l
.delimited_range("'", true)
18 local dq_str
= l
.delimited_range('"', true)
19 local string = token(l
.STRING
, sq_str
+ dq_str
)
22 local number = token(l
.NUMBER
, l
.digit^
1 * -l
.alpha
)
25 local keyword
= token(l
.KEYWORD
, word_match
{
26 'and', 'break', 'continue', 'do', 'elif', 'else', 'end', 'fail', 'false',
27 'fi', 'for', 'function', 'if', 'in', 'infinity', 'local', 'not', 'od', 'or',
28 'rec', 'repeat', 'return', 'then', 'true', 'until', 'while'
32 local identifier
= token(l
.IDENTIFIER
, l
.word
)
35 local operator
= token(l
.OPERATOR
, S('*+-,./:;<=>~^#()[]{}'))
40 {'identifier', identifier
},
44 {'operator', operator
},
48 _patterns
= {'[a-z]+', '#'},
50 ['function'] = 1, ['end'] = -1, ['do'] = 1, od
= -1, ['if'] = 1, fi
= -1,
51 ['repeat'] = 1, ['until'] = -1
53 [l
.COMMENT
] = {['#'] = l
.fold_line_comments('#')}