@exercism/codemirror-lang-ocaml 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/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +169 -2
- package/dist/index.cjs +1260 -0
- package/dist/index.d.cts +147 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +1253 -0
- package/package.json +55 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people write most often in OCaml.
|
|
9
|
+
*/
|
|
10
|
+
declare const snippets = [
|
|
11
|
+
snip("let ${name} ${args} =\n\t${}", {
|
|
12
|
+
label: "let",
|
|
13
|
+
detail: "function",
|
|
14
|
+
type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snip("let rec ${name} ${args} =\n\t${}", {
|
|
17
|
+
label: "let rec",
|
|
18
|
+
detail: "recursive function",
|
|
19
|
+
type: "keyword"
|
|
20
|
+
}),
|
|
21
|
+
snip("let ${name} = ${value} in\n${}", {
|
|
22
|
+
label: "let",
|
|
23
|
+
detail: "in",
|
|
24
|
+
type: "keyword"
|
|
25
|
+
}),
|
|
26
|
+
snip("match ${expression} with\n| ${pattern} -> ${}\n| _ -> ${}", {
|
|
27
|
+
label: "match",
|
|
28
|
+
detail: "with",
|
|
29
|
+
type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snip("function\n| ${pattern} -> ${}\n| _ -> ${}", {
|
|
32
|
+
label: "function",
|
|
33
|
+
detail: "match on the argument",
|
|
34
|
+
type: "keyword"
|
|
35
|
+
}),
|
|
36
|
+
snip("fun ${x} -> ${}", {
|
|
37
|
+
label: "fun",
|
|
38
|
+
detail: "anonymous function",
|
|
39
|
+
type: "keyword"
|
|
40
|
+
}),
|
|
41
|
+
snip("if ${condition} then ${} else ${}", {
|
|
42
|
+
label: "if",
|
|
43
|
+
detail: "then else",
|
|
44
|
+
type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snip("try ${expression} with\n| ${exception} -> ${}", {
|
|
47
|
+
label: "try",
|
|
48
|
+
detail: "with",
|
|
49
|
+
type: "keyword"
|
|
50
|
+
}),
|
|
51
|
+
snip("for ${i} = ${0} to ${n} do\n\t${}\ndone", {
|
|
52
|
+
label: "for",
|
|
53
|
+
detail: "loop",
|
|
54
|
+
type: "keyword"
|
|
55
|
+
}),
|
|
56
|
+
snip("while ${condition} do\n\t${}\ndone", {
|
|
57
|
+
label: "while",
|
|
58
|
+
detail: "loop",
|
|
59
|
+
type: "keyword"
|
|
60
|
+
}),
|
|
61
|
+
snip("type ${name} =\n\t| ${Constructor}\n\t| ${Constructor} of ${type}", {
|
|
62
|
+
label: "type",
|
|
63
|
+
detail: "variant",
|
|
64
|
+
type: "keyword"
|
|
65
|
+
}),
|
|
66
|
+
snip("type ${name} = { ${field} : ${type} }", {
|
|
67
|
+
label: "type",
|
|
68
|
+
detail: "record",
|
|
69
|
+
type: "keyword"
|
|
70
|
+
}),
|
|
71
|
+
snip("module ${Name} = struct\n\t${}\nend", {
|
|
72
|
+
label: "module",
|
|
73
|
+
detail: "struct",
|
|
74
|
+
type: "keyword"
|
|
75
|
+
}),
|
|
76
|
+
snip("module type ${Name} = sig\n\t${}\nend", {
|
|
77
|
+
label: "module type",
|
|
78
|
+
detail: "sig",
|
|
79
|
+
type: "keyword"
|
|
80
|
+
}),
|
|
81
|
+
snip("exception ${Name} of ${type}", {
|
|
82
|
+
label: "exception",
|
|
83
|
+
detail: "definition",
|
|
84
|
+
type: "keyword"
|
|
85
|
+
}),
|
|
86
|
+
snip("List.fold_left (fun ${acc} ${x} -> ${}) ${initial} ${list}", {
|
|
87
|
+
label: "fold_left",
|
|
88
|
+
detail: "fold with a function",
|
|
89
|
+
type: "function"
|
|
90
|
+
})
|
|
91
|
+
];
|
|
92
|
+
/**
|
|
93
|
+
Completes the names declared in the file that are in scope at the cursor:
|
|
94
|
+
top-level values, functions, types, constructors, record fields, modules and
|
|
95
|
+
exceptions, and also parameters, the names a `let ... in` binds, and the
|
|
96
|
+
variables bound by match arms, `fun` and `for` loops.
|
|
97
|
+
*/
|
|
98
|
+
declare const localCompletionSource = (context) => {
|
|
99
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
100
|
+
if (dontComplete.includes(inner.name))
|
|
101
|
+
return null;
|
|
102
|
+
const word = context.matchBefore(/[\w'\xa1-]+/);
|
|
103
|
+
if (!word && !context.explicit)
|
|
104
|
+
return null;
|
|
105
|
+
// `List.l` asks for a name out of another module, and `r.f` for a field of a
|
|
106
|
+
// record value. Neither is a name this scope declares.
|
|
107
|
+
const start = word ? word.from : context.pos;
|
|
108
|
+
if (context.state.sliceDoc(start - 1, start) == ".")
|
|
109
|
+
return null;
|
|
110
|
+
const doc = context.state.doc;
|
|
111
|
+
const options = [];
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
const def = (n, type) => {
|
|
114
|
+
const label = doc.sliceString(n.from, n.to);
|
|
115
|
+
if (!label || label == (word === null || word === void 0 ? void 0 : word.text) || seen.has(label))
|
|
116
|
+
return;
|
|
117
|
+
seen.add(label);
|
|
118
|
+
options.push({ label, type });
|
|
119
|
+
};
|
|
120
|
+
for (let node = inner; node; node = node.parent) {
|
|
121
|
+
if (!ScopeNodes.has(node.name))
|
|
122
|
+
continue;
|
|
123
|
+
ownBindings(node, context.pos, def);
|
|
124
|
+
for (const option of declaredIn(doc, node)) {
|
|
125
|
+
if (option.label != (word === null || word === void 0 ? void 0 : word.text) && !seen.has(option.label)) {
|
|
126
|
+
seen.add(option.label);
|
|
127
|
+
options.push(option);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { options, from: start, validFor: Identifier };
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
declare const ocamlLanguage: LRLanguage;
|
|
135
|
+
/**
|
|
136
|
+
Autocompletion for OCaml's keywords and the parts of the standard library
|
|
137
|
+
that are reached for often enough to be worth proposing.
|
|
138
|
+
It also offers the snippets, and nothing inside strings and comments.
|
|
139
|
+
*/
|
|
140
|
+
declare const ocamlCompletion: CompletionSource;
|
|
141
|
+
/**
|
|
142
|
+
OCaml language support, with completion for keywords, snippets, the
|
|
143
|
+
standard library and the names declared in the file.
|
|
144
|
+
*/
|
|
145
|
+
declare function ocaml(): LanguageSupport;
|
|
146
|
+
|
|
147
|
+
export { localCompletionSource, ocaml, ocamlCompletion, ocamlLanguage, parser, snippets };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people write most often in OCaml.
|
|
9
|
+
*/
|
|
10
|
+
declare const snippets = [
|
|
11
|
+
snip("let ${name} ${args} =\n\t${}", {
|
|
12
|
+
label: "let",
|
|
13
|
+
detail: "function",
|
|
14
|
+
type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snip("let rec ${name} ${args} =\n\t${}", {
|
|
17
|
+
label: "let rec",
|
|
18
|
+
detail: "recursive function",
|
|
19
|
+
type: "keyword"
|
|
20
|
+
}),
|
|
21
|
+
snip("let ${name} = ${value} in\n${}", {
|
|
22
|
+
label: "let",
|
|
23
|
+
detail: "in",
|
|
24
|
+
type: "keyword"
|
|
25
|
+
}),
|
|
26
|
+
snip("match ${expression} with\n| ${pattern} -> ${}\n| _ -> ${}", {
|
|
27
|
+
label: "match",
|
|
28
|
+
detail: "with",
|
|
29
|
+
type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snip("function\n| ${pattern} -> ${}\n| _ -> ${}", {
|
|
32
|
+
label: "function",
|
|
33
|
+
detail: "match on the argument",
|
|
34
|
+
type: "keyword"
|
|
35
|
+
}),
|
|
36
|
+
snip("fun ${x} -> ${}", {
|
|
37
|
+
label: "fun",
|
|
38
|
+
detail: "anonymous function",
|
|
39
|
+
type: "keyword"
|
|
40
|
+
}),
|
|
41
|
+
snip("if ${condition} then ${} else ${}", {
|
|
42
|
+
label: "if",
|
|
43
|
+
detail: "then else",
|
|
44
|
+
type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snip("try ${expression} with\n| ${exception} -> ${}", {
|
|
47
|
+
label: "try",
|
|
48
|
+
detail: "with",
|
|
49
|
+
type: "keyword"
|
|
50
|
+
}),
|
|
51
|
+
snip("for ${i} = ${0} to ${n} do\n\t${}\ndone", {
|
|
52
|
+
label: "for",
|
|
53
|
+
detail: "loop",
|
|
54
|
+
type: "keyword"
|
|
55
|
+
}),
|
|
56
|
+
snip("while ${condition} do\n\t${}\ndone", {
|
|
57
|
+
label: "while",
|
|
58
|
+
detail: "loop",
|
|
59
|
+
type: "keyword"
|
|
60
|
+
}),
|
|
61
|
+
snip("type ${name} =\n\t| ${Constructor}\n\t| ${Constructor} of ${type}", {
|
|
62
|
+
label: "type",
|
|
63
|
+
detail: "variant",
|
|
64
|
+
type: "keyword"
|
|
65
|
+
}),
|
|
66
|
+
snip("type ${name} = { ${field} : ${type} }", {
|
|
67
|
+
label: "type",
|
|
68
|
+
detail: "record",
|
|
69
|
+
type: "keyword"
|
|
70
|
+
}),
|
|
71
|
+
snip("module ${Name} = struct\n\t${}\nend", {
|
|
72
|
+
label: "module",
|
|
73
|
+
detail: "struct",
|
|
74
|
+
type: "keyword"
|
|
75
|
+
}),
|
|
76
|
+
snip("module type ${Name} = sig\n\t${}\nend", {
|
|
77
|
+
label: "module type",
|
|
78
|
+
detail: "sig",
|
|
79
|
+
type: "keyword"
|
|
80
|
+
}),
|
|
81
|
+
snip("exception ${Name} of ${type}", {
|
|
82
|
+
label: "exception",
|
|
83
|
+
detail: "definition",
|
|
84
|
+
type: "keyword"
|
|
85
|
+
}),
|
|
86
|
+
snip("List.fold_left (fun ${acc} ${x} -> ${}) ${initial} ${list}", {
|
|
87
|
+
label: "fold_left",
|
|
88
|
+
detail: "fold with a function",
|
|
89
|
+
type: "function"
|
|
90
|
+
})
|
|
91
|
+
];
|
|
92
|
+
/**
|
|
93
|
+
Completes the names declared in the file that are in scope at the cursor:
|
|
94
|
+
top-level values, functions, types, constructors, record fields, modules and
|
|
95
|
+
exceptions, and also parameters, the names a `let ... in` binds, and the
|
|
96
|
+
variables bound by match arms, `fun` and `for` loops.
|
|
97
|
+
*/
|
|
98
|
+
declare const localCompletionSource = (context) => {
|
|
99
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
100
|
+
if (dontComplete.includes(inner.name))
|
|
101
|
+
return null;
|
|
102
|
+
const word = context.matchBefore(/[\w'\xa1-]+/);
|
|
103
|
+
if (!word && !context.explicit)
|
|
104
|
+
return null;
|
|
105
|
+
// `List.l` asks for a name out of another module, and `r.f` for a field of a
|
|
106
|
+
// record value. Neither is a name this scope declares.
|
|
107
|
+
const start = word ? word.from : context.pos;
|
|
108
|
+
if (context.state.sliceDoc(start - 1, start) == ".")
|
|
109
|
+
return null;
|
|
110
|
+
const doc = context.state.doc;
|
|
111
|
+
const options = [];
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
const def = (n, type) => {
|
|
114
|
+
const label = doc.sliceString(n.from, n.to);
|
|
115
|
+
if (!label || label == (word === null || word === void 0 ? void 0 : word.text) || seen.has(label))
|
|
116
|
+
return;
|
|
117
|
+
seen.add(label);
|
|
118
|
+
options.push({ label, type });
|
|
119
|
+
};
|
|
120
|
+
for (let node = inner; node; node = node.parent) {
|
|
121
|
+
if (!ScopeNodes.has(node.name))
|
|
122
|
+
continue;
|
|
123
|
+
ownBindings(node, context.pos, def);
|
|
124
|
+
for (const option of declaredIn(doc, node)) {
|
|
125
|
+
if (option.label != (word === null || word === void 0 ? void 0 : word.text) && !seen.has(option.label)) {
|
|
126
|
+
seen.add(option.label);
|
|
127
|
+
options.push(option);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { options, from: start, validFor: Identifier };
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
declare const ocamlLanguage: LRLanguage;
|
|
135
|
+
/**
|
|
136
|
+
Autocompletion for OCaml's keywords and the parts of the standard library
|
|
137
|
+
that are reached for often enough to be worth proposing.
|
|
138
|
+
It also offers the snippets, and nothing inside strings and comments.
|
|
139
|
+
*/
|
|
140
|
+
declare const ocamlCompletion: CompletionSource;
|
|
141
|
+
/**
|
|
142
|
+
OCaml language support, with completion for keywords, snippets, the
|
|
143
|
+
standard library and the names declared in the file.
|
|
144
|
+
*/
|
|
145
|
+
declare function ocaml(): LanguageSupport;
|
|
146
|
+
|
|
147
|
+
export { localCompletionSource, ocaml, ocamlCompletion, ocamlLanguage, parser, snippets };
|