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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# 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'
# self-modifying method that loads the keywords file
def self.directives
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
directives
end
def self.sections
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
sections
end
def self.values
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
values
end
def name_for_token(token, tktype)
if self.class.sections.include? token
tktype
elsif self.class.directives.include? token
tktype
elsif self.class.values.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, Name::Label)
push :section
end
rule %r/\w+/ do |m|
token name_for_token(m[0].downcase, 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].downcase, Literal::String::Symbol)
end
end
end
end
end
|