1 -- Copyright 2016 Alejandro Baez (https://keybase.io/baez). See LICENSE.
2 -- Dockerfile 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
= 'dockerfile'}
11 local indent
= #l
.starts_line(S(' \t')) *
12 (token(l
.WHITESPACE
, ' ') + token('indent_error', '\t'))^
1
13 local ws
= token(l
.WHITESPACE
, S(' \t')^
1 + l
.newline^
1)
16 local comment
= token(l
.COMMENT
, '#' * l
.nonnewline^
0)
19 local sq_str
= l
.delimited_range("'", false, true)
20 local dq_str
= l
.delimited_range('"')
21 local string = token(l
.STRING
, sq_str
+ dq_str
)
24 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
27 local keyword
= token(l
.KEYWORD
, word_match
{
28 'ADD', 'ARG', 'CMD', 'COPY', 'ENTRYPOINT', 'ENV', 'EXPOSE', 'FROM', 'LABEL',
29 'MAINTAINER', 'ONBUILD', 'RUN', 'STOPSIGNAL', 'USER', 'VOLUME', 'WORKDIR'
33 local identifier
= token(l
.IDENTIFIER
, l
.word
)
36 local variable
= token(l
.VARIABLE
,
37 S('$')^
1 * (S('{')^
1 * l
.word
* S('}')^
1 + l
.word
))
40 local operator
= token(l
.OPERATOR
, S('\\[],=:{}'))
45 {'variable', variable
},
46 {'identifier', identifier
},
50 {'operator', operator
},
53 M
._FOLDBYINDENTATION
= true