forked from rouge-ruby/rouge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
apache.rb
69 lines (56 loc) · 1.58 KB
/
apache.rb
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
# 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.keywords
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
keywords
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