@spyglassmc/mcdoc 0.1.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/README.md +20 -0
- package/lib/binder/index.d.ts +3 -0
- package/lib/binder/index.js +19 -0
- package/lib/binder/uriBinder.d.ts +3 -0
- package/lib/binder/uriBinder.js +50 -0
- package/lib/binder/util.d.ts +4 -0
- package/lib/binder/util.js +16 -0
- package/lib/checker/CheckerContext.d.ts +18 -0
- package/lib/checker/CheckerContext.js +3 -0
- package/lib/checker/entry.d.ts +4 -0
- package/lib/checker/entry.js +358 -0
- package/lib/checker/index.d.ts +2 -0
- package/lib/checker/index.js +18 -0
- package/lib/colorizer/index.d.ts +6 -0
- package/lib/colorizer/index.js +18 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +50 -0
- package/lib/node/index.d.ts +326 -0
- package/lib/node/index.js +277 -0
- package/lib/parser/index.d.ts +44 -0
- package/lib/parser/index.js +631 -0
- package/lib/type/index.d.ts +161 -0
- package/lib/type/index.js +398 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# `@spyglassmc/mcdoc`
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://npmjs.com/package/@spyglassmc/mcdoc)
|
|
6
|
+
|
|
7
|
+
This package contains parsers and processors for [the `mcdoc` language][mcdoc-format] designed by [Yurihaia][yurihaia].
|
|
8
|
+
|
|
9
|
+
# Contributions
|
|
10
|
+
|
|
11
|
+
## Languages
|
|
12
|
+
|
|
13
|
+
- `mcdoc` language that is associated with the `.mcdoc` file extension. The implementation strictly follows the [mcdoc Format][mcdoc-format]
|
|
14
|
+
|
|
15
|
+
## Processors
|
|
16
|
+
|
|
17
|
+
### Validators
|
|
18
|
+
|
|
19
|
+
[mcdoc-format]: https://spyglassmc.com/user/mcdoc
|
|
20
|
+
[yurihaia]: https://github.com/Yurihaia
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./uriBinder"), exports);
|
|
18
|
+
__exportStar(require("./util"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uriBinder = void 0;
|
|
4
|
+
const core_1 = require("@spyglassmc/core");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
const Extension = '.mcdoc';
|
|
7
|
+
const McdocRootPrefix = 'mcdoc/';
|
|
8
|
+
const uriBinder = (uris, ctx) => {
|
|
9
|
+
let urisAndRels = [];
|
|
10
|
+
for (const uri of uris) {
|
|
11
|
+
if (!uri.endsWith(Extension)) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
let rel = core_1.fileUtil.getRel(uri, ctx.roots);
|
|
15
|
+
if (!rel) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
rel = rel
|
|
19
|
+
.slice(0, -Extension.length)
|
|
20
|
+
.replace(/(^|\/)mod$/, '');
|
|
21
|
+
urisAndRels.push([uri, rel]);
|
|
22
|
+
}
|
|
23
|
+
// Now the value of `urisAndRels`:
|
|
24
|
+
// file:///root/mcdoc/foo/mod.mcdoc -> mcdoc/foo
|
|
25
|
+
// file:///root/mcdoc/foo/bar.mcdoc -> mcdoc/foo/bar
|
|
26
|
+
// A special check for the directory named `mcdoc`:
|
|
27
|
+
// If all files are put under this folder, we will treat that folder as the "root" instead.
|
|
28
|
+
if (urisAndRels.every(([_, rel]) => rel.startsWith(McdocRootPrefix))) {
|
|
29
|
+
urisAndRels = urisAndRels
|
|
30
|
+
.map(([uri, rel]) => [uri, rel.slice(McdocRootPrefix.length)]);
|
|
31
|
+
}
|
|
32
|
+
// Now the value of `urisAndRels`:
|
|
33
|
+
// file:///root/mcdoc/foo/mod.mcdoc -> foo
|
|
34
|
+
// file:///root/mcdoc/foo/bar.mcdoc -> foo/bar
|
|
35
|
+
for (const [uri, rel] of urisAndRels) {
|
|
36
|
+
ctx.symbols
|
|
37
|
+
.query(uri, 'mcdoc', (0, util_1.segToIdentifier)(rel.split('/')))
|
|
38
|
+
.ifKnown(() => { })
|
|
39
|
+
.elseEnter({
|
|
40
|
+
data: {
|
|
41
|
+
subcategory: 'module',
|
|
42
|
+
},
|
|
43
|
+
usage: {
|
|
44
|
+
type: 'implementation',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.uriBinder = uriBinder;
|
|
50
|
+
//# sourceMappingURL=uriBinder.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.segToIdentifier = exports.identifierToSeg = void 0;
|
|
4
|
+
function identifierToSeg(identifier) {
|
|
5
|
+
const ans = identifier.slice(2).split('::');
|
|
6
|
+
if (ans.length === 1 && ans[0] === '') {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
return ans;
|
|
10
|
+
}
|
|
11
|
+
exports.identifierToSeg = identifierToSeg;
|
|
12
|
+
function segToIdentifier(seg) {
|
|
13
|
+
return `::${seg.join('::')}`;
|
|
14
|
+
}
|
|
15
|
+
exports.segToIdentifier = segToIdentifier;
|
|
16
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as core from '@spyglassmc/core';
|
|
2
|
+
import type { Symbol } from '@spyglassmc/core';
|
|
3
|
+
import type { Segments } from '../binder';
|
|
4
|
+
export interface CheckerContext extends core.CheckerContext {
|
|
5
|
+
/**
|
|
6
|
+
* The current module's identifier.
|
|
7
|
+
*/
|
|
8
|
+
modIdentifier: string;
|
|
9
|
+
/**
|
|
10
|
+
* The current module's segments.
|
|
11
|
+
*/
|
|
12
|
+
modSeg: Segments;
|
|
13
|
+
/**
|
|
14
|
+
* The current module's symbol.
|
|
15
|
+
*/
|
|
16
|
+
modSymbol: Symbol;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=CheckerContext.d.ts.map
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.module_ = void 0;
|
|
4
|
+
// import type * as core from '@spyglassmc/core'
|
|
5
|
+
// import type { Checker, RangeLike, Symbol, SymbolQuery } from '@spyglassmc/core'
|
|
6
|
+
// import { ErrorSeverity, Range, ResourceLocationNode, SymbolPath, SymbolUtil } from '@spyglassmc/core'
|
|
7
|
+
// import { localeQuote, localize } from '@spyglassmc/locales'
|
|
8
|
+
// import type { Segments } from '../binder'
|
|
9
|
+
// import { identifierToSeg, segToIdentifier } from '../binder'
|
|
10
|
+
// import type { DispatchStatementNode, IdentPathToken, InjectClauseNode, MainNode, UseStatementNode } from '../node'
|
|
11
|
+
// import { CompoundFieldNode, EnumFieldNode, EnumNode, ExtendableRootRegistryMap, StructNode } from '../node'
|
|
12
|
+
// import type { CheckerContext } from './CheckerContext'
|
|
13
|
+
const module_ = async (node, ctx) => {
|
|
14
|
+
// const modSeg = uriToSeg(ctx.doc.uri, ctx)
|
|
15
|
+
// if (modSeg === undefined) {
|
|
16
|
+
// ctx.err.report(localize('mcdoc.checker.entry.undefined-mod-seg'), 0, ErrorSeverity.Warning)
|
|
17
|
+
// return
|
|
18
|
+
// } else if (modSeg.length === 0) {
|
|
19
|
+
// ctx.err.report(localize('mcdoc.checker.entry.empty-mod-seg'), 0, ErrorSeverity.Warning)
|
|
20
|
+
// }
|
|
21
|
+
// const modIdentifier = segToIdentifier(modSeg)
|
|
22
|
+
// const modSymbol = ctx.symbols.query(ctx.doc, 'mcdoc', modIdentifier).symbol!
|
|
23
|
+
// const hoistingNodes: (StructNode | EnumNode | ModuleDeclarationNode | UseStatementNode)[] = []
|
|
24
|
+
// const checkingNodes: (StructNode | EnumNode | DispatchStatementNode | InjectClauseNode)[] = []
|
|
25
|
+
// for (const childNode of node.children) {
|
|
26
|
+
// switch (childNode.type) {
|
|
27
|
+
// case 'mcdoc:struct':
|
|
28
|
+
// hoistingNodes.push(childNode)
|
|
29
|
+
// checkingNodes.push(childNode)
|
|
30
|
+
// break
|
|
31
|
+
// case 'mcdoc:describes_clause':
|
|
32
|
+
// checkingNodes.push(childNode)
|
|
33
|
+
// break
|
|
34
|
+
// case 'mcdoc:enum':
|
|
35
|
+
// hoistingNodes.push(childNode)
|
|
36
|
+
// checkingNodes.push(childNode)
|
|
37
|
+
// break
|
|
38
|
+
// case 'mcdoc:inject_clause':
|
|
39
|
+
// checkingNodes.push(childNode)
|
|
40
|
+
// break
|
|
41
|
+
// case 'mcdoc:module_declaration':
|
|
42
|
+
// hoistingNodes.push(childNode)
|
|
43
|
+
// break
|
|
44
|
+
// case 'mcdoc:use_statement':
|
|
45
|
+
// hoistingNodes.push(childNode)
|
|
46
|
+
// break
|
|
47
|
+
// case 'comment':
|
|
48
|
+
// default:
|
|
49
|
+
// break
|
|
50
|
+
// }
|
|
51
|
+
// }
|
|
52
|
+
// const mcdocCtx: CheckerContext = {
|
|
53
|
+
// ...ctx,
|
|
54
|
+
// modIdentifier,
|
|
55
|
+
// modSeg,
|
|
56
|
+
// modSymbol,
|
|
57
|
+
// }
|
|
58
|
+
// // Hoisting declarations.
|
|
59
|
+
// for (const childNode of hoistingNodes) {
|
|
60
|
+
// switch (childNode.type) {
|
|
61
|
+
// case 'mcdoc:struct':
|
|
62
|
+
// compoundDefinitionHoisting(childNode, mcdocCtx)
|
|
63
|
+
// break
|
|
64
|
+
// case 'mcdoc:enum':
|
|
65
|
+
// enumDefinitionHoisting(childNode, mcdocCtx)
|
|
66
|
+
// break
|
|
67
|
+
// case 'mcdoc:module_declaration':
|
|
68
|
+
// moduleDeclaration(childNode, mcdocCtx)
|
|
69
|
+
// break
|
|
70
|
+
// case 'mcdoc:use_statement':
|
|
71
|
+
// await useClause(childNode, mcdocCtx)
|
|
72
|
+
// break
|
|
73
|
+
// }
|
|
74
|
+
// }
|
|
75
|
+
// // Actual checking.
|
|
76
|
+
// for (const childNode of checkingNodes) {
|
|
77
|
+
// switch (childNode.type) {
|
|
78
|
+
// case 'mcdoc:struct':
|
|
79
|
+
// await compoundDefinition(childNode, mcdocCtx)
|
|
80
|
+
// break
|
|
81
|
+
// case 'mcdoc:enum':
|
|
82
|
+
// enumDefinition(childNode, mcdocCtx)
|
|
83
|
+
// break
|
|
84
|
+
// case 'mcdoc:describes_clause':
|
|
85
|
+
// await dispatchStatement(childNode, mcdocCtx)
|
|
86
|
+
// break
|
|
87
|
+
// case 'mcdoc:inject_clause':
|
|
88
|
+
// await injectClause(childNode, mcdocCtx)
|
|
89
|
+
// break
|
|
90
|
+
// }
|
|
91
|
+
// }
|
|
92
|
+
};
|
|
93
|
+
exports.module_ = module_;
|
|
94
|
+
// async function compoundFields<N extends { fields: CompoundFieldNode[] }>(definitionQuery: core.SymbolQuery, node: N, ctx: CheckerContext) {
|
|
95
|
+
// const promises: Promise<void>[] = []
|
|
96
|
+
// definitionQuery.onEach(node.fields, field => {
|
|
97
|
+
// promises.push(new Promise(resolve => {
|
|
98
|
+
// definitionQuery.member(field.key.value, member => member
|
|
99
|
+
// .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, field.key))
|
|
100
|
+
// .else(async () => {
|
|
101
|
+
// const data = await CompoundFieldNode.toSymbolData(field, async n => (await resolveIdentPath(n, ctx))?.symbol)
|
|
102
|
+
// member.enter({
|
|
103
|
+
// data: { data, desc: field.doc.value, subcategory: 'compound_key' },
|
|
104
|
+
// usage: { type: 'definition', node: field.key, fullRange: field },
|
|
105
|
+
// })
|
|
106
|
+
// resolve()
|
|
107
|
+
// })
|
|
108
|
+
// )
|
|
109
|
+
// }))
|
|
110
|
+
// })
|
|
111
|
+
// return Promise.allSettled(promises)
|
|
112
|
+
// }
|
|
113
|
+
// const compoundDefinition = async (node: StructNode, ctx: CheckerContext): Promise<void> => {
|
|
114
|
+
// const definitionQuery = ctx.symbols.query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
|
|
115
|
+
// if (!definitionQuery.symbol) {
|
|
116
|
+
// return
|
|
117
|
+
// }
|
|
118
|
+
// const data = await StructNode.toSymbolData(node, async n => (await resolveIdentPath(n, ctx))?.symbol)
|
|
119
|
+
// definitionQuery.amend({ data: { data } })
|
|
120
|
+
// await compoundFields(definitionQuery, node, ctx)
|
|
121
|
+
// }
|
|
122
|
+
// const compoundDefinitionHoisting = (node: StructNode, ctx: CheckerContext): void => {
|
|
123
|
+
// if (!node.identifier.value) {
|
|
124
|
+
// return
|
|
125
|
+
// }
|
|
126
|
+
// ctx.symbols
|
|
127
|
+
// .query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
|
|
128
|
+
// .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, node.identifier))
|
|
129
|
+
// .elseEnter({
|
|
130
|
+
// data: {
|
|
131
|
+
// desc: node.doc.value,
|
|
132
|
+
// subcategory: 'compound',
|
|
133
|
+
// },
|
|
134
|
+
// usage: {
|
|
135
|
+
// type: 'definition',
|
|
136
|
+
// node: node.identifier,
|
|
137
|
+
// fullRange: node,
|
|
138
|
+
// },
|
|
139
|
+
// })
|
|
140
|
+
// }
|
|
141
|
+
// const dispatchStatement = async (node: DispatchStatementNode, ctx: CheckerContext): Promise<void> => {
|
|
142
|
+
// const registry = ResourceLocationNode.toString(node.registry, 'full')
|
|
143
|
+
// if (!(registry in ExtendableRootRegistryMap)) {
|
|
144
|
+
// return
|
|
145
|
+
// }
|
|
146
|
+
// const describerSymbol = await resolveIdentPath(node.path, ctx)
|
|
147
|
+
// const category = ExtendableRootRegistryMap[registry as keyof typeof ExtendableRootRegistryMap]
|
|
148
|
+
// const objects = node.objects ? node.objects.map(v => ResourceLocationNode.toString(v, 'full')) : ['@default']
|
|
149
|
+
// ctx.symbols
|
|
150
|
+
// .query(ctx.doc, 'mcdoc/description', category)
|
|
151
|
+
// .enter({})
|
|
152
|
+
// .onEach(objects, (object, query) => {
|
|
153
|
+
// query.member(object, member => member
|
|
154
|
+
// .enter({
|
|
155
|
+
// data: {
|
|
156
|
+
// relations: {
|
|
157
|
+
// describedBy: SymbolPath.fromSymbol(describerSymbol?.symbol),
|
|
158
|
+
// },
|
|
159
|
+
// },
|
|
160
|
+
// usage: { type: 'definition', range: node },
|
|
161
|
+
// })
|
|
162
|
+
// )
|
|
163
|
+
// })
|
|
164
|
+
// }
|
|
165
|
+
// function enumFields<N extends { fields: EnumFieldNode[] }>(definitionQuery: core.SymbolQuery, node: N, ctx: CheckerContext) {
|
|
166
|
+
// definitionQuery.onEach(node.fields, field => {
|
|
167
|
+
// definitionQuery.member(field.key.value, member => member
|
|
168
|
+
// .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, field.key))
|
|
169
|
+
// .else(() => {
|
|
170
|
+
// const data = EnumFieldNode.toSymbolData(field)
|
|
171
|
+
// member.enter({
|
|
172
|
+
// data: { data, desc: field.doc.value, subcategory: 'enum_key' },
|
|
173
|
+
// usage: { type: 'definition', node: field.key, fullRange: field },
|
|
174
|
+
// })
|
|
175
|
+
// })
|
|
176
|
+
// )
|
|
177
|
+
// })
|
|
178
|
+
// }
|
|
179
|
+
// const enumDefinition = (node: EnumNode, ctx: CheckerContext): void => {
|
|
180
|
+
// const definitionQuery = ctx.symbols.query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
|
|
181
|
+
// if (!definitionQuery.symbol) {
|
|
182
|
+
// return
|
|
183
|
+
// }
|
|
184
|
+
// const data = EnumNode.toSymbolData(node)
|
|
185
|
+
// definitionQuery.amend({ data: { data } })
|
|
186
|
+
// enumFields(definitionQuery, node, ctx)
|
|
187
|
+
// }
|
|
188
|
+
// const enumDefinitionHoisting = (node: EnumNode, ctx: CheckerContext): void => {
|
|
189
|
+
// if (!node.identifier.value) {
|
|
190
|
+
// return
|
|
191
|
+
// }
|
|
192
|
+
// ctx.symbols
|
|
193
|
+
// .query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
|
|
194
|
+
// .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, node.identifier))
|
|
195
|
+
// .elseEnter({
|
|
196
|
+
// data: {
|
|
197
|
+
// desc: node.doc.value,
|
|
198
|
+
// subcategory: 'enum',
|
|
199
|
+
// },
|
|
200
|
+
// usage: {
|
|
201
|
+
// type: 'definition',
|
|
202
|
+
// node: node.identifier,
|
|
203
|
+
// fullRange: node,
|
|
204
|
+
// },
|
|
205
|
+
// })
|
|
206
|
+
// }
|
|
207
|
+
// const injectClause = async (node: InjectClauseNode, ctx: CheckerContext): Promise<void> => {
|
|
208
|
+
// if (!node.def) {
|
|
209
|
+
// return
|
|
210
|
+
// }
|
|
211
|
+
// const injectedQuery = await resolveIdentPath(node.def.path, ctx)
|
|
212
|
+
// if (!injectedQuery?.symbol) {
|
|
213
|
+
// return
|
|
214
|
+
// }
|
|
215
|
+
// if (!(
|
|
216
|
+
// (node.def?.type === 'mcdoc:inject_clause/compound' && injectedQuery.symbol.subcategory === 'compound') ||
|
|
217
|
+
// (node.def?.type === 'mcdoc:inject_clause/enum' && injectedQuery.symbol.subcategory === 'enum')
|
|
218
|
+
// )) {
|
|
219
|
+
// const target = localize(`mcdoc.node.${injectedQuery.symbol.subcategory === 'enum' ? 'enum-definition' : 'compound-definition'}`)
|
|
220
|
+
// const injection = localize(`mcdoc.node.${node.def?.type === 'mcdoc:inject_clause/enum' ? 'enum-definition' : 'compound-definition'}`)
|
|
221
|
+
// ctx.err.report(localize('mcdoc.checker.inject-clause.unmatched-injection', target, injection), node.def.path)
|
|
222
|
+
// return
|
|
223
|
+
// }
|
|
224
|
+
// if (node.def?.type === 'mcdoc:inject_clause/compound') {
|
|
225
|
+
// await compoundFields(injectedQuery, node.def, ctx)
|
|
226
|
+
// } else if (node.def?.type === 'mcdoc:inject_clause/enum') {
|
|
227
|
+
// enumFields(injectedQuery, node.def, ctx)
|
|
228
|
+
// }
|
|
229
|
+
// }
|
|
230
|
+
// const moduleDeclaration = (node: ModuleDeclarationNode, ctx: CheckerContext): void => {
|
|
231
|
+
// if (node.identifier.value.length) {
|
|
232
|
+
// const declaredSeg = [...ctx.modSeg, node.identifier.value]
|
|
233
|
+
// const declaredIdentifier = segToIdentifier(declaredSeg)
|
|
234
|
+
// ctx.symbols
|
|
235
|
+
// .query(ctx.doc, 'mcdoc', declaredIdentifier)
|
|
236
|
+
// .ifUnknown(() => ctx.err.report(
|
|
237
|
+
// localize('mcdoc.checker.module-declaration.non-existent', localeQuote(declaredIdentifier)),
|
|
238
|
+
// node.identifier
|
|
239
|
+
// ))
|
|
240
|
+
// .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.module-declaration.duplicated', ctx, symbol, node.identifier))
|
|
241
|
+
// .elseEnter({
|
|
242
|
+
// usage: {
|
|
243
|
+
// type: 'declaration',
|
|
244
|
+
// node: node.identifier,
|
|
245
|
+
// fullRange: node,
|
|
246
|
+
// },
|
|
247
|
+
// })
|
|
248
|
+
// }
|
|
249
|
+
// }
|
|
250
|
+
// const useClause = async (node: UseStatementNode, ctx: CheckerContext): Promise<void> => {
|
|
251
|
+
// const usedSymbol = (await resolveIdentPath(node.path, ctx))?.symbol
|
|
252
|
+
// if (usedSymbol) {
|
|
253
|
+
// const lastToken = node.path.children[node.path.children.length - 1]
|
|
254
|
+
// ctx.symbols
|
|
255
|
+
// .query({ doc: ctx.doc, node }, 'mcdoc', ctx.modIdentifier, usedSymbol.identifier)
|
|
256
|
+
// .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, lastToken))
|
|
257
|
+
// .elseEnter({
|
|
258
|
+
// data: {
|
|
259
|
+
// relations: {
|
|
260
|
+
// aliasOf: { category: 'mcdoc', path: usedSymbol.path },
|
|
261
|
+
// },
|
|
262
|
+
// },
|
|
263
|
+
// usage: {
|
|
264
|
+
// type: 'declaration',
|
|
265
|
+
// node: lastToken,
|
|
266
|
+
// fullRange: node,
|
|
267
|
+
// ...node.isExport ? {} : { visibility: SymbolVisibility.File },
|
|
268
|
+
// },
|
|
269
|
+
// })
|
|
270
|
+
// }
|
|
271
|
+
// }
|
|
272
|
+
// function reportDuplicatedDeclaration(localeString: string, ctx: CheckerContext, symbol: Symbol, range: RangeLike) {
|
|
273
|
+
// ctx.err.report(
|
|
274
|
+
// localize(localeString, localeQuote(symbol.identifier)),
|
|
275
|
+
// range, ErrorSeverity.Warning,
|
|
276
|
+
// {
|
|
277
|
+
// related: [{
|
|
278
|
+
// location: SymbolUtil.getDeclaredLocation(symbol) as core.Location,
|
|
279
|
+
// message: localize(`${localeString}.related`, localeQuote(symbol.identifier)),
|
|
280
|
+
// }],
|
|
281
|
+
// }
|
|
282
|
+
// )
|
|
283
|
+
// }
|
|
284
|
+
// function uriToSeg(uri: string, ctx: core.CheckerContext): Segments | undefined {
|
|
285
|
+
// const identifier = Object
|
|
286
|
+
// .keys(ctx.symbols.global.mcdoc ?? {})
|
|
287
|
+
// .find(identifier => {
|
|
288
|
+
// const symbol = ctx.symbols.global.mcdoc![identifier]!
|
|
289
|
+
// return symbol.subcategory === 'module' && symbol.implementation?.some(loc => loc.uri === uri)
|
|
290
|
+
// })
|
|
291
|
+
// return identifier ? identifierToSeg(identifier) : undefined
|
|
292
|
+
// }
|
|
293
|
+
// function segToUri(seg: Segments, ctx: core.CheckerContext): string | undefined {
|
|
294
|
+
// const identifier = segToIdentifier(seg)
|
|
295
|
+
// return ctx.symbols.global.mcdoc?.[identifier]?.implementation?.[0]?.uri
|
|
296
|
+
// }
|
|
297
|
+
// /**
|
|
298
|
+
// * @returns The actual symbol being used/imported from another module.
|
|
299
|
+
// */
|
|
300
|
+
// async function resolveIdentPath(identPath: IdentPathToken, ctx: CheckerContext): Promise<SymbolQuery | undefined> {
|
|
301
|
+
// const targetSeg = identPath.fromGlobalRoot ? [] : [...ctx.modSeg]
|
|
302
|
+
// for (const [i, token] of identPath.children.entries()) {
|
|
303
|
+
// if (i < identPath.children.length - 1) {
|
|
304
|
+
// // Referencing to a module.
|
|
305
|
+
// // Resolve this token.
|
|
306
|
+
// if (token.value === 'super') {
|
|
307
|
+
// if (targetSeg.length === 0) {
|
|
308
|
+
// ctx.err.report(localize('mcdoc.checker.ident-path.super-from-root'), Range.span(token, identPath))
|
|
309
|
+
// return undefined
|
|
310
|
+
// }
|
|
311
|
+
// targetSeg.pop()
|
|
312
|
+
// } else {
|
|
313
|
+
// targetSeg.push(token.value)
|
|
314
|
+
// }
|
|
315
|
+
// ctx.symbols
|
|
316
|
+
// .query(ctx.doc, 'mcdoc', segToIdentifier(targetSeg))
|
|
317
|
+
// .amend({
|
|
318
|
+
// usage: {
|
|
319
|
+
// type: 'reference',
|
|
320
|
+
// node: token,
|
|
321
|
+
// skipRenaming: token.value === 'super',
|
|
322
|
+
// },
|
|
323
|
+
// })
|
|
324
|
+
// } else {
|
|
325
|
+
// // Referencing to a compound or enum.
|
|
326
|
+
// const currentId = segToIdentifier(ctx.modSeg)
|
|
327
|
+
// const targetId = segToIdentifier(targetSeg)
|
|
328
|
+
// if (currentId !== targetId) {
|
|
329
|
+
// // The referenced compound/enum is in another module.
|
|
330
|
+
// // We should load and check that module first.
|
|
331
|
+
// const targetUri = segToUri(targetSeg, ctx)
|
|
332
|
+
// const ensured = targetUri ? await ctx.ensureChecked(targetUri) : false
|
|
333
|
+
// if (!ensured) {
|
|
334
|
+
// ctx.err.report(
|
|
335
|
+
// localize('mcdoc.checker.ident-path.unknown-module', localeQuote(targetId)),
|
|
336
|
+
// Range.span(token, identPath)
|
|
337
|
+
// )
|
|
338
|
+
// return undefined
|
|
339
|
+
// }
|
|
340
|
+
// }
|
|
341
|
+
// return ctx.symbols
|
|
342
|
+
// .query(ctx.doc, 'mcdoc', targetId, token.value)
|
|
343
|
+
// .ifUnknown(() => ctx.err.report(
|
|
344
|
+
// localize('mcdoc.checker.ident-path.unknown-identifier', localeQuote(token.value), localeQuote(targetId)),
|
|
345
|
+
// Range.span(token, identPath)
|
|
346
|
+
// ))
|
|
347
|
+
// .elseResolveAlias()
|
|
348
|
+
// .elseEnter({
|
|
349
|
+
// usage: {
|
|
350
|
+
// type: 'reference',
|
|
351
|
+
// node: token,
|
|
352
|
+
// },
|
|
353
|
+
// })
|
|
354
|
+
// }
|
|
355
|
+
// }
|
|
356
|
+
// return undefined
|
|
357
|
+
// }
|
|
358
|
+
//# sourceMappingURL=entry.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./entry"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Colorizer, MetaRegistry } from '@spyglassmc/core';
|
|
2
|
+
import type { IdentifierNode, LiteralNode } from '../node';
|
|
3
|
+
export declare const identifier: Colorizer<IdentifierNode>;
|
|
4
|
+
export declare const literal: Colorizer<LiteralNode>;
|
|
5
|
+
export declare function registerMcdocColorizer(meta: MetaRegistry): void;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerMcdocColorizer = exports.literal = exports.identifier = void 0;
|
|
4
|
+
const core_1 = require("@spyglassmc/core");
|
|
5
|
+
const identifier = node => {
|
|
6
|
+
return [core_1.ColorToken.create(node, 'variable')];
|
|
7
|
+
};
|
|
8
|
+
exports.identifier = identifier;
|
|
9
|
+
const literal = node => {
|
|
10
|
+
return [core_1.ColorToken.create(node, node.colorTokenType ?? 'literal')];
|
|
11
|
+
};
|
|
12
|
+
exports.literal = literal;
|
|
13
|
+
function registerMcdocColorizer(meta) {
|
|
14
|
+
meta.registerColorizer('mcdoc:literal', exports.literal);
|
|
15
|
+
meta.registerColorizer('mcdoc:identifier', exports.identifier);
|
|
16
|
+
}
|
|
17
|
+
exports.registerMcdocColorizer = registerMcdocColorizer;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as core from '@spyglassmc/core';
|
|
2
|
+
export * as checker from './checker';
|
|
3
|
+
export * as colorizer from './colorizer';
|
|
4
|
+
export * from './node';
|
|
5
|
+
export * from './parser';
|
|
6
|
+
export * from './type';
|
|
7
|
+
export declare const initialize: core.ProjectInitializer;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.initialize = exports.colorizer = exports.checker = void 0;
|
|
30
|
+
const binder = __importStar(require("./binder"));
|
|
31
|
+
const checker = __importStar(require("./checker"));
|
|
32
|
+
const colorizer = __importStar(require("./colorizer"));
|
|
33
|
+
const parser = __importStar(require("./parser"));
|
|
34
|
+
exports.checker = __importStar(require("./checker"));
|
|
35
|
+
exports.colorizer = __importStar(require("./colorizer"));
|
|
36
|
+
__exportStar(require("./node"), exports);
|
|
37
|
+
__exportStar(require("./parser"), exports);
|
|
38
|
+
__exportStar(require("./type"), exports);
|
|
39
|
+
/* istanbul ignore next */
|
|
40
|
+
const initialize = ({ meta }) => {
|
|
41
|
+
meta.registerLanguage('mcdoc', {
|
|
42
|
+
extensions: ['.mcdoc'],
|
|
43
|
+
parser: parser.module_,
|
|
44
|
+
});
|
|
45
|
+
meta.registerChecker('mcdoc:module', checker.module_);
|
|
46
|
+
meta.registerUriBinder(binder.uriBinder);
|
|
47
|
+
colorizer.registerMcdocColorizer(meta);
|
|
48
|
+
};
|
|
49
|
+
exports.initialize = initialize;
|
|
50
|
+
//# sourceMappingURL=index.js.map
|