main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
2.2 KB
|
Line | |
---|
1 | 'use strict'
|
---|
2 |
|
---|
3 | module.exports = systemd
|
---|
4 | systemd.displayName = 'systemd'
|
---|
5 | systemd.aliases = []
|
---|
6 | function systemd(Prism) {
|
---|
7 | // https://www.freedesktop.org/software/systemd/man/systemd.syntax.html
|
---|
8 | ;(function (Prism) {
|
---|
9 | var comment = {
|
---|
10 | pattern: /^[;#].*/m,
|
---|
11 | greedy: true
|
---|
12 | }
|
---|
13 | var quotesSource = /"(?:[^\r\n"\\]|\\(?:[^\r]|\r\n?))*"(?!\S)/.source
|
---|
14 | Prism.languages.systemd = {
|
---|
15 | comment: comment,
|
---|
16 | section: {
|
---|
17 | pattern: /^\[[^\n\r\[\]]*\](?=[ \t]*$)/m,
|
---|
18 | greedy: true,
|
---|
19 | inside: {
|
---|
20 | punctuation: /^\[|\]$/,
|
---|
21 | 'section-name': {
|
---|
22 | pattern: /[\s\S]+/,
|
---|
23 | alias: 'selector'
|
---|
24 | }
|
---|
25 | }
|
---|
26 | },
|
---|
27 | key: {
|
---|
28 | pattern: /^[^\s=]+(?=[ \t]*=)/m,
|
---|
29 | greedy: true,
|
---|
30 | alias: 'attr-name'
|
---|
31 | },
|
---|
32 | value: {
|
---|
33 | // This pattern is quite complex because of two properties:
|
---|
34 | // 1) Quotes (strings) must be preceded by a space. Since we can't use lookbehinds, we have to "resolve"
|
---|
35 | // the lookbehind. You will see this in the main loop where spaces are handled separately.
|
---|
36 | // 2) Line continuations.
|
---|
37 | // After line continuations, empty lines and comments are ignored so we have to consume them.
|
---|
38 | pattern: RegExp(
|
---|
39 | /(=[ \t]*(?!\s))/.source + // the value either starts with quotes or not
|
---|
40 | '(?:' +
|
---|
41 | quotesSource +
|
---|
42 | '|(?=[^"\r\n]))' + // main loop
|
---|
43 | '(?:' +
|
---|
44 | (/[^\s\\]/.source + // handle spaces separately because of quotes
|
---|
45 | '|' +
|
---|
46 | '[ \t]+(?:(?![ \t"])|' +
|
---|
47 | quotesSource +
|
---|
48 | ')' + // line continuation
|
---|
49 | '|' +
|
---|
50 | /\\[\r\n]+(?:[#;].*[\r\n]+)*(?![#;])/.source) +
|
---|
51 | ')*'
|
---|
52 | ),
|
---|
53 | lookbehind: true,
|
---|
54 | greedy: true,
|
---|
55 | alias: 'attr-value',
|
---|
56 | inside: {
|
---|
57 | comment: comment,
|
---|
58 | quoted: {
|
---|
59 | pattern: RegExp(/(^|\s)/.source + quotesSource),
|
---|
60 | lookbehind: true,
|
---|
61 | greedy: true
|
---|
62 | },
|
---|
63 | punctuation: /\\$/m,
|
---|
64 | boolean: {
|
---|
65 | pattern: /^(?:false|no|off|on|true|yes)$/,
|
---|
66 | greedy: true
|
---|
67 | }
|
---|
68 | }
|
---|
69 | },
|
---|
70 | punctuation: /=/
|
---|
71 | }
|
---|
72 | })(Prism)
|
---|
73 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.