Sha256: 9f614fc77b43dc0360109e2d780138490d6fbbfb78afe1adfe690273b54875e4

Contents?: true

Size: 1.67 KB

Versions: 13

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require 'yaml'

module Rouge
  module Lexers
    class Apache < RegexLexer
      title "Apache"
      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(File.join(__dir__, 'apache/keywords.yml')).tap do |h|
        h.each do |k,v|
          h[k] = Set.new v
        end
      end

      def name_for_token(token, kwtype, tktype)
        if self.class.keywords[kwtype].include? token
          tktype
        else
          Text
        end
      end

      state :whitespace do
        rule %r/\#.*/, Comment
        rule %r/\s+/m, Text
      end

      state :root do
        mixin :whitespace

        rule %r/(<\/?)(\w+)/ do |m|
          groups Punctuation, name_for_token(m[2].downcase, :sections, Name::Label)
          push :section
        end

        rule %r/\w+/ do |m|
          token name_for_token(m[0].downcase, :directives, Name::Class)
          push :directive
        end
      end

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

        mixin :whitespace
      end

      state :directive do
        # Match value literals and other directive arguments
        rule %r/\r\n?|\n/, Text, :pop!

        mixin :whitespace

        rule %r/\S+/ do |m|
          token name_for_token(m[0], :values, Literal::String::Symbol)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rouge-3.17.0 lib/rouge/lexers/apache.rb
rouge-3.16.0 lib/rouge/lexers/apache.rb
rouge-3.15.0 lib/rouge/lexers/apache.rb
rouge-3.14.0 lib/rouge/lexers/apache.rb
rouge-3.13.0 lib/rouge/lexers/apache.rb
rouge-3.12.0 lib/rouge/lexers/apache.rb
rouge-3.11.1 lib/rouge/lexers/apache.rb
rouge-3.11.0 lib/rouge/lexers/apache.rb
rouge-3.10.0 lib/rouge/lexers/apache.rb
rouge-3.9.0 lib/rouge/lexers/apache.rb
rouge-3.8.0 lib/rouge/lexers/apache.rb
rouge-3.7.0 lib/rouge/lexers/apache.rb
rouge-3.6.0 lib/rouge/lexers/apache.rb