Sha256: e63e61809a1e491afdb0fbf6239fa0cc062f78e8f30aefc3ccee18611d58010f

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 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/, 'Literal.String.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 /"/, 'Literal.String', :dq
        rule /'.*?'/, 'Literal.String'
        mixin :esc_str
        rule /[^\\\n]+/, 'Literal.String'
      end

      state :dq do
        rule /"/, 'Literal.String', :pop!
        mixin :esc_str
        rule /[^\\"]+/m, 'Literal.String'
      end

      state :esc_str do
        rule /\\./m, 'Literal.String.Escape'
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rouge-0.4.0 lib/rouge/lexers/ini.rb
rouge-0.3.10 lib/rouge/lexers/ini.rb
rouge-0.3.9 lib/rouge/lexers/ini.rb
rouge-0.3.8 lib/rouge/lexers/ini.rb
rouge-0.3.7 lib/rouge/lexers/ini.rb
rouge-0.3.6 lib/rouge/lexers/ini.rb
rouge-0.3.5 lib/rouge/lexers/ini.rb
rouge-0.3.4 lib/rouge/lexers/ini.rb
rouge-0.3.3 lib/rouge/lexers/ini.rb
rouge-0.3.2 lib/rouge/lexers/ini.rb
rouge-0.3.1 lib/rouge/lexers/ini.rb
rouge-0.3.0 lib/rouge/lexers/ini.rb
rouge-0.2.15 lib/rouge/lexers/ini.rb
rouge-0.2.14 lib/rouge/lexers/ini.rb