Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docker lexer #2092

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/rouge/lexers/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Docker < RegexLexer
mimetypes 'text/x-dockerfile-config'

KEYWORDS = %w(
FROM MAINTAINER CMD LABEL EXPOSE ENV ADD COPY ENTRYPOINT VOLUME USER WORKDIR ARG STOPSIGNAL HEALTHCHECK SHELL
FROM MAINTAINER CMD EXPOSE ADD COPY ENTRYPOINT VOLUME USER WORKDIR ARG STOPSIGNAL HEALTHCHECK SHELL
).join('|')

start { @shell = Shell.new(@options) }
Expand Down Expand Up @@ -40,16 +40,37 @@ class Docker < RegexLexer
@shell.reset!
end

rule %r/^(LABEL|ENV)(\s+)/i do
token Keyword
push :identifier
end

rule %r/\w+/, Text
rule %r/[^\w]+/, Text
rule %r/./, Text
end

state :run do
rule %r/\n/, Text, :pop!
rule %r/^\s*#.*\n/, Comment
rule %r/\\./m, Str::Escape
rule(/(\\.|[^\n\\])+/) { delegate @shell }
end

state :identifier do
rule %r/\n/, Text, :pop!
rule %r/^\s*#.*\n/, Comment
rule %r/\s*\\./m, Str::Escape
rule %r/(\s*(?:[^\s=]+|"[^"]+"|'[^']+'))(=)/ do
groups Name::Property, Punctuation
push :value
end
end

state :value do
rule %r/\n/, Text, :pop!
rule %r/(".*?")|('.*?')|((?:[^\\\s]|\\\s)+)/m, Str, :pop!
end
end
end
end
Loading