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
|
-- mod-version:2 -- lite-xl 2.0
local syntax = require "core.syntax"
local keywords = {
"AddCharset", "AddDefaultCharset", "AddHandler", "AddOutputFilterByType", "AddType", "Allow",
"AuthName", "AuthType", "AuthUserFile", "BrowserMatch", "CheckSpelling", "DefaultLanguage",
"Deny", "DirectoryIndex", "ErrorDocument", "ExpiresActive", "ExpiresByType", "ExpiresDefault",
"FallbackResource", "FileETag", "ForceType", "from", "Header", "IndexIgnore", "LimitRequestBody",
"LoadModule", "Options", "Order", "php_flag", "php_value", "Redirect", "RedirectMatch",
"RequestHeader", "Require", "RewriteBase", "RewriteCond", "RewriteEngine", "RewriteRule",
"Satisfy", "ServerSignature", "SetEnv", "SetEnvIf", "SetEnvIfNoCase",
}
local literals = {
"on", "off", "deny", "denied", "all", "All", "allow", "Basic", "valid-user", "append", "unset",
"set", "DEFLATE",
}
local symbols = {}
for _,kw in ipairs(keywords) do
symbols[kw] = "keyword"
end
for _,lt in ipairs(literals) do
symbols[lt] = "literal"
end
local url_syntax = {
patterns = {
{ pattern = "[%%$]%{?[%w_]+%}?", type = "keyword2" },
{ pattern = "[^%%$%s]", type = "string" }
},
symbols = {}
}
local xml_syntax = {
patterns = {{ pattern = { '"', '"', '\\' }, type = "string" }},
symbols = {}
}
syntax.add {
name = ".htaccess File",
files = { "%.htaccess$" },
comment = "#",
patterns = {
-- Comments
{ pattern = "#.*\n", type = "comment" },
-- Strings
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = { '`', '`', '\\' }, type = "string" },
-- URLs
{ pattern = { "%w-://", "%s" }, type = "string", syntax = url_syntax },
{ pattern = { "%s/", "%s" }, type = "string", syntax = url_syntax },
-- Mime types
{ pattern = "application/[%w%._+-]+", type = "keyword2" },
{ pattern = "font/[%w%._+-]+", type = "keyword2" },
{ pattern = "image/[%w%._+-]+", type = "keyword2" },
{ pattern = "text/[%w%._+-]+", type = "keyword2" },
{ pattern = "audio/[%w%._+-]+", type = "keyword2" },
{ pattern = "video/[%w%._+-]+", type = "keyword2" },
-- IPs
{ pattern = "%d+.%d+.%d+.%d+", type = "keyword2" },
{ pattern = "%d+.%d+.%d+.%d+/%d+", type = "keyword2" },
-- Regex (TODO: improve this, it's pretty naive and only works on some regex)
{ pattern = "%^%S*", type = "literal" },
{ pattern = "%S*%$", type = "literal" },
{ pattern = "%b()", type = "literal" },
-- Rewrite option sections
{ pattern = "%b[]", type = "number" },
-- XML tags
{ pattern = { "</?%w+", ">" }, type = "literal", syntax = xml_syntax },
-- Variables
{ pattern = "[%%$][%w_%{%}]+", type = "keyword2" },
-- Everything else
{ pattern = "[%a_][%w_-]*", type = "symbol" },
},
symbols = symbols
}
|