Sha256: 788a257e549114d341daaa421e7e368c583e36f2f55468071a54a344e94719b1

Contents?: true

Size: 1.5 KB

Versions: 28

Compression:

Stored size: 1.5 KB

Contents

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

module Rouge
  module Lexers
    class Nginx < RegexLexer
      title "nginx"
      desc 'configuration files for the nginx web server (nginx.org)'
      tag 'nginx'
      mimetypes 'text/x-nginx-conf'
      filenames 'nginx.conf'

      id = /[^\s$;{}()#]+/

      state :root do
        rule %r/(include)(\s+)([^\s;]+)/ do
          groups Keyword, Text, Name
        end

        rule id, Keyword, :statement

        mixin :base
      end

      state :block do
        rule %r/}/, Punctuation, :pop!
        rule id, Keyword::Namespace, :statement
        mixin :base
      end

      state :statement do
        rule %r/{/ do
          token Punctuation; pop!; push :block
        end

        rule %r/;/, Punctuation, :pop!

        mixin :base
      end

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

        rule %r/#.*/, Comment::Single
        rule %r/(?:on|off)\b/, Name::Constant
        rule %r/[$][\w-]+/, Name::Variable

        # host/port
        rule %r/([a-z0-9.-]+)(:)([0-9]+)/i do
          groups Name::Function, Punctuation, Num::Integer
        end

        # mimetype
        rule %r([a-z-]+/[a-z-]+)i, Name::Class

        rule %r/[0-9]+[kmg]?\b/i, Num::Integer
        rule %r/(~)(\s*)([^\s{]+)/ do
          groups Punctuation, Text, Str::Regex
        end

        rule %r/[:=~]/, Punctuation

        # pathname
        rule %r(/#{id}?), Name

        rule %r/[^#\s;{}$\\]+/, Str # catchall

        rule %r/[$;]/, Text
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
rouge-4.2.0 lib/rouge/lexers/nginx.rb
rouge-4.1.3 lib/rouge/lexers/nginx.rb
rouge-4.1.2 lib/rouge/lexers/nginx.rb
rouge-4.1.1 lib/rouge/lexers/nginx.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/nginx.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/nginx.rb
rouge-4.1.0 lib/rouge/lexers/nginx.rb
rouge-4.0.1 lib/rouge/lexers/nginx.rb
rouge-4.0.0 lib/rouge/lexers/nginx.rb
rouge-3.30.0 lib/rouge/lexers/nginx.rb
rouge-3.29.0 lib/rouge/lexers/nginx.rb
rouge-3.28.0 lib/rouge/lexers/nginx.rb
rouge-3.27.0 lib/rouge/lexers/nginx.rb
rouge-3.26.1 lib/rouge/lexers/nginx.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/nginx.rb
rouge-3.26.0 lib/rouge/lexers/nginx.rb
rouge-3.25.0 lib/rouge/lexers/nginx.rb
rouge-3.24.0 lib/rouge/lexers/nginx.rb
rouge-3.23.0 lib/rouge/lexers/nginx.rb
rouge-3.22.0 lib/rouge/lexers/nginx.rb