@exercism/codemirror-lang-pascal 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 +153 -0
- package/LICENSE +21 -0
- package/README.md +218 -2
- package/dist/index.cjs +1703 -0
- package/dist/index.d.cts +124 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +1696 -0
- package/package.json +57 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
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 type most: a program, a unit, the two
|
|
9
|
+
kinds of subprogram, blocks, conditionals, loops, `case`, exceptions, and
|
|
10
|
+
class and record types.
|
|
11
|
+
*/
|
|
12
|
+
declare const snippets = [
|
|
13
|
+
snippetCompletion("program ${Name};\n\nbegin\n\t${}\nend.", {
|
|
14
|
+
label: "program", detail: "definition", type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snippetCompletion("unit ${Name};\n\ninterface\n\n${}\n\nimplementation\n\nend.", { label: "unit", detail: "interface / implementation", type: "keyword" }),
|
|
17
|
+
snippetCompletion("procedure ${Name}(${params});\nbegin\n\t${}\nend;", {
|
|
18
|
+
label: "procedure", detail: "definition", type: "keyword"
|
|
19
|
+
}),
|
|
20
|
+
snippetCompletion("function ${Name}(${params}): ${Integer};\nbegin\n\t${}\nend;", {
|
|
21
|
+
label: "function", detail: "definition", type: "keyword"
|
|
22
|
+
}),
|
|
23
|
+
snippetCompletion("begin\n\t${}\nend;", { label: "begin", detail: "block", type: "keyword" }),
|
|
24
|
+
snippetCompletion("if ${condition} then\n\t${}", { label: "if", detail: "then", type: "keyword" }),
|
|
25
|
+
snippetCompletion("if ${condition} then\nbegin\n\t${}\nend\nelse\nbegin\n\t${}\nend;", {
|
|
26
|
+
label: "if", detail: "then / else", type: "keyword"
|
|
27
|
+
}),
|
|
28
|
+
snippetCompletion("for ${i} := ${1} to ${n} do\nbegin\n\t${}\nend;", {
|
|
29
|
+
label: "for", detail: "to loop", type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snippetCompletion("for ${i} := ${n} downto ${1} do\nbegin\n\t${}\nend;", {
|
|
32
|
+
label: "for", detail: "downto loop", type: "keyword"
|
|
33
|
+
}),
|
|
34
|
+
snippetCompletion("for ${item} in ${items} do\nbegin\n\t${}\nend;", {
|
|
35
|
+
label: "for", detail: "in loop", type: "keyword"
|
|
36
|
+
}),
|
|
37
|
+
snippetCompletion("while ${condition} do\nbegin\n\t${}\nend;", {
|
|
38
|
+
label: "while", detail: "loop", type: "keyword"
|
|
39
|
+
}),
|
|
40
|
+
snippetCompletion("repeat\n\t${}\nuntil ${condition};", {
|
|
41
|
+
label: "repeat", detail: "loop", type: "keyword"
|
|
42
|
+
}),
|
|
43
|
+
snippetCompletion("case ${value} of\n\t${1}: ${};\nelse\n\t${}\nend;", {
|
|
44
|
+
label: "case", detail: "statement", type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snippetCompletion("try\n\t${}\nexcept\n\ton ${E}: ${Exception} do\n\t\t${}\nend;", {
|
|
47
|
+
label: "try", detail: "except", type: "keyword"
|
|
48
|
+
}),
|
|
49
|
+
snippetCompletion("try\n\t${}\nfinally\n\t${}\nend;", {
|
|
50
|
+
label: "try", detail: "finally", type: "keyword"
|
|
51
|
+
}),
|
|
52
|
+
snippetCompletion("${TName} = class\nprivate\n\t${}\npublic\n\tconstructor Create;\nend;", { label: "class", detail: "type", type: "keyword" }),
|
|
53
|
+
snippetCompletion("${TName} = record\n\t${}\nend;", { label: "record", detail: "type", type: "keyword" })
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
Completes the names declared in the file, each where it is in scope. A
|
|
57
|
+
subprogram's parameters, locals and `Result` count inside it, a variable
|
|
58
|
+
declared in a block counts to the end of the block, and a loop variable
|
|
59
|
+
declared with `for var` counts in its loop. Names declared at the top of
|
|
60
|
+
the file count from their declaration on. Inside a method, the class's
|
|
61
|
+
fields, methods and properties count too, and so does `Self`. After
|
|
62
|
+
`name.` it offers the members of the type of `name`, when the file
|
|
63
|
+
declares that type.
|
|
64
|
+
*/
|
|
65
|
+
declare const localCompletionSource = context => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const tree = syntaxTree(context.state);
|
|
68
|
+
const inner = tree.resolveInner(context.pos, -1);
|
|
69
|
+
if (inStringOrComment(inner))
|
|
70
|
+
return null;
|
|
71
|
+
const names = gather(context.state, tree);
|
|
72
|
+
const member = completeMember(context, names, inner);
|
|
73
|
+
if (member)
|
|
74
|
+
return member.options.length ? member : null;
|
|
75
|
+
if (context.matchBefore(/\.\s*\w*$/))
|
|
76
|
+
return null;
|
|
77
|
+
if (dontComplete.indexOf(inner.name) > -1 || dontComplete.indexOf((_b = (_a = inner.parent) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "") > -1)
|
|
78
|
+
return null;
|
|
79
|
+
const word = context.matchBefore(/[a-zA-Z_]\w*$/);
|
|
80
|
+
if (!word && !context.explicit)
|
|
81
|
+
return null;
|
|
82
|
+
const options = [];
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
const add = (option) => {
|
|
85
|
+
if (seen.has(key(option.label)))
|
|
86
|
+
return;
|
|
87
|
+
seen.add(key(option.label));
|
|
88
|
+
options.push(option);
|
|
89
|
+
};
|
|
90
|
+
// Later definitions are closer to the cursor, so they win on a name clash.
|
|
91
|
+
for (let i = names.definitions.length - 1; i >= 0; i--) {
|
|
92
|
+
const d = names.definitions[i];
|
|
93
|
+
if (d.from > context.pos || d.to < context.pos)
|
|
94
|
+
continue;
|
|
95
|
+
if (word && d.at == word.from)
|
|
96
|
+
continue;
|
|
97
|
+
add({ label: d.label, type: d.type });
|
|
98
|
+
}
|
|
99
|
+
const owner = ownerAt(names, context.pos);
|
|
100
|
+
if (owner)
|
|
101
|
+
for (const option of membersOf(names, owner))
|
|
102
|
+
add(option);
|
|
103
|
+
return { from: word ? word.from : context.pos, options, validFor: identifier };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
A language provider based on the Lezer Pascal parser in this package,
|
|
108
|
+
extended with highlighting, folding and indentation information.
|
|
109
|
+
*/
|
|
110
|
+
declare const pascalLanguage: LRLanguage;
|
|
111
|
+
/**
|
|
112
|
+
Autocompletion for Pascal's reserved words and directives, snippets, the
|
|
113
|
+
predefined types, the common RTL and SysUtils routines and the common units.
|
|
114
|
+
It offers nothing inside strings and comments.
|
|
115
|
+
*/
|
|
116
|
+
declare const pascalCompletion: CompletionSource;
|
|
117
|
+
/**
|
|
118
|
+
Pascal language support, with completion for keywords, snippets, the
|
|
119
|
+
predefined types, the common routines and units, and the names declared in
|
|
120
|
+
the file.
|
|
121
|
+
*/
|
|
122
|
+
declare function pascal(): LanguageSupport;
|
|
123
|
+
|
|
124
|
+
export { localCompletionSource, parser, pascal, pascalCompletion, pascalLanguage, snippets };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
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 type most: a program, a unit, the two
|
|
9
|
+
kinds of subprogram, blocks, conditionals, loops, `case`, exceptions, and
|
|
10
|
+
class and record types.
|
|
11
|
+
*/
|
|
12
|
+
declare const snippets = [
|
|
13
|
+
snippetCompletion("program ${Name};\n\nbegin\n\t${}\nend.", {
|
|
14
|
+
label: "program", detail: "definition", type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snippetCompletion("unit ${Name};\n\ninterface\n\n${}\n\nimplementation\n\nend.", { label: "unit", detail: "interface / implementation", type: "keyword" }),
|
|
17
|
+
snippetCompletion("procedure ${Name}(${params});\nbegin\n\t${}\nend;", {
|
|
18
|
+
label: "procedure", detail: "definition", type: "keyword"
|
|
19
|
+
}),
|
|
20
|
+
snippetCompletion("function ${Name}(${params}): ${Integer};\nbegin\n\t${}\nend;", {
|
|
21
|
+
label: "function", detail: "definition", type: "keyword"
|
|
22
|
+
}),
|
|
23
|
+
snippetCompletion("begin\n\t${}\nend;", { label: "begin", detail: "block", type: "keyword" }),
|
|
24
|
+
snippetCompletion("if ${condition} then\n\t${}", { label: "if", detail: "then", type: "keyword" }),
|
|
25
|
+
snippetCompletion("if ${condition} then\nbegin\n\t${}\nend\nelse\nbegin\n\t${}\nend;", {
|
|
26
|
+
label: "if", detail: "then / else", type: "keyword"
|
|
27
|
+
}),
|
|
28
|
+
snippetCompletion("for ${i} := ${1} to ${n} do\nbegin\n\t${}\nend;", {
|
|
29
|
+
label: "for", detail: "to loop", type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snippetCompletion("for ${i} := ${n} downto ${1} do\nbegin\n\t${}\nend;", {
|
|
32
|
+
label: "for", detail: "downto loop", type: "keyword"
|
|
33
|
+
}),
|
|
34
|
+
snippetCompletion("for ${item} in ${items} do\nbegin\n\t${}\nend;", {
|
|
35
|
+
label: "for", detail: "in loop", type: "keyword"
|
|
36
|
+
}),
|
|
37
|
+
snippetCompletion("while ${condition} do\nbegin\n\t${}\nend;", {
|
|
38
|
+
label: "while", detail: "loop", type: "keyword"
|
|
39
|
+
}),
|
|
40
|
+
snippetCompletion("repeat\n\t${}\nuntil ${condition};", {
|
|
41
|
+
label: "repeat", detail: "loop", type: "keyword"
|
|
42
|
+
}),
|
|
43
|
+
snippetCompletion("case ${value} of\n\t${1}: ${};\nelse\n\t${}\nend;", {
|
|
44
|
+
label: "case", detail: "statement", type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snippetCompletion("try\n\t${}\nexcept\n\ton ${E}: ${Exception} do\n\t\t${}\nend;", {
|
|
47
|
+
label: "try", detail: "except", type: "keyword"
|
|
48
|
+
}),
|
|
49
|
+
snippetCompletion("try\n\t${}\nfinally\n\t${}\nend;", {
|
|
50
|
+
label: "try", detail: "finally", type: "keyword"
|
|
51
|
+
}),
|
|
52
|
+
snippetCompletion("${TName} = class\nprivate\n\t${}\npublic\n\tconstructor Create;\nend;", { label: "class", detail: "type", type: "keyword" }),
|
|
53
|
+
snippetCompletion("${TName} = record\n\t${}\nend;", { label: "record", detail: "type", type: "keyword" })
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
Completes the names declared in the file, each where it is in scope. A
|
|
57
|
+
subprogram's parameters, locals and `Result` count inside it, a variable
|
|
58
|
+
declared in a block counts to the end of the block, and a loop variable
|
|
59
|
+
declared with `for var` counts in its loop. Names declared at the top of
|
|
60
|
+
the file count from their declaration on. Inside a method, the class's
|
|
61
|
+
fields, methods and properties count too, and so does `Self`. After
|
|
62
|
+
`name.` it offers the members of the type of `name`, when the file
|
|
63
|
+
declares that type.
|
|
64
|
+
*/
|
|
65
|
+
declare const localCompletionSource = context => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const tree = syntaxTree(context.state);
|
|
68
|
+
const inner = tree.resolveInner(context.pos, -1);
|
|
69
|
+
if (inStringOrComment(inner))
|
|
70
|
+
return null;
|
|
71
|
+
const names = gather(context.state, tree);
|
|
72
|
+
const member = completeMember(context, names, inner);
|
|
73
|
+
if (member)
|
|
74
|
+
return member.options.length ? member : null;
|
|
75
|
+
if (context.matchBefore(/\.\s*\w*$/))
|
|
76
|
+
return null;
|
|
77
|
+
if (dontComplete.indexOf(inner.name) > -1 || dontComplete.indexOf((_b = (_a = inner.parent) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "") > -1)
|
|
78
|
+
return null;
|
|
79
|
+
const word = context.matchBefore(/[a-zA-Z_]\w*$/);
|
|
80
|
+
if (!word && !context.explicit)
|
|
81
|
+
return null;
|
|
82
|
+
const options = [];
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
const add = (option) => {
|
|
85
|
+
if (seen.has(key(option.label)))
|
|
86
|
+
return;
|
|
87
|
+
seen.add(key(option.label));
|
|
88
|
+
options.push(option);
|
|
89
|
+
};
|
|
90
|
+
// Later definitions are closer to the cursor, so they win on a name clash.
|
|
91
|
+
for (let i = names.definitions.length - 1; i >= 0; i--) {
|
|
92
|
+
const d = names.definitions[i];
|
|
93
|
+
if (d.from > context.pos || d.to < context.pos)
|
|
94
|
+
continue;
|
|
95
|
+
if (word && d.at == word.from)
|
|
96
|
+
continue;
|
|
97
|
+
add({ label: d.label, type: d.type });
|
|
98
|
+
}
|
|
99
|
+
const owner = ownerAt(names, context.pos);
|
|
100
|
+
if (owner)
|
|
101
|
+
for (const option of membersOf(names, owner))
|
|
102
|
+
add(option);
|
|
103
|
+
return { from: word ? word.from : context.pos, options, validFor: identifier };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
A language provider based on the Lezer Pascal parser in this package,
|
|
108
|
+
extended with highlighting, folding and indentation information.
|
|
109
|
+
*/
|
|
110
|
+
declare const pascalLanguage: LRLanguage;
|
|
111
|
+
/**
|
|
112
|
+
Autocompletion for Pascal's reserved words and directives, snippets, the
|
|
113
|
+
predefined types, the common RTL and SysUtils routines and the common units.
|
|
114
|
+
It offers nothing inside strings and comments.
|
|
115
|
+
*/
|
|
116
|
+
declare const pascalCompletion: CompletionSource;
|
|
117
|
+
/**
|
|
118
|
+
Pascal language support, with completion for keywords, snippets, the
|
|
119
|
+
predefined types, the common routines and units, and the names declared in
|
|
120
|
+
the file.
|
|
121
|
+
*/
|
|
122
|
+
declare function pascal(): LanguageSupport;
|
|
123
|
+
|
|
124
|
+
export { localCompletionSource, parser, pascal, pascalCompletion, pascalLanguage, snippets };
|