Sha256: 2f17230cc9c4a2fce4428ddfd5c1dd19f432fdf3ede97e2e7ff2727aff32680a

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

module Rouge
  module Lexers
    class Nginx < RegexLexer
      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 /(include)(\s+)([^\s;]+)/ do
          groups Keyword, Text, Name
        end

        rule id, Keyword, :statement

        mixin :base
      end

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

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

        rule /;/, Punctuation, :pop!

        mixin :base
      end

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

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

        # host/port
        rule /([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 /[0-9]+[kmg]?\b/i, Num::Integer
        rule /(~)(\s*)([^\s{]+)/ do
          groups Punctuation, Text, Str::Regex
        end

        rule /[:=~]/, Punctuation

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

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rouge-1.5.0 lib/rouge/lexers/nginx.rb
rouge-1.4.0 lib/rouge/lexers/nginx.rb
rouge-1.3.4 lib/rouge/lexers/nginx.rb
rouge-1.3.3 lib/rouge/lexers/nginx.rb
rouge-1.3.2 lib/rouge/lexers/nginx.rb
rouge-1.3.1 lib/rouge/lexers/nginx.rb
rouge-1.3.0 lib/rouge/lexers/nginx.rb
rouge-1.2.0 lib/rouge/lexers/nginx.rb