Sha256: 9149e88d2f126bf3cf3b300dfe8386830394ca8abd5c2c08ff607a413031a41f

Contents?: true

Size: 1.35 KB

Versions: 13

Compression:

Stored size: 1.35 KB

Contents

# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Lexers
    class Docker < RegexLexer
      title "Docker"
      desc "Dockerfile syntax"
      tag 'docker'
      aliases 'dockerfile', 'Dockerfile'
      filenames 'Dockerfile', '*.Dockerfile', '*.docker'
      mimetypes 'text/x-dockerfile-config'

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

      start { @shell = Shell.new(@options) }

      state :root do
        rule %r/\s+/, Text

        rule %r/^(FROM)(\s+)(.*)(\s+)(AS)(\s+)(.*)/io do
          groups Keyword, Text::Whitespace, Str, Text::Whitespace, Keyword, Text::Whitespace, Str
        end

        rule %r/^(ONBUILD)(\s+)(#{KEYWORDS})(.*)/io do
          groups Keyword, Text::Whitespace, Keyword, Str
        end

        rule %r/^(#{KEYWORDS})\b(.*)/io do
          groups Keyword, Str
        end

        rule %r/#.*?$/, Comment

        rule %r/^(ONBUILD\s+)?RUN(\s+)/i do
          token Keyword
          push :run
          @shell.reset!
        end

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

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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
rouge-4.3.0 lib/rouge/lexers/docker.rb
rouge-4.2.1 lib/rouge/lexers/docker.rb
rouge-4.2.0 lib/rouge/lexers/docker.rb
rouge-4.1.3 lib/rouge/lexers/docker.rb
rouge-4.1.2 lib/rouge/lexers/docker.rb
rouge-4.1.1 lib/rouge/lexers/docker.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/docker.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/docker.rb
rouge-4.1.0 lib/rouge/lexers/docker.rb
rouge-4.0.1 lib/rouge/lexers/docker.rb
rouge-4.0.0 lib/rouge/lexers/docker.rb
rouge-3.30.0 lib/rouge/lexers/docker.rb
rouge-3.29.0 lib/rouge/lexers/docker.rb