-
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.
Merge pull request #795 from Golmote/prism-nix
Add support for Nix
- Loading branch information
Showing
13 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
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,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); |
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,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> |
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,14 @@ | ||
${42} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["antiquotation", "$"], | ||
["punctuation", "{"], | ||
["number", "42"], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for antiquotations outside of strings. |
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,13 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for booleans. |
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,18 @@ | ||
# | ||
# foobar | ||
/**/ | ||
/* foo | ||
bar */ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "#"], | ||
["comment", "# foobar"], | ||
["comment", "/**/"], | ||
["comment", "/* foo\r\nbar */"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
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,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. |
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,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. |
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,15 @@ | ||
0 | ||
42 | ||
120457 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "0"], | ||
["number", "42"], | ||
["number", "120457"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for integers. |
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,25 @@ | ||
= == | ||
! != | ||
< <= | ||
> >= | ||
+ ++ | ||
- -> | ||
|| && // | ||
? @ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", "="], ["operator", "=="], | ||
["operator", "!"], ["operator", "!="], | ||
["operator", "<"], ["operator", "<="], | ||
["operator", ">"], ["operator", ">="], | ||
["operator", "+"], ["operator", "++"], | ||
["operator", "-"], ["operator", "->"], | ||
["operator", "||"], ["operator", "&&"], ["operator", "//"], | ||
["operator", "?"], ["operator", "@"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
Oops, something went wrong.