aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/dockerfile.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-11 01:27:32 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-03-27 06:04:21 -0600
commit4c4392d29df777ff702dfe99b4f3c23142976e05 (patch)
tree5355324abe18952f7d19d6cfc5dbeb5d6cb72b84 /lua/lexers/dockerfile.lua
parent95bf9f59f8a9a37148bdc0787db378d62c7cd032 (diff)
downloadvis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.gz
vis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.xz
update lexers to orbitalquark/scintillua@b789dde
Rather than cherry pick patches from after 6.2 we will just grab everything as is.
Diffstat (limited to 'lua/lexers/dockerfile.lua')
-rw-r--r--lua/lexers/dockerfile.lua43
1 files changed, 25 insertions, 18 deletions
diff --git a/lua/lexers/dockerfile.lua b/lua/lexers/dockerfile.lua
index 4b131df..9b335de 100644
--- a/lua/lexers/dockerfile.lua
+++ b/lua/lexers/dockerfile.lua
@@ -1,40 +1,47 @@
--- Copyright 2016-2022 Alejandro Baez (https://keybase.io/baez). See LICENSE.
+-- Copyright 2016-2024 Alejandro Baez (https://keybase.io/baez). See LICENSE.
-- Dockerfile LPeg lexer.
-local lexer = require('lexer')
-local token, word_match = lexer.token, lexer.word_match
-local P, S = lpeg.P, lpeg.S
+local lexer = lexer
+local P, S, B = lpeg.P, lpeg.S, lpeg.B
-local lex = lexer.new('dockerfile', {fold_by_indentation = true})
-
--- Whitespace
-lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
+local lex = lexer.new(..., {fold_by_indentation = true})
-- Keywords.
-lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
- 'ADD', 'ARG', 'CMD', 'COPY', 'ENTRYPOINT', 'ENV', 'EXPOSE', 'FROM', 'LABEL', 'MAINTAINER',
- 'ONBUILD', 'RUN', 'STOPSIGNAL', 'USER', 'VOLUME', 'WORKDIR'
-}))
+local keyword = lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD))
+lex:add_rule('keyword', keyword)
-- Identifiers.
-lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
+lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
-- Variable.
lex:add_rule('variable',
- token(lexer.VARIABLE, S('$')^1 * (P('{')^1 * lexer.word * P('}')^1 + lexer.word)))
+-B('\\') * lex:tag(lexer.OPERATOR, '$' * P('{')^-1) * lex:tag(lexer.VARIABLE, lexer.word))
-- Strings.
local sq_str = lexer.range("'", false, false)
local dq_str = lexer.range('"')
-lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
+lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))
-- Comments.
-lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
+lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.to_eol('#')))
-- Numbers.
-lex:add_rule('number', token(lexer.NUMBER, lexer.number))
+lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number))
-- Operators.
-lex:add_rule('operator', token(lexer.OPERATOR, S('\\[],=:{}')))
+lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('\\[],=:{}')))
+
+local bash = lexer.load('bash')
+local start_rule = #P('RUN') * keyword * bash:get_rule('whitespace')
+local end_rule = -B('\\') * #lexer.newline * lex:get_rule('whitespace')
+lex:embed(bash, start_rule, end_rule)
+
+-- Word lists.
+lex:set_word_list(lexer.KEYWORD, {
+ 'ADD', 'ARG', 'CMD', 'COPY', 'ENTRYPOINT', 'ENV', 'EXPOSE', 'FROM', 'LABEL', 'MAINTAINER',
+ 'ONBUILD', 'RUN', 'STOPSIGNAL', 'USER', 'VOLUME', 'WORKDIR'
+})
+
+lexer.property['scintillua.comment'] = '#'
return lex