summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/rouge-4.7.0/lib/rouge/lexers/ini.rb
blob: 500167e2c3611a669c113c0d8e9847d11c51bb36 (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
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Lexers
    class INI < RegexLexer
      title "INI"
      desc 'the INI configuration format'
      tag 'ini'

      filenames '*.ini', '*.INI', '*.gitconfig', '*.cfg', '.editorconfig', '*.inf'
      mimetypes 'text/x-ini', 'text/inf'

      identifier = /[\w\-.]+/

      state :basic do
        rule %r/\s+/, Text::Whitespace
        rule %r/[;#].*?\n/, Comment
        rule %r/\\\n/, Str::Escape
      end

      state :root do
        mixin :basic

        rule %r/(#{identifier})(\s*)(=)/ do
          groups Name::Property, Text::Whitespace, Punctuation
          push :value
        end

        rule %r/\[.*?\]/, Name::Namespace

        # standalone option, supported by some INI parsers
        rule %r/(.+?)/, Name::Attribute
      end

      state :value do
        rule %r/\n/, Text, :pop!
        mixin :basic
        rule %r/"/, Str, :dq
        rule %r/'.*?'/, Str
        mixin :esc_str
        rule %r/[^\\\n]+/, Str
      end

      state :dq do
        rule %r/"/, Str, :pop!
        mixin :esc_str
        rule %r/[^\\"]+/m, Str
      end

      state :esc_str do
        rule %r/\\./m, Str::Escape
      end
    end
  end
end