summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/rouge-4.7.0/lib/rouge/lexers/nginx.rb
blob: f2661cce49150f65ef4b75249825a3611c9aacd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- 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/\d+\.\d+/, Num::Float
        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