Sha256: 717cd970177c1e2720bf3456ab44b44e3ab948cb7d7f6164424cb6fd892af456

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 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/^(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

6 entries across 6 versions & 2 rubygems

Version Path
rouge-3.28.0 lib/rouge/lexers/docker.rb
rouge-3.27.0 lib/rouge/lexers/docker.rb
rouge-3.26.1 lib/rouge/lexers/docker.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/docker.rb
rouge-3.26.0 lib/rouge/lexers/docker.rb
rouge-3.25.0 lib/rouge/lexers/docker.rb