-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Systemd configuration files (#3053)
- Loading branch information
1 parent
87e5a37
commit 8df825e
Showing
12 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// https://www.freedesktop.org/software/systemd/man/systemd.syntax.html | ||
|
||
(function (Prism) { | ||
|
||
var comment = { | ||
pattern: /^[;#].*/m, | ||
greedy: true | ||
}; | ||
|
||
var quotesSource = /"(?:[^\r\n"\\]|\\(?:[^\r]|\r\n?))*"(?!\S)/.source; | ||
|
||
Prism.languages.systemd = { | ||
'comment': comment, | ||
|
||
'section': { | ||
pattern: /^\[[^\n\r\[\]]*\](?=[ \t]*$)/m, | ||
greedy: true, | ||
inside: { | ||
'punctuation': /^\[|\]$/, | ||
'section-name': { | ||
pattern: /[\s\S]+/, | ||
alias: 'selector' | ||
}, | ||
} | ||
}, | ||
|
||
'key': { | ||
pattern: /^[^\s=]+(?=[ \t]*=)/m, | ||
greedy: true, | ||
alias: 'attr-name' | ||
}, | ||
'value': { | ||
// This pattern is quite complex because of two properties: | ||
// 1) Quotes (strings) must be preceded by a space. Since we can't use lookbehinds, we have to "resolve" | ||
// the lookbehind. You will see this in the main loop where spaces are handled separately. | ||
// 2) Line continuations. | ||
// After line continuations, empty lines and comments are ignored so we have to consume them. | ||
pattern: RegExp( | ||
/(=[ \t]*(?!\s))/.source + | ||
// the value either starts with quotes or not | ||
'(?:' + quotesSource + '|(?=[^"\r\n]))' + | ||
// main loop | ||
'(?:' + ( | ||
/[^\s\\]/.source + | ||
// handle spaces separately because of quotes | ||
'|' + '[ \t]+(?:(?![ \t"])|' + quotesSource + ')' + | ||
// line continuation | ||
'|' + /\\[\r\n]+(?:[#;].*[\r\n]+)*(?![#;])/.source | ||
) + | ||
')*' | ||
), | ||
lookbehind: true, | ||
greedy: true, | ||
alias: 'attr-value', | ||
inside: { | ||
'comment': comment, | ||
'quoted': { | ||
pattern: RegExp(/(^|\s)/.source + quotesSource), | ||
lookbehind: true, | ||
greedy: true, | ||
}, | ||
'punctuation': /\\$/m, | ||
|
||
'boolean': { | ||
pattern: /^(?:false|no|off|on|true|yes)$/, | ||
greedy: true | ||
} | ||
} | ||
}, | ||
|
||
'operator': /=/ | ||
}; | ||
|
||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h2>Full example</h2> | ||
<pre><code># Source: https://www.freedesktop.org/software/systemd/man/systemd.syntax.html | ||
|
||
[Section A] | ||
KeyOne=value 1 | ||
KeyTwo=value 2 | ||
|
||
# a comment | ||
|
||
[Section B] | ||
Setting="something" "some thing" "…" | ||
KeyTwo=value 2 \ | ||
value 2 continued | ||
|
||
[Section C] | ||
KeyThree=value 3\ | ||
# this line is ignored | ||
; this line is ignored too | ||
value 3 continued | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
foo=on | ||
foo=true | ||
foo=yes | ||
foo=off | ||
foo=false | ||
foo=no | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["boolean", "on"] | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["boolean", "true"] | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["boolean", "yes"] | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["boolean", "off"] | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["boolean", "false"] | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["boolean", "no"] | ||
]] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# comment | ||
; comment | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "# comment"], | ||
["comment", "; comment"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
foo= | ||
foo = | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["key", "foo"], ["operator", "="], | ||
["key", "foo"], ["operator", "="] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Section Foo] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["section", [ | ||
["punctuation", "["], | ||
["section-name", "Section Foo"], | ||
["punctuation", "]"] | ||
]] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
foo= value 2 | ||
|
||
foo="something" "some thing" "…" | ||
foo= "something" "some thing" "…" | ||
foo=value 2 \ | ||
value 2 continued | ||
|
||
foo=value 3\ | ||
# this line is ignored | ||
; this line is ignored too | ||
value 3 continued | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["key", "foo"], ["operator", "="], ["value", ["value 2"]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["quoted", "\"something\""], | ||
["quoted", "\"some thing\""], | ||
["quoted", "\"…\""] | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
["quoted", "\"something\""], | ||
["quoted", "\"some thing\""], | ||
["quoted", "\"…\""] | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
"value 2 ", ["punctuation", "\\"], | ||
"\r\n value 2 continued" | ||
]], | ||
|
||
["key", "foo"], | ||
["operator", "="], | ||
["value", [ | ||
"value 3", ["punctuation", "\\"], | ||
["comment", "# this line is ignored"], | ||
["comment", "; this line is ignored too"], | ||
"\r\n value 3 continued" | ||
]] | ||
] |