1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function nginx(hljs) {
|
11 | const regex = hljs.regex;
|
12 | const VAR = {
|
13 | className: 'variable',
|
14 | variants: [
|
15 | { begin: /\$\d+/ },
|
16 | { begin: /\$\{\w+\}/ },
|
17 | { begin: regex.concat(/[$@]/, hljs.UNDERSCORE_IDENT_RE) }
|
18 | ]
|
19 | };
|
20 | const LITERALS = [
|
21 | "on",
|
22 | "off",
|
23 | "yes",
|
24 | "no",
|
25 | "true",
|
26 | "false",
|
27 | "none",
|
28 | "blocked",
|
29 | "debug",
|
30 | "info",
|
31 | "notice",
|
32 | "warn",
|
33 | "error",
|
34 | "crit",
|
35 | "select",
|
36 | "break",
|
37 | "last",
|
38 | "permanent",
|
39 | "redirect",
|
40 | "kqueue",
|
41 | "rtsig",
|
42 | "epoll",
|
43 | "poll",
|
44 | "/dev/poll"
|
45 | ];
|
46 | const DEFAULT = {
|
47 | endsWithParent: true,
|
48 | keywords: {
|
49 | $pattern: /[a-z_]{2,}|\/dev\/poll/,
|
50 | literal: LITERALS
|
51 | },
|
52 | relevance: 0,
|
53 | illegal: '=>',
|
54 | contains: [
|
55 | hljs.HASH_COMMENT_MODE,
|
56 | {
|
57 | className: 'string',
|
58 | contains: [
|
59 | hljs.BACKSLASH_ESCAPE,
|
60 | VAR
|
61 | ],
|
62 | variants: [
|
63 | {
|
64 | begin: /"/,
|
65 | end: /"/
|
66 | },
|
67 | {
|
68 | begin: /'/,
|
69 | end: /'/
|
70 | }
|
71 | ]
|
72 | },
|
73 |
|
74 | {
|
75 | begin: '([a-z]+):/',
|
76 | end: '\\s',
|
77 | endsWithParent: true,
|
78 | excludeEnd: true,
|
79 | contains: [ VAR ]
|
80 | },
|
81 | {
|
82 | className: 'regexp',
|
83 | contains: [
|
84 | hljs.BACKSLASH_ESCAPE,
|
85 | VAR
|
86 | ],
|
87 | variants: [
|
88 | {
|
89 | begin: "\\s\\^",
|
90 | end: "\\s|\\{|;",
|
91 | returnEnd: true
|
92 | },
|
93 |
|
94 | {
|
95 | begin: "~\\*?\\s+",
|
96 | end: "\\s|\\{|;",
|
97 | returnEnd: true
|
98 | },
|
99 |
|
100 | { begin: "\\*(\\.[a-z\\-]+)+" },
|
101 |
|
102 | { begin: "([a-z\\-]+\\.)+\\*" }
|
103 | ]
|
104 | },
|
105 |
|
106 | {
|
107 | className: 'number',
|
108 | begin: '\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b'
|
109 | },
|
110 |
|
111 | {
|
112 | className: 'number',
|
113 | begin: '\\b\\d+[kKmMgGdshdwy]?\\b',
|
114 | relevance: 0
|
115 | },
|
116 | VAR
|
117 | ]
|
118 | };
|
119 |
|
120 | return {
|
121 | name: 'Nginx config',
|
122 | aliases: [ 'nginxconf' ],
|
123 | contains: [
|
124 | hljs.HASH_COMMENT_MODE,
|
125 | {
|
126 | beginKeywords: "upstream location",
|
127 | end: /;|\{/,
|
128 | contains: DEFAULT.contains,
|
129 | keywords: { section: "upstream location" }
|
130 | },
|
131 | {
|
132 | className: 'section',
|
133 | begin: regex.concat(hljs.UNDERSCORE_IDENT_RE + regex.lookahead(/\s+\{/)),
|
134 | relevance: 0
|
135 | },
|
136 | {
|
137 | begin: regex.lookahead(hljs.UNDERSCORE_IDENT_RE + '\\s'),
|
138 | end: ';|\\{',
|
139 | contains: [
|
140 | {
|
141 | className: 'attribute',
|
142 | begin: hljs.UNDERSCORE_IDENT_RE,
|
143 | starts: DEFAULT
|
144 | }
|
145 | ],
|
146 | relevance: 0
|
147 | }
|
148 | ],
|
149 | illegal: '[^\\s\\}\\{]'
|
150 | };
|
151 | }
|
152 |
|
153 | module.exports = nginx;
|