Sha256: becad97ab4b45129143ba9f2a0dff8b252b6466e58d0cbe1e25238b419126aed

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'yaml'

module Rouge
  module Lexers
    class Apache < RegexLexer
      desc 'configuration files for Apache web server'
      tag 'apache'
      mimetypes 'text/x-httpd-conf', 'text/x-apache-conf'
      filenames '.htaccess', 'httpd.conf'

      class << self
        attr_reader :keywords
      end
      # Load Apache keywords from separate YML file
      @keywords = ::YAML.load(File.open(Pathname.new(__FILE__).dirname.join('apache/keywords.yml')))

      def name_for_token(token)
        if self.class.keywords[:sections].include? token
          Name::Class
        elsif self.class.keywords[:directives].include? token
          Name::Label
        elsif self.class.keywords[:values].include? token
          Literal::String::Symbol
        end
      end

      state :whitespace do
        rule /\#.*?\n/, Comment
        rule /[\s\n]+/m, Text
      end


      state :root do
        mixin :whitespace

        rule /(<\/?)(\w+)/ do |m|
          groups Punctuation, name_for_token(m[2])
          push :section
        end

        rule /\w+/ do |m|
          token name_for_token(m[0])
          push :directive
        end
      end

      state :section do
        mixin :whitespace

        # Match section arguments
        rule /([^>]+)?(>\n)/ do |m|
          groups Literal::String::Regex, Punctuation
          pop!
        end
      end

      state :directive do
        # Match value literals and other directive arguments
        rule /(\w+)*(.*?(\n|$))/ do |m|
          token name_for_token(m[1]), m[1]
          token Text, m[2]
          pop!
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rouge-1.7.7 lib/rouge/lexers/apache.rb