File: ini.rb

package info (click to toggle)
ruby-rugments 1.0.0~beta8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 820 kB
  • sloc: ruby: 10,293; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download | duplicates (3)
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
module Rugments
  module Lexers
    class INI < RegexLexer
      title 'INI'
      desc 'the INI configuration format'
      tag 'ini'

      # TODO add more here
      filenames '*.ini', '*.INI', '*.gitconfig'
      mimetypes 'text/x-ini'

      def self.analyze_text(text)
        return 0.1 if text =~ /\A\[[\w.]+\]\s*\w+=\w+/
      end

      identifier = /[\w.]+/

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

      state :root do
        mixin :basic

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

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

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

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

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