-
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 JQ language (#1896)
This adds support for the JQ language.
- Loading branch information
1 parent
0853e69
commit 73d964b
Showing
17 changed files
with
380 additions
and
3 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,67 @@ | ||
(function (Prism) { | ||
|
||
var interpolation = /\\\((?:[^()]|\([^()]*\))*\)/.source; | ||
var string = RegExp(/"(?:[^"\r\n\\]|\\[^\r\n(]|__)*"/.source.replace(/__/g, interpolation)); | ||
var stringInterpolation = { | ||
'interpolation': { | ||
pattern: RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + interpolation), | ||
lookbehind: true, | ||
inside: { | ||
'content': { | ||
pattern: /^(\\\()[\s\S]+(?=\)$)/, | ||
lookbehind: true, | ||
inside: null // see below | ||
}, | ||
'punctuation': /^\\\(|\)$/ | ||
} | ||
} | ||
}; | ||
|
||
var jq = Prism.languages.jq = { | ||
'comment': /#.*/, | ||
'property': { | ||
pattern: RegExp(string.source + /(?=\s*:(?!:))/.source), | ||
greedy: true, | ||
inside: stringInterpolation | ||
}, | ||
'string': { | ||
pattern: string, | ||
greedy: true, | ||
inside: stringInterpolation | ||
}, | ||
|
||
'function': { | ||
pattern: /(\bdef\s+)[a-z_]\w+/i, | ||
lookbehind: true | ||
}, | ||
|
||
'variable': /\B\$\w+/, | ||
'property-literal': { | ||
pattern: /[a-z_]\w*(?=\s*:(?!:))/i, | ||
alias: 'property' | ||
}, | ||
'keyword': /\b(?:as|break|catch|def|elif|else|end|foreach|if|import|include|label|module|modulemeta|null|reduce|then|try|while)\b/, | ||
'boolean': /\b(?:true|false)\b/, | ||
'number': /(?:\b\d+\.|\B\.)?\d+(?:[eE][+-]?\d+)?\b/, | ||
|
||
'operator': [ | ||
{ | ||
pattern: /\|=?/, | ||
alias: 'pipe' | ||
}, | ||
/\.\.|[!=<>]?=|\?\/\/|\/\/=?|[-+*/%]=?|[<>?]|\b(?:and|or|not)\b/ | ||
], | ||
'c-style-function': { | ||
pattern: /\b[a-z_]\w*(?=\s*\()/i, | ||
alias: 'function' | ||
}, | ||
'punctuation': /::|[()\[\]{},:;]|\.(?=\s*[\[\w$])/, | ||
'dot': { | ||
pattern: /\./, | ||
alias: 'important' | ||
} | ||
} | ||
|
||
stringInterpolation.interpolation.inside.content.inside = jq; | ||
|
||
}(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,11 @@ | ||
<h2>Full example</h2> | ||
<pre><code># comment | ||
def some_method: | ||
to_entries | sort_by(.foo) | | ||
map(.foo) as $keys | | ||
map(.bar) | transpose | | ||
map( | ||
[$keys, .] | transpose | | ||
map({foo: .[0], bar: .[1], "foo-bar": "foo\("-" + "bar")"}) | from_entries | ||
) | ||
;</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,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,13 @@ | ||
# foo | ||
# | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "# foo"], | ||
["comment", "#"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,11 @@ | ||
. | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["dot", "."] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for the dot. |
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,31 @@ | ||
def foo: | ||
def bar(x,y,z): | ||
fooBar(x) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "def"], | ||
["function", "foo"], | ||
["punctuation", ":"], | ||
|
||
["keyword", "def"], | ||
["function", "bar"], | ||
["punctuation", "("], | ||
"x", | ||
["punctuation", ","], | ||
"y", | ||
["punctuation", ","], | ||
"z", | ||
["punctuation", ")"], | ||
["punctuation", ":"], | ||
|
||
["c-style-function", "fooBar"], | ||
["punctuation", "("], | ||
"x", | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for 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,47 @@ | ||
as | ||
break | ||
catch | ||
def; | ||
elif | ||
else | ||
end | ||
foreach | ||
if | ||
import | ||
include | ||
label | ||
module | ||
modulemeta | ||
null | ||
reduce | ||
then | ||
try | ||
while | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "as"], | ||
["keyword", "break"], | ||
["keyword", "catch"], | ||
["keyword", "def"], ["punctuation", ";"], | ||
["keyword", "elif"], | ||
["keyword", "else"], | ||
["keyword", "end"], | ||
["keyword", "foreach"], | ||
["keyword", "if"], | ||
["keyword", "import"], | ||
["keyword", "include"], | ||
["keyword", "label"], | ||
["keyword", "module"], | ||
["keyword", "modulemeta"], | ||
["keyword", "null"], | ||
["keyword", "reduce"], | ||
["keyword", "then"], | ||
["keyword", "try"], | ||
["keyword", "while"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,46 @@ | ||
.. | ||
== != >= <= < > | ||
= ? | ||
?// //= | ||
+ - * / % | += -= *= /= %= |= | ||
and or not | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", ".."], | ||
|
||
["operator", "=="], | ||
["operator", "!="], | ||
["operator", ">="], | ||
["operator", "<="], | ||
["operator", "<"], | ||
["operator", ">"], | ||
|
||
["operator", "="], | ||
["operator", "?"], | ||
|
||
["operator", "?//"], | ||
["operator", "//="], | ||
|
||
["operator", "+"], | ||
["operator", "-"], | ||
["operator", "*"], | ||
["operator", "/"], | ||
["operator", "%"], | ||
["operator", "|"], | ||
["operator", "+="], | ||
["operator", "-="], | ||
["operator", "*="], | ||
["operator", "/="], | ||
["operator", "%="], | ||
["operator", "|="], | ||
|
||
["operator", "and"], | ||
["operator", "or"], | ||
["operator", "not"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
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,45 @@ | ||
{ foo: 1, "bar": 2, "foo\("Bar")": 3 } | ||
|
||
# not a property | ||
foo::bar | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["punctuation", "{"], | ||
["property-literal", "foo"], | ||
["punctuation", ":"], | ||
["number", "1"], | ||
["punctuation", ","], | ||
["property", [ | ||
"\"bar\"" | ||
]], | ||
["punctuation", ":"], | ||
["number", "2"], | ||
["punctuation", ","], | ||
["property", [ | ||
"\"foo", | ||
["interpolation", [ | ||
["punctuation", "\\("], | ||
["content", [ | ||
["string", [ | ||
"\"Bar\"" | ||
]] | ||
]], | ||
["punctuation", ")"] | ||
]], | ||
"\"" | ||
]], | ||
["punctuation", ":"], | ||
["number", "3"], | ||
["punctuation", "}"], | ||
|
||
["comment", "# not a property"], | ||
"\r\nfoo", | ||
["punctuation", "::"], | ||
"bar" | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for properties. |
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,33 @@ | ||
() [] {} | ||
, : ; | ||
:: | ||
.foo | ||
.[] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
["punctuation", "["], | ||
["punctuation", "]"], | ||
["punctuation", "{"], | ||
["punctuation", "}"], | ||
|
||
["punctuation", ","], | ||
["punctuation", ":"], | ||
["punctuation", ";"], | ||
|
||
["punctuation", "::"], | ||
|
||
["punctuation", "."], | ||
"foo\r\n", | ||
|
||
["punctuation", "."], | ||
["punctuation", "["], | ||
["punctuation", "]"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for 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,42 @@ | ||
"foo" | ||
"\"" | ||
"Aa\r\n\t\b\f\u03bc" | ||
"inter\("pol" + "ation")" | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["string", [ | ||
"\"foo\"" | ||
]], | ||
|
||
["string", [ | ||
"\"\\\"\"" | ||
]], | ||
|
||
["string", [ | ||
"\"Aa\\r\\n\\t\\b\\f\\u03bc\"" | ||
]], | ||
|
||
["string", [ | ||
"\"inter", | ||
["interpolation", [ | ||
["punctuation", "\\("], | ||
["content", [ | ||
["string", [ | ||
"\"pol\"" | ||
]], | ||
["operator", "+"], | ||
["string", [ | ||
"\"ation\"" | ||
]] | ||
]], | ||
["punctuation", ")"] | ||
]], | ||
"\"" | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for strings and string interpolation. |
Oops, something went wrong.