Add support for Nix
This commit is contained in:
parent
29643f4e46
commit
198bc99a64
|
@ -304,6 +304,10 @@ var components = {
|
|||
"title": "Nim",
|
||||
"owner": "Golmote"
|
||||
},
|
||||
"nix": {
|
||||
"title": "Nix",
|
||||
"owner": "Golmote"
|
||||
},
|
||||
"nsis": {
|
||||
"title": "NSIS",
|
||||
"owner": "idleberg"
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
Prism.languages.nix = {
|
||||
'comment': /\/\*[\s\S]*?\*\/|#.*/,
|
||||
'string': {
|
||||
pattern: /"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,
|
||||
inside: {
|
||||
'interpolation': {
|
||||
// The lookbehind ensures the ${} is not preceded by \ or ''
|
||||
pattern: /(^|(?:^|(?!'').)[^\\])\$\{(?:[^}]|\{[^}]*\})*}/,
|
||||
lookbehind: true,
|
||||
inside: {
|
||||
'antiquotation': {
|
||||
pattern: /^\$(?=\{)/,
|
||||
alias: 'variable'
|
||||
}
|
||||
// See rest below
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'url': [
|
||||
/\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,
|
||||
{
|
||||
pattern: /([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,
|
||||
lookbehind: true
|
||||
}
|
||||
],
|
||||
'antiquotation': {
|
||||
pattern: /\$(?=\{)/,
|
||||
alias: 'variable'
|
||||
},
|
||||
'number': /\b\d+\b/,
|
||||
'keyword': /\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,
|
||||
'function': /\b(?:abort|add|all|any|attrNames|attrValues|baseNameOf|compareVersions|concatLists|currentSystem|deepSeq|derivation|dirOf|div|elem(?:At)?|fetch(?:url|Tarball)|filter(?:Source)?|fromJSON|genList|getAttr|getEnv|hasAttr|hashString|head|import|intersectAttrs|is(?:Attrs|Bool|Function|Int|List|Null|String)|length|lessThan|listToAttrs|map|mul|parseDrvName|pathExists|read(?:Dir|File)|removeAttrs|replaceStrings|seq|sort|stringLength|sub(?:string)?|tail|throw|to(?:File|JSON|Path|String|XML)|trace|typeOf)\b|\bfoldl'\B/,
|
||||
'boolean': /\b(?:true|false)\b/,
|
||||
'operator': /[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,
|
||||
'punctuation': /[{}()[\].,:;]/
|
||||
};
|
||||
|
||||
Prism.languages.nix.string.inside.interpolation.inside.rest = Prism.util.clone(Prism.languages.nix);
|
|
@ -0,0 +1 @@
|
|||
Prism.languages.nix={comment:/\/\*[\s\S]*?\*\/|#.*/,string:{pattern:/"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,inside:{interpolation:{pattern:/(^|(?:^|(?!'').)[^\\])\$\{(?:[^}]|\{[^}]*\})*}/,lookbehind:!0,inside:{antiquotation:{pattern:/^\$(?=\{)/,alias:"variable"}}}}},url:[/\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,{pattern:/([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,lookbehind:!0}],antiquotation:{pattern:/\$(?=\{)/,alias:"variable"},number:/\b\d+\b/,keyword:/\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,"function":/\b(?:abort|add|all|any|attrNames|attrValues|baseNameOf|compareVersions|concatLists|currentSystem|deepSeq|derivation|dirOf|div|elem(?:At)?|fetch(?:url|Tarball)|filter(?:Source)?|fromJSON|genList|getAttr|getEnv|hasAttr|hashString|head|import|intersectAttrs|is(?:Attrs|Bool|Function|Int|List|Null|String)|length|lessThan|listToAttrs|map|mul|parseDrvName|pathExists|read(?:Dir|File)|removeAttrs|replaceStrings|seq|sort|stringLength|sub(?:string)?|tail|throw|to(?:File|JSON|Path|String|XML)|trace|typeOf)\b|\bfoldl'\B/,"boolean":/\b(?:true|false)\b/,operator:/[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,punctuation:/[{}()[\].,:;]/},Prism.languages.nix.string.inside.interpolation.inside.rest=Prism.util.clone(Prism.languages.nix);
|
|
@ -0,0 +1,59 @@
|
|||
<h1>Nix</h1>
|
||||
<p>To use this language, use the class "language-nix".</p>
|
||||
|
||||
<h2>Comments</h2>
|
||||
<pre><code>#
|
||||
# Single line comment
|
||||
/* Multi-line
|
||||
comment */</code></pre>
|
||||
|
||||
<h2>String</h2>
|
||||
<pre><code>""
|
||||
"foo\"bar"
|
||||
"foo
|
||||
bar"
|
||||
|
||||
''''
|
||||
''foo'''bar''
|
||||
''
|
||||
foo
|
||||
bar
|
||||
''</code></pre>
|
||||
|
||||
<h2>String interpolation</h2>
|
||||
<pre><code>"foo${42}bar"
|
||||
"foo\${42}bar" # This is not interpolated
|
||||
''foo${42}bar''
|
||||
''foo''${42}bar'' # This is not interpolated</code></pre>
|
||||
|
||||
<h2>URLs and paths</h2>
|
||||
<pre><code>ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz
|
||||
http://example.org/foo.tar.bz2
|
||||
/bin/sh
|
||||
./builder.sh
|
||||
~/foo.bar</code></pre>
|
||||
|
||||
<h2>Integers, booleans and null</h2>
|
||||
<pre><code>0
|
||||
42
|
||||
|
||||
true
|
||||
false
|
||||
|
||||
null</code></pre>
|
||||
|
||||
<h2>Builtin functions</h2>
|
||||
<pre><code>name = baseNameOf (toString url);
|
||||
imap =
|
||||
if builtins ? genList then
|
||||
f: list: genList (n: f (n + 1) (elemAt list n)) (length list)</code></pre>
|
||||
|
||||
<h2>Known failures</h2>
|
||||
<p>There are certain edge cases where Prism will fail.
|
||||
There are always such cases in every regex-based syntax highlighter.
|
||||
However, Prism dares to be open and honest about them.
|
||||
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
|
||||
</p>
|
||||
|
||||
<h3>Comment-like substrings</h3>
|
||||
<pre><code>"This # is a broken string"</code></pre>
|
|
@ -0,0 +1,14 @@
|
|||
${42}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["antiquotation", "$"],
|
||||
["punctuation", "{"],
|
||||
["number", "42"],
|
||||
["punctuation", "}"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for antiquotations outside of strings.
|
|
@ -0,0 +1,13 @@
|
|||
true
|
||||
false
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["boolean", "true"],
|
||||
["boolean", "false"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for booleans.
|
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# foobar
|
||||
/**/
|
||||
/* foo
|
||||
bar */
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["comment", "#"],
|
||||
["comment", "# foobar"],
|
||||
["comment", "/**/"],
|
||||
["comment", "/* foo\r\nbar */"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for comments.
|
|
@ -0,0 +1,133 @@
|
|||
abort
|
||||
add
|
||||
all
|
||||
any
|
||||
attrNames
|
||||
attrValues
|
||||
baseNameOf
|
||||
compareVersions
|
||||
concatLists
|
||||
currentSystem
|
||||
deepSeq
|
||||
derivation
|
||||
dirOf
|
||||
div
|
||||
elem
|
||||
elemAt
|
||||
fetchurl
|
||||
fetchTarball
|
||||
filter
|
||||
filterSource
|
||||
fromJSON
|
||||
genList
|
||||
getAttr
|
||||
getEnv
|
||||
hasAttr
|
||||
hashString
|
||||
head
|
||||
import
|
||||
intersectAttrs
|
||||
isAttrs
|
||||
isBool
|
||||
isFunction
|
||||
isInt
|
||||
isList
|
||||
isNull
|
||||
isString
|
||||
length
|
||||
lessThan
|
||||
listToAttrs
|
||||
map
|
||||
mul
|
||||
parseDrvName
|
||||
pathExists
|
||||
readDir
|
||||
readFile
|
||||
removeAttrs
|
||||
replaceStrings
|
||||
seq
|
||||
sort
|
||||
stringLength
|
||||
sub
|
||||
substring
|
||||
tail
|
||||
throw
|
||||
toFile
|
||||
toJSON
|
||||
toPath
|
||||
toString
|
||||
toXML
|
||||
trace
|
||||
typeOf
|
||||
foldl'
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["function", "abort"],
|
||||
["function", "add"],
|
||||
["function", "all"],
|
||||
["function", "any"],
|
||||
["function", "attrNames"],
|
||||
["function", "attrValues"],
|
||||
["function", "baseNameOf"],
|
||||
["function", "compareVersions"],
|
||||
["function", "concatLists"],
|
||||
["function", "currentSystem"],
|
||||
["function", "deepSeq"],
|
||||
["function", "derivation"],
|
||||
["function", "dirOf"],
|
||||
["function", "div"],
|
||||
["function", "elem"],
|
||||
["function", "elemAt"],
|
||||
["function", "fetchurl"],
|
||||
["function", "fetchTarball"],
|
||||
["function", "filter"],
|
||||
["function", "filterSource"],
|
||||
["function", "fromJSON"],
|
||||
["function", "genList"],
|
||||
["function", "getAttr"],
|
||||
["function", "getEnv"],
|
||||
["function", "hasAttr"],
|
||||
["function", "hashString"],
|
||||
["function", "head"],
|
||||
["function", "import"],
|
||||
["function", "intersectAttrs"],
|
||||
["function", "isAttrs"],
|
||||
["function", "isBool"],
|
||||
["function", "isFunction"],
|
||||
["function", "isInt"],
|
||||
["function", "isList"],
|
||||
["function", "isNull"],
|
||||
["function", "isString"],
|
||||
["function", "length"],
|
||||
["function", "lessThan"],
|
||||
["function", "listToAttrs"],
|
||||
["function", "map"],
|
||||
["function", "mul"],
|
||||
["function", "parseDrvName"],
|
||||
["function", "pathExists"],
|
||||
["function", "readDir"],
|
||||
["function", "readFile"],
|
||||
["function", "removeAttrs"],
|
||||
["function", "replaceStrings"],
|
||||
["function", "seq"],
|
||||
["function", "sort"],
|
||||
["function", "stringLength"],
|
||||
["function", "sub"],
|
||||
["function", "substring"],
|
||||
["function", "tail"],
|
||||
["function", "throw"],
|
||||
["function", "toFile"],
|
||||
["function", "toJSON"],
|
||||
["function", "toPath"],
|
||||
["function", "toString"],
|
||||
["function", "toXML"],
|
||||
["function", "trace"],
|
||||
["function", "typeOf"],
|
||||
["function", "foldl'"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for built-in functions.
|
|
@ -0,0 +1,15 @@
|
|||
assert builtins else if
|
||||
in inherit let null
|
||||
or then with
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["keyword", "assert"], ["keyword", "builtins"], ["keyword", "else"], ["keyword", "if"],
|
||||
["keyword", "in"], ["keyword", "inherit"], ["keyword", "let"], ["keyword", "null"],
|
||||
["keyword", "or"], ["keyword", "then"], ["keyword", "with"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for keywords.
|
|
@ -0,0 +1,15 @@
|
|||
0
|
||||
42
|
||||
120457
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["number", "0"],
|
||||
["number", "42"],
|
||||
["number", "120457"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for integers.
|
|
@ -0,0 +1,25 @@
|
|||
= ==
|
||||
! !=
|
||||
< <=
|
||||
> >=
|
||||
+ ++
|
||||
- ->
|
||||
|| && //
|
||||
? @
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["operator", "="], ["operator", "=="],
|
||||
["operator", "!"], ["operator", "!="],
|
||||
["operator", "<"], ["operator", "<="],
|
||||
["operator", ">"], ["operator", ">="],
|
||||
["operator", "+"], ["operator", "++"],
|
||||
["operator", "-"], ["operator", "->"],
|
||||
["operator", "||"], ["operator", "&&"], ["operator", "//"],
|
||||
["operator", "?"], ["operator", "@"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for operators.
|
|
@ -0,0 +1,56 @@
|
|||
""
|
||||
"foo\"b\\ar"
|
||||
"f''o'o'\"bar"
|
||||
"foo
|
||||
bar"
|
||||
"foo ${ 42 } baz"
|
||||
"foo \${ 42 } baz"
|
||||
|
||||
''''
|
||||
''
|
||||
foo
|
||||
bar
|
||||
''
|
||||
''
|
||||
f'oo'''ba'r
|
||||
foo ${ 42 } baz
|
||||
foo ''${ 42 } baz
|
||||
''
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["string", ["\"\""]],
|
||||
["string", ["\"foo\\\"b\\\\ar\""]],
|
||||
["string", ["\"f''o'o'\\\"bar\""]],
|
||||
["string", ["\"foo\r\nbar\""]],
|
||||
["string", [
|
||||
"\"foo ",
|
||||
["interpolation", [
|
||||
["antiquotation", "$"],
|
||||
["punctuation", "{"],
|
||||
["number", "42"],
|
||||
["punctuation", "}"]
|
||||
]],
|
||||
" baz\""
|
||||
]],
|
||||
["string", ["\"foo \\${ 42 } baz\""]],
|
||||
|
||||
["string", ["''''"]],
|
||||
["string", ["''\r\nfoo\r\nbar\r\n''"]],
|
||||
["string", [
|
||||
"''\r\nf'oo'''ba'r\r\nfoo ",
|
||||
["interpolation", [
|
||||
["antiquotation", "$"],
|
||||
["punctuation", "{"],
|
||||
["number", "42"],
|
||||
["punctuation", "}"]
|
||||
]],
|
||||
" baz\r\nfoo ''${ 42 } baz\r\n''"
|
||||
]]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for strings and string interpolation.
|
||||
Also checks that escaped interpolations are not interpreted.
|
|
@ -0,0 +1,21 @@
|
|||
http://example.org/foo.tar.bz2
|
||||
ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz
|
||||
|
||||
/bin/sh
|
||||
./builder.sh
|
||||
~/foo.bar
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["url", "http://example.org/foo.tar.bz2"],
|
||||
["url", "ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz"],
|
||||
|
||||
["url", "/bin/sh"],
|
||||
["url", "./builder.sh"],
|
||||
["url", "~/foo.bar"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for URLs and paths.
|
Loading…
Reference in New Issue