Sha256: aedc04ff580b751a6008062d73607dee3bd267637f59aa9989b8a87df49f733d

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

module Rouge
  module Lexers
    class INI < RegexLexer
      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
          group Name::Property; group Text
          group 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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rouge-1.1.0 lib/rouge/lexers/ini.rb
rouge-0.5.4 lib/rouge/lexers/ini.rb
rouge-0.5.3 lib/rouge/lexers/ini.rb
rouge-0.5.2 lib/rouge/lexers/ini.rb
rouge-0.5.1 lib/rouge/lexers/ini.rb
rouge-0.5.0 lib/rouge/lexers/ini.rb