@exercism/codemirror-lang-jq 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/dist/index.cjs +358 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +351 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jq language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives the CodeMirror 6 editor a Lezer grammar for jq 1.8, with highlighting, indentation, folding and autocompletion.
|
|
6
|
+
Exercism uses it in the in-browser editor for the jq track.
|
|
7
|
+
|
|
8
|
+
The Exercism website needs these dependency ranges, so keep them as they are in `package.json`:
|
|
9
|
+
|
|
10
|
+
```json
|
|
11
|
+
"@codemirror/language": "^6.10.1",
|
|
12
|
+
"@lezer/highlight": "^1.2.0",
|
|
13
|
+
"@lezer/lr": "^1.4.0"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
- NPM: `npm install @exercism/codemirror-lang-jq`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-jq`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-jq`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { jq } from "@exercism/codemirror-lang-jq";
|
|
27
|
+
|
|
28
|
+
new EditorView({
|
|
29
|
+
extensions: [basicSetup, jq()],
|
|
30
|
+
parent: document.body,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## What it does
|
|
35
|
+
|
|
36
|
+
- It highlights keywords, strings and their escapes, string formats such as `@base64`, numbers, comments, function definitions and calls, variables, field names and operators.
|
|
37
|
+
- It indents the body of a `def`, an `if`, a `reduce` or a `foreach`, and the contents of brackets. It folds the same blocks.
|
|
38
|
+
- Its autocompletion offers:
|
|
39
|
+
- jq's keywords, and snippets for a function, `if` with and without `elif`, `reduce`, `foreach`, `try` and `catch`, an `as $x |` binding, a label, and an import.
|
|
40
|
+
- jq 1.8's built-in functions. A function with several argument counts gets one option per count. For example, `range` appears three times: `range(upto)`, `range(from; upto)` and `range(from; upto; by)`.
|
|
41
|
+
- the string formats after `@`, and `$ENV` and `$__loc__` after `$`.
|
|
42
|
+
- functions defined in the file and in scope at the cursor, with their parameters, and the parameters of the function that the cursor is inside.
|
|
43
|
+
- variables in scope at the cursor: those bound by `as`, `reduce`, `foreach` and `label`, and the `$` parameters of the enclosing function.
|
|
44
|
+
|
|
45
|
+
Completion is active in code and inside a string's `\(...)`. It is off in comments, strings and field names.
|
|
46
|
+
|
|
47
|
+
## How the grammar is built
|
|
48
|
+
|
|
49
|
+
The grammar in `src/syntax.grammar` follows the yacc grammar in jq's own [`src/parser.y`](https://github.com/jqlang/jq/blob/master/src/parser.y), so it parses code the way jq does.
|
|
50
|
+
For example, `,` is grouped before `|`, so `a, b | c` means `(a, b) | c`. A `def`, an `as` binding or a `label` covers everything after it, up to the end of the query.
|
|
51
|
+
The syntax tree uses different node types for definitions (`FunctionName`, `ParameterName`, `VariableDefinition`) and references (`Identifier`, `VariableName`). The completion uses the definition nodes to find the names in scope.
|
|
52
|
+
|
|
53
|
+
## Prerequisites
|
|
54
|
+
|
|
55
|
+
- [Bun](https://bun.sh/)
|
|
56
|
+
|
|
57
|
+
## Setup
|
|
58
|
+
|
|
59
|
+
Run `bun install` to install all dependencies.
|
|
60
|
+
|
|
61
|
+
## Developing
|
|
62
|
+
|
|
63
|
+
Run `bun run dev` to start a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/). It shows `index.html` with some sample jq code.
|
|
64
|
+
|
|
65
|
+
The grammar is in `src/syntax.grammar`, and the completion is in `src/complete.ts` and `src/builtins.ts`.
|
|
66
|
+
|
|
67
|
+
## Building
|
|
68
|
+
|
|
69
|
+
Run `bun run prepare` to build the package into `dist`.
|
|
70
|
+
`bun install` also runs this script.
|
|
71
|
+
|
|
72
|
+
## Testing
|
|
73
|
+
|
|
74
|
+
Run `bun run test`. It builds the package and then runs the tests in `test/`.
|
|
75
|
+
|
|
76
|
+
- `test/cases/*.txt` hold the grammar tests, in [Lezer's test format](https://lezer.codemirror.net/docs/guide/#running-the-grammar).
|
|
77
|
+
- `test/completion.test.ts` checks what the completion offers at a given position.
|
|
78
|
+
- `test/editor.test.ts` checks highlighting, indentation and folding.
|
|
79
|
+
|
|
80
|
+
## Resources
|
|
81
|
+
|
|
82
|
+
- [CodeMirror](https://codemirror.net/docs/)
|
|
83
|
+
- [Lezer](https://lezer.codemirror.net/docs/guide/)
|
|
84
|
+
- [The jq manual](https://jqlang.org/manual/)
|
|
85
|
+
|
|
86
|
+
## Publishing
|
|
87
|
+
|
|
88
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
89
|
+
Then push a git tag named `v` followed by that version, such as `v1.0.1` for version 1.0.1.
|
|
90
|
+
The publish workflow builds and tests the package, then publishes it to npm.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lr = require('@lezer/lr');
|
|
4
|
+
var language = require('@codemirror/language');
|
|
5
|
+
var highlight = require('@lezer/highlight');
|
|
6
|
+
var autocomplete = require('@codemirror/autocomplete');
|
|
7
|
+
|
|
8
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
9
|
+
const spec_identifier = {__proto__:null,module:10, def:22, if:24, then:26, elif:28, else:30, end:32, as:34, reduce:36, foreach:38, try:40, catch:42, label:44, break:46, import:48, include:50, and:52, or:54, true:56, false:58, null:60};
|
|
10
|
+
const parser = lr.LRParser.deserialize({
|
|
11
|
+
version: 14,
|
|
12
|
+
states: "@^Q!vQPOOOOQO'#C{'#C{O!}QPO'#D[O$zQPO'#DbOOQO'#Dg'#DgO&wQPO'#DfO(tQPO'#DiO*[QPO'#DlOOQO'#Dw'#DwO*cQPO'#DvO+sQPO'#EvOOQO'#Ew'#EwO._QPO'#E{OOQO'#Ev'#EvO/UQPO'#EtOOQO'#Et'#EtO/uQPO'#EsOOQO'#E{'#E{OOQO'#Es'#EsO0jOQO'#C|O2iQPO'#CdOOQO'#Ek'#EkQYQPOOQOQPOOQYQPOOO2p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unctionDefinition FunctionName ) ( ParamList VariableDefinition ParameterName : BindingExpression Identity . RecursiveDescent Field QuotedField Number Format FormatName BooleanLiteral Null Call Identifier ArgList ParenthesizedExpression ] [ ArrayExpression ReduceExpression ArrayPattern , ObjectPattern ? AlternativeOp ForeachExpression IfExpression BreakExpression UnaryExpression ArithOp - TryExpression SuffixExpression Optional BinaryExpression UpdateOp CompareOp ArithOp + ArithOp * ArithOp / ArithOp % | LabelExpression PipeExpression CommaExpression InterpolationEnd \" ObjectValuePipe Import ModuleName Include",
|
|
16
|
+
maxTerm: 124,
|
|
17
|
+
nodeProps: [
|
|
18
|
+
["openedBy", 6,"{",39,"(",60,"["],
|
|
19
|
+
["closedBy", 7,"}",40,")",61,"]"]
|
|
20
|
+
],
|
|
21
|
+
skippedNodes: [0,1],
|
|
22
|
+
repeatNodeCount: 9,
|
|
23
|
+
tokenData: ",f~RwX^#lpq#lqr$ars$lst$qtu%Yuv&Qxy&_yz&dz{&i{|&q|}&y}!O'O!O!P'W!P!Q(|!Q![)a![!])r!]!^)w!^!_)|!_!`*U!`!a)|!a!b*^!b!c*c!c!}+Q!}#O+x#P#Q+}#R#S+Q#T#o+Q#o#p,S#p#q,X#q#r,a#y#z#l$f$g#l#BY#BZ#l$IS$I_#l$I|$JO#l$JT$JU#l$KV$KW#l&FU&FV#l~#qY#b~X^#lpq#l#y#z#l$f$g#l#BY#BZ#l$IS$I_#l$I|$JO#l$JT$JU#l$KV$KW#l&FU&FV#l~$dP!_!`$g~$lO!r~~$qOq~~$vSP~OY$qZ;'S$q;'S;=`%S<%lO$q~%VP;=`<%l$q~%]R!c!}%f#R#S%f#T#o%f~%kT#e~!Q![%f![!]%z!c!}%f#R#S%f#T#o%f~%}P![!]%Y~&VP!z~!_!`&Y~&_O!q~~&dOx~~&iOw~~&nP!v~!_!`&Y~&vP!t~!_!`&Y~'OO!c~~'TP!l~!_!`&Y~']T!P~!O!P'l!Q!['q!c!}(k#R#S(k#T#o(k~'qO!Q~~'vR!T~!Q!['q!g!h(P#X#Y(P~(SR{|(]}!O(]!Q![(c~(`P!Q![(c~(hP!T~!Q![(c~(pS!R~!Q![(k!c!}(k#R#S(k#T#o(k~)RQ!x~!P!Q)X!_!`&Y~)^P!f~!_!`&Y~)fS!T~!O!P'q!Q![)a!g!h(P#X#Y(P~)wO|~~)|OR~~*RP!r~!_!`$g~*ZP!q~!_!`$g~*cO!e~~*fR!c!}*o#R#S*o#T#o*o~*tS!V~!Q![*o!c!}*o#R#S*o#T#o*o~+VT#c~!Q![+Q![!]+f!c!}+Q#R#S+Q#T#o+Q~+iP![!]+l~+oR!c!}+Q#R#S+Q#T#o+Q~+}O!_~~,SO!^~~,XOV~~,^P!{~!_!`&Y~,fOU~",
|
|
24
|
+
tokenizers: [1, new lr.LocalTokenGroup("!R~RQrsX#O#P^~^O#Q~~aTOxpxyuy;'Sp;'S;=`z<%lOp~uOr~~zOt~~}P;=`<%lp~", 48, 114)],
|
|
25
|
+
topRules: {"Program":[0,2]},
|
|
26
|
+
specialized: [{term: 111, get: (value) => spec_identifier[value] || -1}],
|
|
27
|
+
tokenPrec: 1916
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// jq 1.8's built-in functions, written the way the jq manual writes them.
|
|
31
|
+
// Each arity is its own entry, because jq treats `range/1` and `range/2` as
|
|
32
|
+
// different functions.
|
|
33
|
+
const builtinSignatures = [
|
|
34
|
+
"length", "utf8bytelength", "not", "keys", "keys_unsorted", "has(key)",
|
|
35
|
+
"in(object)", "map(f)", "map_values(f)", "pick(pathexps)", "path(path_expression)",
|
|
36
|
+
"del(path_expression)", "getpath(path)", "setpath(path; value)", "delpaths(paths)",
|
|
37
|
+
"paths", "paths(f)", "to_entries", "from_entries", "with_entries(f)",
|
|
38
|
+
"select(f)", "recurse", "recurse(f)", "recurse(f; cond)", "env", "builtins",
|
|
39
|
+
"input", "inputs", "debug", "debug(msg)", "stderr", "input_filename",
|
|
40
|
+
"input_line_number", "splits(regex)", "splits(regex; flags)", "tostream",
|
|
41
|
+
"fromstream(stream_expression)", "truncate_stream(stream_expression)",
|
|
42
|
+
"add", "add(generator)", "any", "any(condition)",
|
|
43
|
+
"any(generator; condition)", "all", "all(condition)", "all(generator; condition)",
|
|
44
|
+
"flatten", "flatten(depth)", "range(upto)", "range(from; upto)",
|
|
45
|
+
"range(from; upto; by)", "floor", "ceil", "round", "sqrt", "pow(base; exp)",
|
|
46
|
+
"log", "abs", "toarray", "trim", "ltrim", "rtrim", "trimstr(str)",
|
|
47
|
+
"tostring", "tonumber", "type", "infinite", "nan", "isinfinite", "isnan",
|
|
48
|
+
"isnormal", "sort", "sort_by(path_expression)",
|
|
49
|
+
"group_by(path_expression)", "min", "max", "min_by(path_exp)",
|
|
50
|
+
"max_by(path_exp)", "unique", "unique_by(path_exp)", "reverse",
|
|
51
|
+
"contains(element)", "indices(s)", "index(s)", "rindex(s)", "inside(b)",
|
|
52
|
+
"startswith(str)", "endswith(str)", "combinations", "combinations(n)",
|
|
53
|
+
"ltrimstr(str)", "rtrimstr(str)", "explode", "implode", "split(str)",
|
|
54
|
+
"split(regex; flags)", "join(str)", "ascii_downcase", "ascii_upcase",
|
|
55
|
+
"while(cond; update)", "repeat(f)", "until(cond; next)", "walk(f)",
|
|
56
|
+
"transpose", "bsearch(value)", "tojson", "fromjson", "todate", "fromdate",
|
|
57
|
+
"now", "mktime", "gmtime", "localtime", "strptime(fmt)", "strftime(fmt)",
|
|
58
|
+
"strflocaltime(fmt)", "todateiso8601", "fromdateiso8601", "dateadd(u; n)",
|
|
59
|
+
"datesub(u; n)", "date", "test(regex)", "test(regex; flags)",
|
|
60
|
+
"match(regex)", "match(regex; flags)", "capture(regex)",
|
|
61
|
+
"capture(regex; flags)", "scan(regex)", "scan(regex; flags)",
|
|
62
|
+
"sub(regex; tostring)", "sub(regex; tostring; flags)", "gsub(regex; tostring)",
|
|
63
|
+
"gsub(regex; tostring; flags)", "ascii", "error", "error(message)",
|
|
64
|
+
"halt", "halt_error", "halt_error(exit_code)", "empty", "first", "last",
|
|
65
|
+
"first(expr)", "last(expr)", "nth(n)", "nth(n; expr)", "limit(n; expr)",
|
|
66
|
+
"skip(n; expr)", "isempty(exp)",
|
|
67
|
+
"values", "nulls", "booleans", "numbers", "strings",
|
|
68
|
+
"arrays", "objects", "iterables", "scalars", "finites", "normals",
|
|
69
|
+
"leaf_paths", "format(name)", "significand", "logb",
|
|
70
|
+
"gamma", "lgamma", "tgamma", "lgamma_r", "frexp", "modf", "drem(x; y)",
|
|
71
|
+
"ldexp(x; e)", "scalb(x; e)", "scalbln(x; e)", "nearbyint", "trunc",
|
|
72
|
+
"rint", "exp", "exp2", "exp10", "expm1", "log10", "log1p", "log2", "cbrt",
|
|
73
|
+
"sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh",
|
|
74
|
+
"asinh", "acosh", "atanh", "atan2(y; x)", "fabs", "fmax(x; y)",
|
|
75
|
+
"fmin(x; y)", "fmod(x; y)", "fdim(x; y)", "fma(x; y; z)", "hypot(x; y)",
|
|
76
|
+
"copysign(x; y)", "nextafter(x; y)", "nexttoward(x; y)", "remainder(x; y)",
|
|
77
|
+
"j0", "j1", "jn(n; x)", "y0", "y1", "yn(n; x)", "erf", "erfc", "pow10",
|
|
78
|
+
"IN(source)", "IN(source; s)", "INDEX(idx_expr)", "INDEX(stream; idx_expr)",
|
|
79
|
+
"JOIN($idx; idx_expr)", "JOIN($idx; stream; idx_expr)",
|
|
80
|
+
"JOIN($idx; stream; idx_expr; join_expr)",
|
|
81
|
+
"get_search_list", "get_prog_origin", "get_jq_origin",
|
|
82
|
+
"modulemeta", "have_decnum",
|
|
83
|
+
"have_literal_numbers",
|
|
84
|
+
];
|
|
85
|
+
// The `@name` formats for strings.
|
|
86
|
+
const formats = [
|
|
87
|
+
"@text", "@json", "@html", "@uri", "@csv", "@tsv", "@sh", "@base64",
|
|
88
|
+
"@base64d", "@base32", "@base32d",
|
|
89
|
+
];
|
|
90
|
+
// Variables that jq defines in every program.
|
|
91
|
+
const builtinVariables = ["$ENV", "$__loc__"];
|
|
92
|
+
|
|
93
|
+
// A call with arguments inserts a snippet with a field for each argument, so
|
|
94
|
+
// `range(from; upto)` inserts `range(|; )` with the cursor in the first one.
|
|
95
|
+
function functionCompletion(name, params, detail) {
|
|
96
|
+
if (params.length == 0)
|
|
97
|
+
return { label: name, type: "function", detail };
|
|
98
|
+
const fields = params.map((param) => "${" + param + "}").join("; ");
|
|
99
|
+
return autocomplete.snippetCompletion(`${name}(${fields})`, {
|
|
100
|
+
label: name,
|
|
101
|
+
detail: `(${params.join("; ")})${detail ? " " + detail : ""}`,
|
|
102
|
+
type: "function",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/// The built-in functions, one option for each arity.
|
|
106
|
+
const builtins = builtinSignatures.map((signature) => {
|
|
107
|
+
const [, name, params] = /^(\w+)(?:\((.*)\))?$/.exec(signature);
|
|
108
|
+
return functionCompletion(name, params ? params.split(/;\s*/) : []);
|
|
109
|
+
});
|
|
110
|
+
const formatOptions = formats.map((label) => ({ label, type: "constant" }));
|
|
111
|
+
const builtinVariableOptions = builtinVariables.map((label) => ({
|
|
112
|
+
label,
|
|
113
|
+
type: "variable",
|
|
114
|
+
detail: "built-in",
|
|
115
|
+
}));
|
|
116
|
+
const keywords = [
|
|
117
|
+
"def", "if", "then", "elif", "else", "end", "as", "reduce", "foreach", "try",
|
|
118
|
+
"catch", "label", "break", "import", "include", "module", "and", "or",
|
|
119
|
+
"true", "false", "null",
|
|
120
|
+
].map((label) => ({ label, type: "keyword" }));
|
|
121
|
+
/// Snippets for the constructs people write most often in jq.
|
|
122
|
+
const snippets = [
|
|
123
|
+
autocomplete.snippetCompletion("def ${name}: ${};", { label: "def", detail: "function", type: "keyword" }),
|
|
124
|
+
autocomplete.snippetCompletion("def ${name}(${f}): ${};", { label: "def", detail: "function with parameters", type: "keyword" }),
|
|
125
|
+
autocomplete.snippetCompletion("if ${condition} then ${} else ${} end", { label: "if", detail: "then else end", type: "keyword" }),
|
|
126
|
+
autocomplete.snippetCompletion("if ${condition} then ${} elif ${condition} then ${} else ${} end", {
|
|
127
|
+
label: "if",
|
|
128
|
+
detail: "then elif else end",
|
|
129
|
+
type: "keyword",
|
|
130
|
+
}),
|
|
131
|
+
autocomplete.snippetCompletion("reduce ${.[]} as $${x} (${init}; ${update})", { label: "reduce", detail: "as (init; update)", type: "keyword" }),
|
|
132
|
+
autocomplete.snippetCompletion("foreach ${.[]} as $${x} (${init}; ${update}; ${extract})", {
|
|
133
|
+
label: "foreach",
|
|
134
|
+
detail: "as (init; update; extract)",
|
|
135
|
+
type: "keyword",
|
|
136
|
+
}),
|
|
137
|
+
autocomplete.snippetCompletion("try ${} catch ${}", { label: "try", detail: "catch", type: "keyword" }),
|
|
138
|
+
autocomplete.snippetCompletion("as $${x} | ${}", { label: "as", detail: "$x |", type: "keyword" }),
|
|
139
|
+
autocomplete.snippetCompletion("label $${out} | ${}", { label: "label", detail: "$out |", type: "keyword" }),
|
|
140
|
+
autocomplete.snippetCompletion('import "${path}" as ${name};', { label: "import", detail: "as", type: "keyword" }),
|
|
141
|
+
autocomplete.snippetCompletion('include "${path}";', { label: "include", type: "keyword" }),
|
|
142
|
+
];
|
|
143
|
+
// Completion would get in the way while someone writes a comment, a string or
|
|
144
|
+
// a field name, or names a new function, parameter or variable.
|
|
145
|
+
const noCompletion = new Set([
|
|
146
|
+
"Comment", "Field", "FunctionName", "ParameterName", "VariableDefinition", "PropertyName",
|
|
147
|
+
]);
|
|
148
|
+
function completionAllowed(node) {
|
|
149
|
+
for (let cur = node; cur; cur = cur.parent) {
|
|
150
|
+
if (cur.name == "Interpolation" && cur.firstChild && node.from >= cur.firstChild.to)
|
|
151
|
+
return true;
|
|
152
|
+
if (cur.name == "String" || noCompletion.has(cur.name))
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
function text(state, node) {
|
|
158
|
+
return state.sliceDoc(node.from, node.to);
|
|
159
|
+
}
|
|
160
|
+
function childBefore(node, name, pos) {
|
|
161
|
+
for (let child = node.firstChild; child; child = child.nextSibling)
|
|
162
|
+
if (child.name == name && child.to <= pos)
|
|
163
|
+
return child;
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
function addFunction(scope, state, def) {
|
|
167
|
+
const name = def.getChild("FunctionName");
|
|
168
|
+
if (!name)
|
|
169
|
+
return;
|
|
170
|
+
const params = [];
|
|
171
|
+
const list = def.getChild("ParamList");
|
|
172
|
+
if (list)
|
|
173
|
+
for (let child = list.firstChild; child; child = child.nextSibling)
|
|
174
|
+
if (child.name == "ParameterName" || child.name == "VariableDefinition")
|
|
175
|
+
params.push(text(state, child));
|
|
176
|
+
const label = text(state, name);
|
|
177
|
+
// jq tells functions apart by name and arity, and an inner definition
|
|
178
|
+
// hides an outer one with the same name and arity.
|
|
179
|
+
const key = `${label}/${params.length}`;
|
|
180
|
+
if (!scope.functions.has(key))
|
|
181
|
+
scope.functions.set(key, functionCompletion(label, params, "defined here"));
|
|
182
|
+
}
|
|
183
|
+
function addVariables(scope, state, node, from, to, detail) {
|
|
184
|
+
const cursor = node.cursor();
|
|
185
|
+
do {
|
|
186
|
+
if (cursor.from >= to)
|
|
187
|
+
break;
|
|
188
|
+
if (cursor.name == "VariableDefinition" && cursor.from >= from) {
|
|
189
|
+
const label = text(state, cursor.node);
|
|
190
|
+
if (!scope.variables.has(label))
|
|
191
|
+
scope.variables.set(label, { label, type: "variable", detail });
|
|
192
|
+
}
|
|
193
|
+
} while (cursor.next());
|
|
194
|
+
}
|
|
195
|
+
// Walks out from the cursor and collects every name that is in scope there:
|
|
196
|
+
// definitions earlier in an enclosing query, the function around the cursor
|
|
197
|
+
// and its parameters, and the variables bound by `as`, `reduce`, `foreach`
|
|
198
|
+
// and `label`.
|
|
199
|
+
function scopeAt(state, pos) {
|
|
200
|
+
const scope = { functions: new Map(), variables: new Map() };
|
|
201
|
+
let child = null;
|
|
202
|
+
for (let cur = language.syntaxTree(state).resolveInner(pos, -1); cur; child = cur, cur = cur.parent) {
|
|
203
|
+
for (let sibling = cur.lastChild; sibling; sibling = sibling.prevSibling)
|
|
204
|
+
if (sibling.name == "FunctionDefinition" && sibling.to <= pos && sibling != child)
|
|
205
|
+
addFunction(scope, state, sibling);
|
|
206
|
+
switch (cur.name) {
|
|
207
|
+
case "FunctionDefinition": {
|
|
208
|
+
const colon = childBefore(cur, ":", pos);
|
|
209
|
+
if (!colon)
|
|
210
|
+
break;
|
|
211
|
+
addFunction(scope, state, cur);
|
|
212
|
+
const list = cur.getChild("ParamList");
|
|
213
|
+
if (list) {
|
|
214
|
+
addVariables(scope, state, list, list.from, list.to, "parameter");
|
|
215
|
+
for (let param = list.firstChild; param; param = param.nextSibling)
|
|
216
|
+
if (param.name == "ParameterName") {
|
|
217
|
+
const label = text(state, param);
|
|
218
|
+
const key = `${label}/0`;
|
|
219
|
+
if (!scope.functions.has(key))
|
|
220
|
+
scope.functions.set(key, { label, type: "function", detail: "parameter" });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case "BindingExpression":
|
|
226
|
+
case "LabelExpression": {
|
|
227
|
+
const pipe = childBefore(cur, "|", pos);
|
|
228
|
+
if (pipe)
|
|
229
|
+
addVariables(scope, state, cur, cur.from, pipe.from, cur.name == "LabelExpression" ? "label" : undefined);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case "ReduceExpression":
|
|
233
|
+
case "ForeachExpression": {
|
|
234
|
+
// The variable is bound in the update and extract parts, after the
|
|
235
|
+
// first `;`.
|
|
236
|
+
const as = cur.getChild("as");
|
|
237
|
+
const open = cur.getChild("(");
|
|
238
|
+
const semicolon = childBefore(cur, ";", pos);
|
|
239
|
+
if (as && open && semicolon)
|
|
240
|
+
addVariables(scope, state, cur, as.to, open.from);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return scope;
|
|
246
|
+
}
|
|
247
|
+
/// Completes keywords, snippets, built-in functions and formats, and the
|
|
248
|
+
/// functions and variables defined in the file that are in scope at the
|
|
249
|
+
/// cursor.
|
|
250
|
+
function jqCompletionSource(context) {
|
|
251
|
+
const node = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
252
|
+
if (!completionAllowed(node))
|
|
253
|
+
return null;
|
|
254
|
+
const word = context.matchBefore(/[$@]?\w*/);
|
|
255
|
+
if (!word || (word.from == word.to && !context.explicit))
|
|
256
|
+
return null;
|
|
257
|
+
// A dot straight before the word makes it a field name, as in `.name`.
|
|
258
|
+
if (context.state.sliceDoc(word.from - 1, word.from) == ".")
|
|
259
|
+
return null;
|
|
260
|
+
let options;
|
|
261
|
+
if (word.text.startsWith("@")) {
|
|
262
|
+
options = formatOptions;
|
|
263
|
+
}
|
|
264
|
+
else if (word.text.startsWith("$")) {
|
|
265
|
+
options = [...scopeAt(context.state, context.pos).variables.values(), ...builtinVariableOptions];
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
options = [...scopeAt(context.state, context.pos).functions.values(), ...snippets, ...keywords, ...builtins];
|
|
269
|
+
}
|
|
270
|
+
return { from: word.from, options, validFor: /^[$@]?\w*$/ };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Folding keeps the first line and the closing `end`, `;` or `)` in view.
|
|
274
|
+
function foldBody(node, state) {
|
|
275
|
+
const line = state.doc.lineAt(node.from);
|
|
276
|
+
const last = node.lastChild;
|
|
277
|
+
const to = last && /^(end|;|\))$/.test(last.name) ? last.from : node.to;
|
|
278
|
+
return to > line.to ? { from: line.to, to } : null;
|
|
279
|
+
}
|
|
280
|
+
// The lines of a block are indented one unit, and the line that closes it
|
|
281
|
+
// lines up with the line that opened it.
|
|
282
|
+
function blockIndent(closing) {
|
|
283
|
+
return (context) => closing.test(context.textAfter) ? context.baseIndent : context.baseIndent + context.unit;
|
|
284
|
+
}
|
|
285
|
+
const jqLanguage = language.LRLanguage.define({
|
|
286
|
+
name: "jq",
|
|
287
|
+
parser: parser.configure({
|
|
288
|
+
props: [
|
|
289
|
+
language.indentNodeProp.add({
|
|
290
|
+
ParenthesizedExpression: language.delimitedIndent({ closing: ")" }),
|
|
291
|
+
"ArgList ParamList": language.delimitedIndent({ closing: ")" }),
|
|
292
|
+
"ArrayExpression ArrayPattern": language.delimitedIndent({ closing: "]" }),
|
|
293
|
+
"ObjectExpression ObjectPattern": language.delimitedIndent({ closing: "}" }),
|
|
294
|
+
IfExpression: blockIndent(/^\s*(then|elif|else|end)\b/),
|
|
295
|
+
"ReduceExpression ForeachExpression": blockIndent(/^\s*\)/),
|
|
296
|
+
FunctionDefinition: blockIndent(/^\s*;/),
|
|
297
|
+
String: () => null,
|
|
298
|
+
}),
|
|
299
|
+
language.foldNodeProp.add({
|
|
300
|
+
"ParenthesizedExpression ArrayExpression ObjectExpression ArgList": language.foldInside,
|
|
301
|
+
"FunctionDefinition IfExpression ReduceExpression ForeachExpression": foldBody,
|
|
302
|
+
}),
|
|
303
|
+
highlight.styleTags({
|
|
304
|
+
def: highlight.tags.definitionKeyword,
|
|
305
|
+
"if then elif else end reduce foreach try catch label break as": highlight.tags.controlKeyword,
|
|
306
|
+
"import include module": highlight.tags.moduleKeyword,
|
|
307
|
+
"and or": highlight.tags.logicOperator,
|
|
308
|
+
// A `!` stops the tokens inside a node from overriding its tag, as the
|
|
309
|
+
// `end` in `{end: 1}` would.
|
|
310
|
+
"BooleanLiteral!": highlight.tags.bool,
|
|
311
|
+
"Null!": highlight.tags.null,
|
|
312
|
+
Number: highlight.tags.number,
|
|
313
|
+
String: highlight.tags.string,
|
|
314
|
+
Escape: highlight.tags.escape,
|
|
315
|
+
FormatName: highlight.tags.special(highlight.tags.string),
|
|
316
|
+
Comment: highlight.tags.lineComment,
|
|
317
|
+
"FunctionDefinition/FunctionName": highlight.tags.definition(highlight.tags.function(highlight.tags.variableName)),
|
|
318
|
+
"ParameterName VariableDefinition": highlight.tags.definition(highlight.tags.variableName),
|
|
319
|
+
"Call/Identifier": highlight.tags.function(highlight.tags.variableName),
|
|
320
|
+
VariableName: highlight.tags.variableName,
|
|
321
|
+
Field: highlight.tags.propertyName,
|
|
322
|
+
"PropertyName!": highlight.tags.propertyName,
|
|
323
|
+
"Identity!": highlight.tags.self,
|
|
324
|
+
RecursiveDescent: highlight.tags.self,
|
|
325
|
+
ModuleName: highlight.tags.namespace,
|
|
326
|
+
"ArithOp!": highlight.tags.arithmeticOperator,
|
|
327
|
+
CompareOp: highlight.tags.compareOperator,
|
|
328
|
+
UpdateOp: highlight.tags.updateOperator,
|
|
329
|
+
"AlternativeOp |": highlight.tags.operator,
|
|
330
|
+
"Optional!": highlight.tags.operator,
|
|
331
|
+
InterpolationStart: highlight.tags.special(highlight.tags.brace),
|
|
332
|
+
"InterpolationEnd!": highlight.tags.special(highlight.tags.brace),
|
|
333
|
+
"( )": highlight.tags.paren,
|
|
334
|
+
"[ ]": highlight.tags.squareBracket,
|
|
335
|
+
"{ }": highlight.tags.brace,
|
|
336
|
+
", ;": highlight.tags.separator,
|
|
337
|
+
":": highlight.tags.punctuation,
|
|
338
|
+
}),
|
|
339
|
+
],
|
|
340
|
+
}),
|
|
341
|
+
languageData: {
|
|
342
|
+
commentTokens: { line: "#" },
|
|
343
|
+
closeBrackets: { brackets: ["(", "[", "{", '"'] },
|
|
344
|
+
indentOnInput: /^\s*(then|elif|else|end|;|[\]})])$/,
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
/// jq language support, with completion for keywords, snippets, built-in
|
|
348
|
+
/// functions and formats, and the functions and variables defined in the file.
|
|
349
|
+
function jq() {
|
|
350
|
+
return new language.LanguageSupport(jqLanguage, jqLanguage.data.of({ autocomplete: jqCompletionSource }));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
exports.builtins = builtins;
|
|
354
|
+
exports.jq = jq;
|
|
355
|
+
exports.jqCompletionSource = jqCompletionSource;
|
|
356
|
+
exports.jqLanguage = jqLanguage;
|
|
357
|
+
exports.parser = parser;
|
|
358
|
+
exports.snippets = snippets;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parser } from "./syntax.grammar";
|
|
2
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
3
|
+
import { Completion, CompletionContext, CompletionResult } from "@codemirror/autocomplete";
|
|
4
|
+
/// The built-in functions, one option for each arity.
|
|
5
|
+
declare const builtins: readonly Completion[];
|
|
6
|
+
/// Snippets for the constructs people write most often in jq.
|
|
7
|
+
declare const snippets: readonly Completion[];
|
|
8
|
+
/// Completes keywords, snippets, built-in functions and formats, and the
|
|
9
|
+
/// functions and variables defined in the file that are in scope at the
|
|
10
|
+
/// cursor.
|
|
11
|
+
declare function jqCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
12
|
+
declare const jqLanguage: LRLanguage;
|
|
13
|
+
declare function jq(): LanguageSupport;
|
|
14
|
+
export { jqLanguage, jq, parser, builtins, snippets, jqCompletionSource };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parser } from "./syntax.grammar";
|
|
2
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
3
|
+
import { Completion, CompletionContext, CompletionResult } from "@codemirror/autocomplete";
|
|
4
|
+
/// The built-in functions, one option for each arity.
|
|
5
|
+
declare const builtins: readonly Completion[];
|
|
6
|
+
/// Snippets for the constructs people write most often in jq.
|
|
7
|
+
declare const snippets: readonly Completion[];
|
|
8
|
+
/// Completes keywords, snippets, built-in functions and formats, and the
|
|
9
|
+
/// functions and variables defined in the file that are in scope at the
|
|
10
|
+
/// cursor.
|
|
11
|
+
declare function jqCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
12
|
+
declare const jqLanguage: LRLanguage;
|
|
13
|
+
declare function jq(): LanguageSupport;
|
|
14
|
+
export { jqLanguage, jq, parser, builtins, snippets, jqCompletionSource };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { LRParser, LocalTokenGroup } from '@lezer/lr';
|
|
2
|
+
import { syntaxTree, LRLanguage, indentNodeProp, delimitedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
|
|
3
|
+
import { styleTags, tags } from '@lezer/highlight';
|
|
4
|
+
import { snippetCompletion } from '@codemirror/autocomplete';
|
|
5
|
+
|
|
6
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
7
|
+
const spec_identifier = {__proto__:null,module:10, def:22, if:24, then:26, elif:28, else:30, end:32, as:34, reduce:36, foreach:38, try:40, catch:42, label:44, break:46, import:48, include:50, and:52, or:54, true:56, false:58, null:60};
|
|
8
|
+
const parser = LRParser.deserialize({
|
|
9
|
+
version: 14,
|
|
10
|
+
states: "@^Q!vQPOOOOQO'#C{'#C{O!}QPO'#D[O$zQPO'#DbOOQO'#Dg'#DgO&wQPO'#DfO(tQPO'#DiO*[QPO'#DlOOQO'#Dw'#DwO*cQPO'#DvO+sQPO'#EvOOQO'#Ew'#EwO._QPO'#E{OOQO'#Ev'#EvO/UQPO'#EtOOQO'#Et'#EtO/uQPO'#EsOOQO'#E{'#E{OOQO'#Es'#EsO0jOQO'#C|O2iQPO'#CdOOQO'#Ek'#EkQYQPOOQOQPOOQYQPOOO2pQPO'#DROOQO'#Dd'#DdOOQO'#De'#DeO*cQPO'#DmO*cQPO'#DsO(tQPO'#DtO!qQPO'#DuO*cQPO'#DyO2uQPO'#EYO2zQPO'#C`O3PQPO'#E`O3PQPO'#EbOOQO,59z,59zOOQO,59|,59|O(tQPO'#DhOOQO,5:Q,5:QO3UQPO,5:TOOQO,5:W,5:WO3ZQPO,5:WO3`QPO,5:bOOQO'#D{'#D{OOQO,5:f,5:fO5YQPO,5:fO5bQPO,5:fOOQO'#EP'#EPOOQO'#ER'#EROOQO'#ET'#ETOOQO'#EV'#EVO*cQPO,5:hO*cQPO,5:hO*cQPO,5:hO*cQPO,5:hO*cQPO,5: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Q#y!}Q#{#PQ$b#jQ$f#nQ$h#pQ$l#uQ$q#zQ$v$PQ$|$TQ%T$cQ%_$pQ%o%UQ%p%VQ%t%XQ%u%ZQ%{%sQ&P%yQ&Q%zQ&S%|R&W&V!bbOUV^fhnw!Q!a!b!h!}#P#j#n#p#u#z$P$T$c$p%U%V%X%Z%s%y%z%|&VR#_!`Q$a#iR%k%P!b[OUV^fhnw!Q!a!b!h!}#P#j#n#p#u#z$P$T$c$p%U%V%X%Z%s%y%z%|&VQ!olQ!pmQ#Q!VQ#R!WQ#S!XQ#T!YQ#U!ZQ#V![Q#W!]Q#^!`V$W#d$}%O!|YOUV^fhlmnw!Q!V!W!X!Y!Z![!]!`!a!b!h!}#P#d#j#n#p#u#z$P$T$c$p$}%O%U%V%X%Z%s%y%z%|&VQ|XQ!spR$g#oQ#]!^Q$d#lR$e#mU#[!^#l#mQ#|#XQ%`$rQ%c$uQ%h$zR&O%xQ$Q#YR%e$w!c`OUV^fhnw!Q!a!b!h!}#P#j#n#p#u#z$P$T$c$p%U%V%X%Z%s%y%z%|&VQ$X#dQ%i$}R%j%O",
|
|
13
|
+
nodeNames: "⚠ Comment Program ; ModuleDirective module } { ObjectExpression ObjectEntry PropertyName def if then elif else end as reduce foreach try catch label break import include and or true false null VariableName String \" Escape Interpolation InterpolationStart FunctionDefinition FunctionName ) ( ParamList VariableDefinition ParameterName : BindingExpression Identity . RecursiveDescent Field QuotedField Number Format FormatName BooleanLiteral Null Call Identifier ArgList ParenthesizedExpression ] [ ArrayExpression ReduceExpression ArrayPattern , ObjectPattern ? AlternativeOp ForeachExpression IfExpression BreakExpression UnaryExpression ArithOp - TryExpression SuffixExpression Optional BinaryExpression UpdateOp CompareOp ArithOp + ArithOp * ArithOp / ArithOp % | LabelExpression PipeExpression CommaExpression InterpolationEnd \" ObjectValuePipe Import ModuleName Include",
|
|
14
|
+
maxTerm: 124,
|
|
15
|
+
nodeProps: [
|
|
16
|
+
["openedBy", 6,"{",39,"(",60,"["],
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!^~~,XOV~~,^P!{~!_!`&Y~,fOU~",
|
|
22
|
+
tokenizers: [1, new LocalTokenGroup("!R~RQrsX#O#P^~^O#Q~~aTOxpxyuy;'Sp;'S;=`z<%lOp~uOr~~zOt~~}P;=`<%lp~", 48, 114)],
|
|
23
|
+
topRules: {"Program":[0,2]},
|
|
24
|
+
specialized: [{term: 111, get: (value) => spec_identifier[value] || -1}],
|
|
25
|
+
tokenPrec: 1916
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// jq 1.8's built-in functions, written the way the jq manual writes them.
|
|
29
|
+
// Each arity is its own entry, because jq treats `range/1` and `range/2` as
|
|
30
|
+
// different functions.
|
|
31
|
+
const builtinSignatures = [
|
|
32
|
+
"length", "utf8bytelength", "not", "keys", "keys_unsorted", "has(key)",
|
|
33
|
+
"in(object)", "map(f)", "map_values(f)", "pick(pathexps)", "path(path_expression)",
|
|
34
|
+
"del(path_expression)", "getpath(path)", "setpath(path; value)", "delpaths(paths)",
|
|
35
|
+
"paths", "paths(f)", "to_entries", "from_entries", "with_entries(f)",
|
|
36
|
+
"select(f)", "recurse", "recurse(f)", "recurse(f; cond)", "env", "builtins",
|
|
37
|
+
"input", "inputs", "debug", "debug(msg)", "stderr", "input_filename",
|
|
38
|
+
"input_line_number", "splits(regex)", "splits(regex; flags)", "tostream",
|
|
39
|
+
"fromstream(stream_expression)", "truncate_stream(stream_expression)",
|
|
40
|
+
"add", "add(generator)", "any", "any(condition)",
|
|
41
|
+
"any(generator; condition)", "all", "all(condition)", "all(generator; condition)",
|
|
42
|
+
"flatten", "flatten(depth)", "range(upto)", "range(from; upto)",
|
|
43
|
+
"range(from; upto; by)", "floor", "ceil", "round", "sqrt", "pow(base; exp)",
|
|
44
|
+
"log", "abs", "toarray", "trim", "ltrim", "rtrim", "trimstr(str)",
|
|
45
|
+
"tostring", "tonumber", "type", "infinite", "nan", "isinfinite", "isnan",
|
|
46
|
+
"isnormal", "sort", "sort_by(path_expression)",
|
|
47
|
+
"group_by(path_expression)", "min", "max", "min_by(path_exp)",
|
|
48
|
+
"max_by(path_exp)", "unique", "unique_by(path_exp)", "reverse",
|
|
49
|
+
"contains(element)", "indices(s)", "index(s)", "rindex(s)", "inside(b)",
|
|
50
|
+
"startswith(str)", "endswith(str)", "combinations", "combinations(n)",
|
|
51
|
+
"ltrimstr(str)", "rtrimstr(str)", "explode", "implode", "split(str)",
|
|
52
|
+
"split(regex; flags)", "join(str)", "ascii_downcase", "ascii_upcase",
|
|
53
|
+
"while(cond; update)", "repeat(f)", "until(cond; next)", "walk(f)",
|
|
54
|
+
"transpose", "bsearch(value)", "tojson", "fromjson", "todate", "fromdate",
|
|
55
|
+
"now", "mktime", "gmtime", "localtime", "strptime(fmt)", "strftime(fmt)",
|
|
56
|
+
"strflocaltime(fmt)", "todateiso8601", "fromdateiso8601", "dateadd(u; n)",
|
|
57
|
+
"datesub(u; n)", "date", "test(regex)", "test(regex; flags)",
|
|
58
|
+
"match(regex)", "match(regex; flags)", "capture(regex)",
|
|
59
|
+
"capture(regex; flags)", "scan(regex)", "scan(regex; flags)",
|
|
60
|
+
"sub(regex; tostring)", "sub(regex; tostring; flags)", "gsub(regex; tostring)",
|
|
61
|
+
"gsub(regex; tostring; flags)", "ascii", "error", "error(message)",
|
|
62
|
+
"halt", "halt_error", "halt_error(exit_code)", "empty", "first", "last",
|
|
63
|
+
"first(expr)", "last(expr)", "nth(n)", "nth(n; expr)", "limit(n; expr)",
|
|
64
|
+
"skip(n; expr)", "isempty(exp)",
|
|
65
|
+
"values", "nulls", "booleans", "numbers", "strings",
|
|
66
|
+
"arrays", "objects", "iterables", "scalars", "finites", "normals",
|
|
67
|
+
"leaf_paths", "format(name)", "significand", "logb",
|
|
68
|
+
"gamma", "lgamma", "tgamma", "lgamma_r", "frexp", "modf", "drem(x; y)",
|
|
69
|
+
"ldexp(x; e)", "scalb(x; e)", "scalbln(x; e)", "nearbyint", "trunc",
|
|
70
|
+
"rint", "exp", "exp2", "exp10", "expm1", "log10", "log1p", "log2", "cbrt",
|
|
71
|
+
"sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh",
|
|
72
|
+
"asinh", "acosh", "atanh", "atan2(y; x)", "fabs", "fmax(x; y)",
|
|
73
|
+
"fmin(x; y)", "fmod(x; y)", "fdim(x; y)", "fma(x; y; z)", "hypot(x; y)",
|
|
74
|
+
"copysign(x; y)", "nextafter(x; y)", "nexttoward(x; y)", "remainder(x; y)",
|
|
75
|
+
"j0", "j1", "jn(n; x)", "y0", "y1", "yn(n; x)", "erf", "erfc", "pow10",
|
|
76
|
+
"IN(source)", "IN(source; s)", "INDEX(idx_expr)", "INDEX(stream; idx_expr)",
|
|
77
|
+
"JOIN($idx; idx_expr)", "JOIN($idx; stream; idx_expr)",
|
|
78
|
+
"JOIN($idx; stream; idx_expr; join_expr)",
|
|
79
|
+
"get_search_list", "get_prog_origin", "get_jq_origin",
|
|
80
|
+
"modulemeta", "have_decnum",
|
|
81
|
+
"have_literal_numbers",
|
|
82
|
+
];
|
|
83
|
+
// The `@name` formats for strings.
|
|
84
|
+
const formats = [
|
|
85
|
+
"@text", "@json", "@html", "@uri", "@csv", "@tsv", "@sh", "@base64",
|
|
86
|
+
"@base64d", "@base32", "@base32d",
|
|
87
|
+
];
|
|
88
|
+
// Variables that jq defines in every program.
|
|
89
|
+
const builtinVariables = ["$ENV", "$__loc__"];
|
|
90
|
+
|
|
91
|
+
// A call with arguments inserts a snippet with a field for each argument, so
|
|
92
|
+
// `range(from; upto)` inserts `range(|; )` with the cursor in the first one.
|
|
93
|
+
function functionCompletion(name, params, detail) {
|
|
94
|
+
if (params.length == 0)
|
|
95
|
+
return { label: name, type: "function", detail };
|
|
96
|
+
const fields = params.map((param) => "${" + param + "}").join("; ");
|
|
97
|
+
return snippetCompletion(`${name}(${fields})`, {
|
|
98
|
+
label: name,
|
|
99
|
+
detail: `(${params.join("; ")})${detail ? " " + detail : ""}`,
|
|
100
|
+
type: "function",
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/// The built-in functions, one option for each arity.
|
|
104
|
+
const builtins = builtinSignatures.map((signature) => {
|
|
105
|
+
const [, name, params] = /^(\w+)(?:\((.*)\))?$/.exec(signature);
|
|
106
|
+
return functionCompletion(name, params ? params.split(/;\s*/) : []);
|
|
107
|
+
});
|
|
108
|
+
const formatOptions = formats.map((label) => ({ label, type: "constant" }));
|
|
109
|
+
const builtinVariableOptions = builtinVariables.map((label) => ({
|
|
110
|
+
label,
|
|
111
|
+
type: "variable",
|
|
112
|
+
detail: "built-in",
|
|
113
|
+
}));
|
|
114
|
+
const keywords = [
|
|
115
|
+
"def", "if", "then", "elif", "else", "end", "as", "reduce", "foreach", "try",
|
|
116
|
+
"catch", "label", "break", "import", "include", "module", "and", "or",
|
|
117
|
+
"true", "false", "null",
|
|
118
|
+
].map((label) => ({ label, type: "keyword" }));
|
|
119
|
+
/// Snippets for the constructs people write most often in jq.
|
|
120
|
+
const snippets = [
|
|
121
|
+
snippetCompletion("def ${name}: ${};", { label: "def", detail: "function", type: "keyword" }),
|
|
122
|
+
snippetCompletion("def ${name}(${f}): ${};", { label: "def", detail: "function with parameters", type: "keyword" }),
|
|
123
|
+
snippetCompletion("if ${condition} then ${} else ${} end", { label: "if", detail: "then else end", type: "keyword" }),
|
|
124
|
+
snippetCompletion("if ${condition} then ${} elif ${condition} then ${} else ${} end", {
|
|
125
|
+
label: "if",
|
|
126
|
+
detail: "then elif else end",
|
|
127
|
+
type: "keyword",
|
|
128
|
+
}),
|
|
129
|
+
snippetCompletion("reduce ${.[]} as $${x} (${init}; ${update})", { label: "reduce", detail: "as (init; update)", type: "keyword" }),
|
|
130
|
+
snippetCompletion("foreach ${.[]} as $${x} (${init}; ${update}; ${extract})", {
|
|
131
|
+
label: "foreach",
|
|
132
|
+
detail: "as (init; update; extract)",
|
|
133
|
+
type: "keyword",
|
|
134
|
+
}),
|
|
135
|
+
snippetCompletion("try ${} catch ${}", { label: "try", detail: "catch", type: "keyword" }),
|
|
136
|
+
snippetCompletion("as $${x} | ${}", { label: "as", detail: "$x |", type: "keyword" }),
|
|
137
|
+
snippetCompletion("label $${out} | ${}", { label: "label", detail: "$out |", type: "keyword" }),
|
|
138
|
+
snippetCompletion('import "${path}" as ${name};', { label: "import", detail: "as", type: "keyword" }),
|
|
139
|
+
snippetCompletion('include "${path}";', { label: "include", type: "keyword" }),
|
|
140
|
+
];
|
|
141
|
+
// Completion would get in the way while someone writes a comment, a string or
|
|
142
|
+
// a field name, or names a new function, parameter or variable.
|
|
143
|
+
const noCompletion = new Set([
|
|
144
|
+
"Comment", "Field", "FunctionName", "ParameterName", "VariableDefinition", "PropertyName",
|
|
145
|
+
]);
|
|
146
|
+
function completionAllowed(node) {
|
|
147
|
+
for (let cur = node; cur; cur = cur.parent) {
|
|
148
|
+
if (cur.name == "Interpolation" && cur.firstChild && node.from >= cur.firstChild.to)
|
|
149
|
+
return true;
|
|
150
|
+
if (cur.name == "String" || noCompletion.has(cur.name))
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
function text(state, node) {
|
|
156
|
+
return state.sliceDoc(node.from, node.to);
|
|
157
|
+
}
|
|
158
|
+
function childBefore(node, name, pos) {
|
|
159
|
+
for (let child = node.firstChild; child; child = child.nextSibling)
|
|
160
|
+
if (child.name == name && child.to <= pos)
|
|
161
|
+
return child;
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
function addFunction(scope, state, def) {
|
|
165
|
+
const name = def.getChild("FunctionName");
|
|
166
|
+
if (!name)
|
|
167
|
+
return;
|
|
168
|
+
const params = [];
|
|
169
|
+
const list = def.getChild("ParamList");
|
|
170
|
+
if (list)
|
|
171
|
+
for (let child = list.firstChild; child; child = child.nextSibling)
|
|
172
|
+
if (child.name == "ParameterName" || child.name == "VariableDefinition")
|
|
173
|
+
params.push(text(state, child));
|
|
174
|
+
const label = text(state, name);
|
|
175
|
+
// jq tells functions apart by name and arity, and an inner definition
|
|
176
|
+
// hides an outer one with the same name and arity.
|
|
177
|
+
const key = `${label}/${params.length}`;
|
|
178
|
+
if (!scope.functions.has(key))
|
|
179
|
+
scope.functions.set(key, functionCompletion(label, params, "defined here"));
|
|
180
|
+
}
|
|
181
|
+
function addVariables(scope, state, node, from, to, detail) {
|
|
182
|
+
const cursor = node.cursor();
|
|
183
|
+
do {
|
|
184
|
+
if (cursor.from >= to)
|
|
185
|
+
break;
|
|
186
|
+
if (cursor.name == "VariableDefinition" && cursor.from >= from) {
|
|
187
|
+
const label = text(state, cursor.node);
|
|
188
|
+
if (!scope.variables.has(label))
|
|
189
|
+
scope.variables.set(label, { label, type: "variable", detail });
|
|
190
|
+
}
|
|
191
|
+
} while (cursor.next());
|
|
192
|
+
}
|
|
193
|
+
// Walks out from the cursor and collects every name that is in scope there:
|
|
194
|
+
// definitions earlier in an enclosing query, the function around the cursor
|
|
195
|
+
// and its parameters, and the variables bound by `as`, `reduce`, `foreach`
|
|
196
|
+
// and `label`.
|
|
197
|
+
function scopeAt(state, pos) {
|
|
198
|
+
const scope = { functions: new Map(), variables: new Map() };
|
|
199
|
+
let child = null;
|
|
200
|
+
for (let cur = syntaxTree(state).resolveInner(pos, -1); cur; child = cur, cur = cur.parent) {
|
|
201
|
+
for (let sibling = cur.lastChild; sibling; sibling = sibling.prevSibling)
|
|
202
|
+
if (sibling.name == "FunctionDefinition" && sibling.to <= pos && sibling != child)
|
|
203
|
+
addFunction(scope, state, sibling);
|
|
204
|
+
switch (cur.name) {
|
|
205
|
+
case "FunctionDefinition": {
|
|
206
|
+
const colon = childBefore(cur, ":", pos);
|
|
207
|
+
if (!colon)
|
|
208
|
+
break;
|
|
209
|
+
addFunction(scope, state, cur);
|
|
210
|
+
const list = cur.getChild("ParamList");
|
|
211
|
+
if (list) {
|
|
212
|
+
addVariables(scope, state, list, list.from, list.to, "parameter");
|
|
213
|
+
for (let param = list.firstChild; param; param = param.nextSibling)
|
|
214
|
+
if (param.name == "ParameterName") {
|
|
215
|
+
const label = text(state, param);
|
|
216
|
+
const key = `${label}/0`;
|
|
217
|
+
if (!scope.functions.has(key))
|
|
218
|
+
scope.functions.set(key, { label, type: "function", detail: "parameter" });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "BindingExpression":
|
|
224
|
+
case "LabelExpression": {
|
|
225
|
+
const pipe = childBefore(cur, "|", pos);
|
|
226
|
+
if (pipe)
|
|
227
|
+
addVariables(scope, state, cur, cur.from, pipe.from, cur.name == "LabelExpression" ? "label" : undefined);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case "ReduceExpression":
|
|
231
|
+
case "ForeachExpression": {
|
|
232
|
+
// The variable is bound in the update and extract parts, after the
|
|
233
|
+
// first `;`.
|
|
234
|
+
const as = cur.getChild("as");
|
|
235
|
+
const open = cur.getChild("(");
|
|
236
|
+
const semicolon = childBefore(cur, ";", pos);
|
|
237
|
+
if (as && open && semicolon)
|
|
238
|
+
addVariables(scope, state, cur, as.to, open.from);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return scope;
|
|
244
|
+
}
|
|
245
|
+
/// Completes keywords, snippets, built-in functions and formats, and the
|
|
246
|
+
/// functions and variables defined in the file that are in scope at the
|
|
247
|
+
/// cursor.
|
|
248
|
+
function jqCompletionSource(context) {
|
|
249
|
+
const node = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
250
|
+
if (!completionAllowed(node))
|
|
251
|
+
return null;
|
|
252
|
+
const word = context.matchBefore(/[$@]?\w*/);
|
|
253
|
+
if (!word || (word.from == word.to && !context.explicit))
|
|
254
|
+
return null;
|
|
255
|
+
// A dot straight before the word makes it a field name, as in `.name`.
|
|
256
|
+
if (context.state.sliceDoc(word.from - 1, word.from) == ".")
|
|
257
|
+
return null;
|
|
258
|
+
let options;
|
|
259
|
+
if (word.text.startsWith("@")) {
|
|
260
|
+
options = formatOptions;
|
|
261
|
+
}
|
|
262
|
+
else if (word.text.startsWith("$")) {
|
|
263
|
+
options = [...scopeAt(context.state, context.pos).variables.values(), ...builtinVariableOptions];
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
options = [...scopeAt(context.state, context.pos).functions.values(), ...snippets, ...keywords, ...builtins];
|
|
267
|
+
}
|
|
268
|
+
return { from: word.from, options, validFor: /^[$@]?\w*$/ };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Folding keeps the first line and the closing `end`, `;` or `)` in view.
|
|
272
|
+
function foldBody(node, state) {
|
|
273
|
+
const line = state.doc.lineAt(node.from);
|
|
274
|
+
const last = node.lastChild;
|
|
275
|
+
const to = last && /^(end|;|\))$/.test(last.name) ? last.from : node.to;
|
|
276
|
+
return to > line.to ? { from: line.to, to } : null;
|
|
277
|
+
}
|
|
278
|
+
// The lines of a block are indented one unit, and the line that closes it
|
|
279
|
+
// lines up with the line that opened it.
|
|
280
|
+
function blockIndent(closing) {
|
|
281
|
+
return (context) => closing.test(context.textAfter) ? context.baseIndent : context.baseIndent + context.unit;
|
|
282
|
+
}
|
|
283
|
+
const jqLanguage = LRLanguage.define({
|
|
284
|
+
name: "jq",
|
|
285
|
+
parser: parser.configure({
|
|
286
|
+
props: [
|
|
287
|
+
indentNodeProp.add({
|
|
288
|
+
ParenthesizedExpression: delimitedIndent({ closing: ")" }),
|
|
289
|
+
"ArgList ParamList": delimitedIndent({ closing: ")" }),
|
|
290
|
+
"ArrayExpression ArrayPattern": delimitedIndent({ closing: "]" }),
|
|
291
|
+
"ObjectExpression ObjectPattern": delimitedIndent({ closing: "}" }),
|
|
292
|
+
IfExpression: blockIndent(/^\s*(then|elif|else|end)\b/),
|
|
293
|
+
"ReduceExpression ForeachExpression": blockIndent(/^\s*\)/),
|
|
294
|
+
FunctionDefinition: blockIndent(/^\s*;/),
|
|
295
|
+
String: () => null,
|
|
296
|
+
}),
|
|
297
|
+
foldNodeProp.add({
|
|
298
|
+
"ParenthesizedExpression ArrayExpression ObjectExpression ArgList": foldInside,
|
|
299
|
+
"FunctionDefinition IfExpression ReduceExpression ForeachExpression": foldBody,
|
|
300
|
+
}),
|
|
301
|
+
styleTags({
|
|
302
|
+
def: tags.definitionKeyword,
|
|
303
|
+
"if then elif else end reduce foreach try catch label break as": tags.controlKeyword,
|
|
304
|
+
"import include module": tags.moduleKeyword,
|
|
305
|
+
"and or": tags.logicOperator,
|
|
306
|
+
// A `!` stops the tokens inside a node from overriding its tag, as the
|
|
307
|
+
// `end` in `{end: 1}` would.
|
|
308
|
+
"BooleanLiteral!": tags.bool,
|
|
309
|
+
"Null!": tags.null,
|
|
310
|
+
Number: tags.number,
|
|
311
|
+
String: tags.string,
|
|
312
|
+
Escape: tags.escape,
|
|
313
|
+
FormatName: tags.special(tags.string),
|
|
314
|
+
Comment: tags.lineComment,
|
|
315
|
+
"FunctionDefinition/FunctionName": tags.definition(tags.function(tags.variableName)),
|
|
316
|
+
"ParameterName VariableDefinition": tags.definition(tags.variableName),
|
|
317
|
+
"Call/Identifier": tags.function(tags.variableName),
|
|
318
|
+
VariableName: tags.variableName,
|
|
319
|
+
Field: tags.propertyName,
|
|
320
|
+
"PropertyName!": tags.propertyName,
|
|
321
|
+
"Identity!": tags.self,
|
|
322
|
+
RecursiveDescent: tags.self,
|
|
323
|
+
ModuleName: tags.namespace,
|
|
324
|
+
"ArithOp!": tags.arithmeticOperator,
|
|
325
|
+
CompareOp: tags.compareOperator,
|
|
326
|
+
UpdateOp: tags.updateOperator,
|
|
327
|
+
"AlternativeOp |": tags.operator,
|
|
328
|
+
"Optional!": tags.operator,
|
|
329
|
+
InterpolationStart: tags.special(tags.brace),
|
|
330
|
+
"InterpolationEnd!": tags.special(tags.brace),
|
|
331
|
+
"( )": tags.paren,
|
|
332
|
+
"[ ]": tags.squareBracket,
|
|
333
|
+
"{ }": tags.brace,
|
|
334
|
+
", ;": tags.separator,
|
|
335
|
+
":": tags.punctuation,
|
|
336
|
+
}),
|
|
337
|
+
],
|
|
338
|
+
}),
|
|
339
|
+
languageData: {
|
|
340
|
+
commentTokens: { line: "#" },
|
|
341
|
+
closeBrackets: { brackets: ["(", "[", "{", '"'] },
|
|
342
|
+
indentOnInput: /^\s*(then|elif|else|end|;|[\]})])$/,
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
/// jq language support, with completion for keywords, snippets, built-in
|
|
346
|
+
/// functions and formats, and the functions and variables defined in the file.
|
|
347
|
+
function jq() {
|
|
348
|
+
return new LanguageSupport(jqLanguage, jqLanguage.data.of({ autocomplete: jqCompletionSource }));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export { builtins, jq, jqCompletionSource, jqLanguage, parser, snippets };
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exercism/codemirror-lang-jq",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "jq language support for CodeMirror",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/exercism/codemirror-lang-jq.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/exercism/codemirror-lang-jq#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/exercism/codemirror-lang-jq/issues"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"prepare": "bun --bun rollup -c",
|
|
15
|
+
"test": "bun run prepare && bun test",
|
|
16
|
+
"dev": "vite"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "dist/index.cjs",
|
|
20
|
+
"module": "dist/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@codemirror/autocomplete": "^6.18.0",
|
|
35
|
+
"@codemirror/language": "^6.10.1",
|
|
36
|
+
"@codemirror/state": "^6.4.0",
|
|
37
|
+
"@lezer/common": "^1.2.0",
|
|
38
|
+
"@lezer/highlight": "^1.2.0",
|
|
39
|
+
"@lezer/lr": "^1.4.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@lezer/generator": "^1.7.0",
|
|
43
|
+
"@types/bun": "^1.1.14",
|
|
44
|
+
"codemirror": "^6.0.1",
|
|
45
|
+
"rollup": "^4.18.0",
|
|
46
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
47
|
+
"rollup-plugin-ts": "^3.4.5",
|
|
48
|
+
"typescript": "^5.4.5",
|
|
49
|
+
"unplugin-lezer": "^1.0.1",
|
|
50
|
+
"vite": "^5.4.11"
|
|
51
|
+
},
|
|
52
|
+
"license": "MIT"
|
|
53
|
+
}
|