skir 0.0.5 → 0.0.7
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/dist/casing.test.js +1 -1
- package/dist/casing.test.js.map +1 -1
- package/dist/command_line_parser.d.ts.map +1 -1
- package/dist/command_line_parser.js +76 -36
- package/dist/command_line_parser.js.map +1 -1
- package/dist/command_line_parser.test.js +119 -31
- package/dist/command_line_parser.test.js.map +1 -1
- package/dist/compiler.js +59 -84
- package/dist/compiler.js.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -13
- package/dist/config.js.map +1 -1
- package/dist/config_parser.d.ts +31 -0
- package/dist/config_parser.d.ts.map +1 -0
- package/dist/config_parser.js +146 -0
- package/dist/config_parser.js.map +1 -0
- package/dist/config_parser.test.d.ts +2 -0
- package/dist/config_parser.test.d.ts.map +1 -0
- package/dist/config_parser.test.js +419 -0
- package/dist/config_parser.test.js.map +1 -0
- package/dist/doc_comment_parser.d.ts +3 -2
- package/dist/doc_comment_parser.d.ts.map +1 -1
- package/dist/doc_comment_parser.js +56 -49
- package/dist/doc_comment_parser.js.map +1 -1
- package/dist/doc_comment_parser.test.js +86 -154
- package/dist/doc_comment_parser.test.js.map +1 -1
- package/dist/error_renderer.d.ts +5 -0
- package/dist/error_renderer.d.ts.map +1 -1
- package/dist/error_renderer.js +27 -3
- package/dist/error_renderer.js.map +1 -1
- package/dist/exit_error.d.ts +8 -0
- package/dist/exit_error.d.ts.map +1 -0
- package/dist/exit_error.js +8 -0
- package/dist/exit_error.js.map +1 -0
- package/dist/io.d.ts +2 -0
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +22 -3
- package/dist/io.js.map +1 -1
- package/dist/module_collector.d.ts.map +1 -1
- package/dist/module_collector.js +12 -7
- package/dist/module_collector.js.map +1 -1
- package/dist/module_set.d.ts.map +1 -1
- package/dist/module_set.js +33 -16
- package/dist/module_set.js.map +1 -1
- package/dist/module_set.test.js +318 -173
- package/dist/module_set.test.js.map +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +16 -16
- package/dist/parser.js.map +1 -1
- package/dist/project_initializer.d.ts.map +1 -1
- package/dist/project_initializer.js +97 -15
- package/dist/project_initializer.js.map +1 -1
- package/dist/tokenizer.d.ts +7 -1
- package/dist/tokenizer.d.ts.map +1 -1
- package/dist/tokenizer.js +12 -0
- package/dist/tokenizer.js.map +1 -1
- package/package.json +14 -9
- package/src/command_line_parser.ts +95 -40
- package/src/compiler.ts +74 -86
- package/src/config.ts +8 -15
- package/src/config_parser.ts +198 -0
- package/src/doc_comment_parser.ts +65 -49
- package/src/error_renderer.ts +45 -3
- package/src/exit_error.ts +6 -0
- package/src/io.ts +22 -3
- package/src/module_collector.ts +21 -7
- package/src/module_set.ts +35 -19
- package/src/parser.ts +22 -16
- package/src/project_initializer.ts +97 -15
- package/src/tokenizer.ts +20 -2
- package/dist/language_server.d.ts +0 -15
- package/dist/language_server.d.ts.map +0 -1
- package/dist/language_server.js +0 -248
- package/dist/language_server.js.map +0 -1
- package/src/language_server.ts +0 -301
package/src/module_set.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Paths from "path";
|
|
2
2
|
import {
|
|
3
|
+
MutableDocReferenceName,
|
|
3
4
|
unquoteAndUnescape,
|
|
4
5
|
type DenseJson,
|
|
5
6
|
type ErrorSink,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
type Module,
|
|
11
12
|
type MutableArrayType,
|
|
12
13
|
type MutableConstant,
|
|
14
|
+
type MutableDoc,
|
|
13
15
|
type MutableDocReference,
|
|
14
16
|
type MutableMethod,
|
|
15
17
|
type MutableModule,
|
|
@@ -812,7 +814,7 @@ export class ModuleSet {
|
|
|
812
814
|
module: Module,
|
|
813
815
|
errors: ErrorSink,
|
|
814
816
|
): void {
|
|
815
|
-
const doc =
|
|
817
|
+
const doc: MutableDoc =
|
|
816
818
|
documentee.kind === "field" ? documentee.field.doc : documentee.doc;
|
|
817
819
|
|
|
818
820
|
const docReferences = doc.pieces.filter(
|
|
@@ -826,23 +828,24 @@ export class ModuleSet {
|
|
|
826
828
|
// Returns true if resolved, false otherwise.
|
|
827
829
|
const tryResolveReference = (
|
|
828
830
|
ref: MutableDocReference,
|
|
829
|
-
|
|
831
|
+
nameParts: readonly MutableDocReferenceName[],
|
|
830
832
|
scope: Record | Module,
|
|
831
833
|
): boolean => {
|
|
832
834
|
if (ref.absolute && scope !== module) {
|
|
833
835
|
return false;
|
|
834
836
|
}
|
|
835
|
-
const firstName =
|
|
836
|
-
const match = scope.nameToDeclaration[firstName.text];
|
|
837
|
+
const firstName = nameParts[0]!;
|
|
838
|
+
const match = scope.nameToDeclaration[firstName.token.text];
|
|
837
839
|
if (!match) {
|
|
838
840
|
return false;
|
|
839
841
|
}
|
|
840
|
-
if (
|
|
842
|
+
if (nameParts.length === 1) {
|
|
841
843
|
// Single name: must refer to a declaration.
|
|
842
844
|
switch (match.kind) {
|
|
843
845
|
case "constant":
|
|
844
846
|
case "method":
|
|
845
847
|
case "record": {
|
|
848
|
+
firstName.declaration = match;
|
|
846
849
|
ref.referee = match;
|
|
847
850
|
return true;
|
|
848
851
|
}
|
|
@@ -850,6 +853,7 @@ export class ModuleSet {
|
|
|
850
853
|
if (scope.kind !== "record") {
|
|
851
854
|
throw new TypeError(scope.kind);
|
|
852
855
|
}
|
|
856
|
+
firstName.declaration = match;
|
|
853
857
|
ref.referee = {
|
|
854
858
|
kind: "field",
|
|
855
859
|
field: match,
|
|
@@ -857,16 +861,21 @@ export class ModuleSet {
|
|
|
857
861
|
};
|
|
858
862
|
return true;
|
|
859
863
|
}
|
|
864
|
+
case "import-alias": {
|
|
865
|
+
firstName.declaration = match;
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
860
868
|
case "import":
|
|
861
|
-
case "import-alias":
|
|
862
869
|
case "removed":
|
|
863
870
|
return false;
|
|
864
871
|
}
|
|
865
872
|
} else {
|
|
866
873
|
// Multi-part name: first part must be a naming scope.
|
|
867
874
|
switch (match.kind) {
|
|
868
|
-
case "record":
|
|
869
|
-
|
|
875
|
+
case "record": {
|
|
876
|
+
firstName.declaration = match;
|
|
877
|
+
return tryResolveReference(ref, nameParts.slice(1), match);
|
|
878
|
+
}
|
|
870
879
|
case "import":
|
|
871
880
|
case "import-alias": {
|
|
872
881
|
if (scope !== module) {
|
|
@@ -881,9 +890,13 @@ export class ModuleSet {
|
|
|
881
890
|
if (!importedModule?.result) {
|
|
882
891
|
return false;
|
|
883
892
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
893
|
+
let newNameChain: readonly MutableDocReferenceName[];
|
|
894
|
+
if (match.kind === "import") {
|
|
895
|
+
newNameChain = nameParts;
|
|
896
|
+
} else {
|
|
897
|
+
firstName.declaration = match;
|
|
898
|
+
newNameChain = nameParts.slice(1);
|
|
899
|
+
}
|
|
887
900
|
return tryResolveReference(
|
|
888
901
|
ref,
|
|
889
902
|
newNameChain,
|
|
@@ -892,7 +905,10 @@ export class ModuleSet {
|
|
|
892
905
|
}
|
|
893
906
|
case "constant":
|
|
894
907
|
case "field":
|
|
895
|
-
case "method":
|
|
908
|
+
case "method": {
|
|
909
|
+
firstName.declaration = match;
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
896
912
|
case "removed":
|
|
897
913
|
return false;
|
|
898
914
|
}
|
|
@@ -947,13 +963,13 @@ export class ModuleSet {
|
|
|
947
963
|
|
|
948
964
|
// Resolve each reference by searching through scopes in priority order.
|
|
949
965
|
for (const reference of docReferences) {
|
|
950
|
-
const {
|
|
951
|
-
if (
|
|
966
|
+
const { nameParts } = reference;
|
|
967
|
+
if (nameParts.length <= 0) {
|
|
952
968
|
continue;
|
|
953
969
|
}
|
|
954
970
|
let resolved = false;
|
|
955
971
|
for (const scope of scopes) {
|
|
956
|
-
if (tryResolveReference(reference,
|
|
972
|
+
if (tryResolveReference(reference, nameParts, scope)) {
|
|
957
973
|
resolved = true;
|
|
958
974
|
break;
|
|
959
975
|
}
|
|
@@ -1295,7 +1311,7 @@ class DefaultModuleParser extends ModuleParserBase {
|
|
|
1295
1311
|
}
|
|
1296
1312
|
|
|
1297
1313
|
readSourceCode(modulePath: string): string | undefined {
|
|
1298
|
-
return this.fileReader.readTextFile(
|
|
1314
|
+
return this.fileReader.readTextFile(Paths.join(this.rootPath, modulePath));
|
|
1299
1315
|
}
|
|
1300
1316
|
}
|
|
1301
1317
|
|
|
@@ -1325,12 +1341,12 @@ function resolveModulePath(
|
|
|
1325
1341
|
if (modulePath.startsWith("./") || modulePath.startsWith("../")) {
|
|
1326
1342
|
// This is a relative path from the module. Let's transform it into a
|
|
1327
1343
|
// relative path from root.
|
|
1328
|
-
modulePath =
|
|
1344
|
+
modulePath = Paths.join(originModulePath, "..", modulePath);
|
|
1329
1345
|
}
|
|
1330
1346
|
// "a/./b/../c" => "a/c"
|
|
1331
1347
|
// Note that `paths.normalize` will use backslashes on Windows.
|
|
1332
1348
|
// We don't want that.
|
|
1333
|
-
modulePath =
|
|
1349
|
+
modulePath = Paths.normalize(modulePath).replace(/\\/g, "/");
|
|
1334
1350
|
if (modulePath.startsWith(`../`)) {
|
|
1335
1351
|
errors.push({
|
|
1336
1352
|
token: pathToken,
|
package/src/parser.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
ImportAlias,
|
|
8
8
|
MutableConstant,
|
|
9
9
|
MutableDeclaration,
|
|
10
|
+
MutableDoc,
|
|
10
11
|
MutableField,
|
|
11
12
|
MutableMethod,
|
|
12
13
|
MutableModule,
|
|
@@ -27,15 +28,15 @@ import type {
|
|
|
27
28
|
UnresolvedType,
|
|
28
29
|
} from "skir-internal";
|
|
29
30
|
import { convertCase, simpleHash } from "skir-internal";
|
|
30
|
-
import * as
|
|
31
|
-
import {
|
|
31
|
+
import * as Casing from "./casing.js";
|
|
32
|
+
import { mergeDocs } from "./doc_comment_parser.js";
|
|
32
33
|
import { ModuleTokens } from "./tokenizer.js";
|
|
33
34
|
|
|
34
35
|
/** Runs syntactic analysis on a module. */
|
|
35
36
|
export function parseModule(moduleTokens: ModuleTokens): Result<MutableModule> {
|
|
36
|
-
const {
|
|
37
|
+
const { modulePath, sourceCode } = moduleTokens;
|
|
37
38
|
const errors: SkirError[] = [];
|
|
38
|
-
const it = new TokenIterator(
|
|
39
|
+
const it = new TokenIterator(moduleTokens, errors);
|
|
39
40
|
const declarations = parseDeclarations(it, "module");
|
|
40
41
|
it.expectThenNext([""]);
|
|
41
42
|
// Create a mappinng from names to declarations, and check for duplicates.
|
|
@@ -160,7 +161,7 @@ function parseDeclaration(
|
|
|
160
161
|
it: TokenIterator,
|
|
161
162
|
parentNode: "module" | "struct" | "enum",
|
|
162
163
|
): MutableDeclaration | null {
|
|
163
|
-
const doc =
|
|
164
|
+
const doc = collectDoc(it);
|
|
164
165
|
let recordType: "struct" | "enum" = "enum";
|
|
165
166
|
const parentIsRoot = parentNode === "module";
|
|
166
167
|
const expected = [
|
|
@@ -397,7 +398,7 @@ function parseRecord(
|
|
|
397
398
|
if (nameMatch.case < 0) {
|
|
398
399
|
return null;
|
|
399
400
|
}
|
|
400
|
-
|
|
401
|
+
Casing.validate(nameMatch.token, "UpperCamel", it.errors);
|
|
401
402
|
nameToken = nameMatch.token;
|
|
402
403
|
}
|
|
403
404
|
let stableId: number | null = null;
|
|
@@ -475,7 +476,7 @@ function parseField(
|
|
|
475
476
|
}
|
|
476
477
|
case 2: {
|
|
477
478
|
const expectedCasing = type ? "lower_underscore" : "UPPER_UNDERSCORE";
|
|
478
|
-
|
|
479
|
+
Casing.validate(name, expectedCasing, it.errors);
|
|
479
480
|
if (recordType === "enum" && name.text === "UNKNOWN") {
|
|
480
481
|
it.errors.push({
|
|
481
482
|
token: name,
|
|
@@ -789,7 +790,7 @@ function parseImportAs(it: TokenIterator): ImportAlias | null {
|
|
|
789
790
|
if (aliasMatch.case < 0) {
|
|
790
791
|
return null;
|
|
791
792
|
}
|
|
792
|
-
|
|
793
|
+
Casing.validate(aliasMatch.token, "lower_underscore", it.errors);
|
|
793
794
|
if (it.expectThenNext(["from"]).case < 0) return null;
|
|
794
795
|
const modulePathMatch = it.expectThenNext([TOKEN_IS_STRING_LITERAL]);
|
|
795
796
|
if (modulePathMatch.case < 0) {
|
|
@@ -837,7 +838,7 @@ function parseMethod(it: TokenIterator, doc: Doc): MutableMethod | null {
|
|
|
837
838
|
return null;
|
|
838
839
|
}
|
|
839
840
|
const name = nameMatch.token;
|
|
840
|
-
|
|
841
|
+
Casing.validate(name, "UpperCamel", it.errors);
|
|
841
842
|
if (it.expectThenNext(["("]).case < 0) {
|
|
842
843
|
return null;
|
|
843
844
|
}
|
|
@@ -897,7 +898,7 @@ function parseConstant(it: TokenIterator, doc: Doc): MutableConstant | null {
|
|
|
897
898
|
if (nameMatch.case < 0) {
|
|
898
899
|
return null;
|
|
899
900
|
}
|
|
900
|
-
|
|
901
|
+
Casing.validate(nameMatch.token, "UPPER_UNDERSCORE", it.errors);
|
|
901
902
|
if (it.expectThenNext([":"]).case < 0) {
|
|
902
903
|
return null;
|
|
903
904
|
}
|
|
@@ -1046,15 +1047,16 @@ function parseArrayValue(it: TokenIterator): MutableValue[] | null {
|
|
|
1046
1047
|
}
|
|
1047
1048
|
}
|
|
1048
1049
|
|
|
1049
|
-
function
|
|
1050
|
+
function collectDoc(it: TokenIterator): MutableDoc {
|
|
1051
|
+
const { moduleTokens } = it;
|
|
1050
1052
|
const docComments: Token[] = [];
|
|
1051
1053
|
while (it.current.startsWith("///")) {
|
|
1052
1054
|
docComments.push(it.currentToken);
|
|
1053
1055
|
it.next();
|
|
1054
1056
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1057
|
+
return mergeDocs(
|
|
1058
|
+
docComments.map((c) => moduleTokens.posToDoc[c.position] ?? EMPTY_DOC),
|
|
1059
|
+
);
|
|
1058
1060
|
}
|
|
1059
1061
|
|
|
1060
1062
|
const EMPTY_DOC: Doc = {
|
|
@@ -1121,10 +1123,14 @@ interface TokenMatch {
|
|
|
1121
1123
|
}
|
|
1122
1124
|
|
|
1123
1125
|
class TokenIterator {
|
|
1126
|
+
private readonly tokens: readonly Token[];
|
|
1127
|
+
|
|
1124
1128
|
constructor(
|
|
1125
|
-
|
|
1129
|
+
readonly moduleTokens: ModuleTokens,
|
|
1126
1130
|
readonly errors: ErrorSink,
|
|
1127
|
-
) {
|
|
1131
|
+
) {
|
|
1132
|
+
this.tokens = moduleTokens.tokens;
|
|
1133
|
+
}
|
|
1128
1134
|
|
|
1129
1135
|
// Returns both:
|
|
1130
1136
|
// · the index of the first predicate matching the current token, or -1 if
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as FileSystem from "fs";
|
|
2
|
+
import * as Paths from "path";
|
|
3
|
+
import { rewritePathForRendering } from "./io.js";
|
|
3
4
|
|
|
4
5
|
export function initializeProject(rootDir: string): void {
|
|
5
|
-
const skirYmlPath =
|
|
6
|
+
const skirYmlPath = Paths.join(rootDir, "skir.yml");
|
|
6
7
|
|
|
7
8
|
// Check if skir.yml already exists
|
|
8
|
-
if (
|
|
9
|
+
if (FileSystem.existsSync(skirYmlPath)) {
|
|
9
10
|
console.log(
|
|
10
11
|
"A skir.yml file already exists in this directory. Skipping project initialization.",
|
|
11
12
|
);
|
|
@@ -13,28 +14,109 @@ export function initializeProject(rootDir: string): void {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
// Create skir.yml file
|
|
16
|
-
|
|
17
|
+
FileSystem.writeFileSync(skirYmlPath, SKIR_YML_CONTENT, "utf-8");
|
|
17
18
|
|
|
18
19
|
// Check if skir-src directory exists
|
|
19
|
-
const skirSrcDir =
|
|
20
|
-
if (!
|
|
20
|
+
const skirSrcDir = Paths.join(rootDir, "skir-src");
|
|
21
|
+
if (!FileSystem.existsSync(skirSrcDir)) {
|
|
21
22
|
// Create skir-src directory
|
|
22
|
-
|
|
23
|
+
FileSystem.mkdirSync(skirSrcDir, { recursive: true });
|
|
23
24
|
|
|
24
25
|
// Create hello_world.skir file
|
|
25
|
-
const helloWorldPath =
|
|
26
|
-
|
|
26
|
+
const helloWorldPath = Paths.join(skirSrcDir, "hello_world.skir");
|
|
27
|
+
FileSystem.writeFileSync(helloWorldPath, HELLO_WORLD_SKIR_CONTENT, "utf-8");
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
console.log(`Done. Please edit: ${
|
|
30
|
+
console.log(`Done. Please edit: ${rewritePathForRendering(skirYmlPath)}`);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
const SKIR_YML_CONTENT =
|
|
33
|
+
const SKIR_YML_CONTENT = `# Configuration file for Skir code generator
|
|
34
|
+
#
|
|
35
|
+
# Documentation: https://skir.build/
|
|
36
|
+
#
|
|
37
|
+
# Cheat sheet:
|
|
38
|
+
# npx skir gen Generate code from .skir files
|
|
39
|
+
# npx skir gen --watch Watch for changes and regenerate automatically
|
|
40
|
+
# npx skir format Format all .skir files
|
|
41
|
+
# npx skir snapshot Take a snapshot of the source directory, verify no
|
|
42
|
+
# breaking changes since last snapshot
|
|
33
43
|
|
|
44
|
+
# Directory containing .skir files
|
|
45
|
+
srcDir: skir-src
|
|
46
|
+
|
|
47
|
+
# Uncomment and configure the generators for your target language(s).
|
|
34
48
|
generators:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
# # --------------------------------------------------------------------------
|
|
50
|
+
# # C++ code generator
|
|
51
|
+
# # Home: https://github.com/gepheum/skir-cc-gen
|
|
52
|
+
# # To install runtime dependencies, follow instructions in repository README
|
|
53
|
+
# # --------------------------------------------------------------------------
|
|
54
|
+
# - mod: skir-cc-gen
|
|
55
|
+
# outDir: ./skirout
|
|
56
|
+
# config:
|
|
57
|
+
# # Set to true if you use GoogleTest
|
|
58
|
+
# writeGoogleTestHeaders: false
|
|
59
|
+
|
|
60
|
+
# # --------------------------------------------------------------------------
|
|
61
|
+
# # Dart code generator
|
|
62
|
+
# # Home: https://github.com/gepheum/skir-dart-gen
|
|
63
|
+
# # To install runtime dependencies: dart pub add skir_client
|
|
64
|
+
# # --------------------------------------------------------------------------
|
|
65
|
+
# - mod: skir-dart-gen
|
|
66
|
+
# outDir: ./skirout
|
|
67
|
+
# config: {}
|
|
68
|
+
|
|
69
|
+
# # --------------------------------------------------------------------------
|
|
70
|
+
# # Java code generator
|
|
71
|
+
# # Home: https://github.com/gepheum/skir-java-gen
|
|
72
|
+
# # Add the following line to your build.gradle dependencies:
|
|
73
|
+
# # implementation("build.skir:skir-client:latest.release")
|
|
74
|
+
# # --------------------------------------------------------------------------
|
|
75
|
+
# - mod: skir-java-gen
|
|
76
|
+
# outDir: ./src/main/java/skirout
|
|
77
|
+
# config: {}
|
|
78
|
+
# # Alternatively:
|
|
79
|
+
# # outDir: ./src/main/java/skirout/my/project
|
|
80
|
+
# # config:
|
|
81
|
+
# # packagePrefix: "my.project."
|
|
82
|
+
|
|
83
|
+
# # --------------------------------------------------------------------------
|
|
84
|
+
# # Kotlin code generator
|
|
85
|
+
# # Home: https://github.com/gepheum/skir-kotlin-gen
|
|
86
|
+
# # Add the following line to your build.gradle dependencies:
|
|
87
|
+
# # implementation("build.skir:skir-client:latest.release")
|
|
88
|
+
# # --------------------------------------------------------------------------
|
|
89
|
+
# - mod: skir-kotlin-gen
|
|
90
|
+
# outDir: ./src/main/kotlin/skirout
|
|
91
|
+
# config: {}
|
|
92
|
+
# # Alternatively:
|
|
93
|
+
# # outDir: ./src/main/kotlin/skirout/my/project
|
|
94
|
+
# # config:
|
|
95
|
+
# # packagePrefix: "my.project."
|
|
96
|
+
|
|
97
|
+
# # --------------------------------------------------------------------------
|
|
98
|
+
# # Python code generator
|
|
99
|
+
# # Home: https://github.com/gepheum/skir-python-gen
|
|
100
|
+
# # To install runtime dependencies: pip install skir-client
|
|
101
|
+
# # --------------------------------------------------------------------------
|
|
102
|
+
# - mod: skir-python-gen
|
|
103
|
+
# outDir: ./skirout
|
|
104
|
+
# config: {}
|
|
105
|
+
# # Alternatively:
|
|
106
|
+
# # outDir: ./my/project/skirout
|
|
107
|
+
# # config:
|
|
108
|
+
# # packagePrefix: "my.project."
|
|
109
|
+
|
|
110
|
+
# # --------------------------------------------------------------------------
|
|
111
|
+
# # TypeScript/JavaScript code generator
|
|
112
|
+
# # Home: https://github.com/gepheum/skir-typescript-gen
|
|
113
|
+
# # To install runtime dependencies: npm i skir-client
|
|
114
|
+
# # --------------------------------------------------------------------------
|
|
115
|
+
# - mod: skir-typescript-gen
|
|
116
|
+
# outDir: ./src/skirout
|
|
117
|
+
# config:
|
|
118
|
+
# # Use ".js" for ES modules, "" for CommonJS
|
|
119
|
+
# importPathExtension: ".js"
|
|
38
120
|
`;
|
|
39
121
|
|
|
40
122
|
const HELLO_WORLD_SKIR_CONTENT = `/// A point in 2D space.
|
package/src/tokenizer.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unquoteAndUnescape,
|
|
3
3
|
type CodeLine,
|
|
4
|
+
type Doc,
|
|
4
5
|
type ErrorSink,
|
|
5
6
|
type Result,
|
|
6
7
|
type SkirError,
|
|
7
8
|
type Token,
|
|
8
9
|
} from "skir-internal";
|
|
10
|
+
import { parseDocComment } from "./doc_comment_parser.js";
|
|
9
11
|
|
|
10
12
|
export interface ModuleTokens {
|
|
11
|
-
|
|
13
|
+
/** Includes regular comments and doc comments. */
|
|
12
14
|
readonly tokens: readonly Token[];
|
|
13
|
-
|
|
15
|
+
/** Includes both kinds of comments. */
|
|
14
16
|
readonly tokensWithComments: readonly Token[];
|
|
17
|
+
/** Maps the start position of a doc comment (///) to the parsed documentation. */
|
|
18
|
+
readonly posToDoc: Readonly<{
|
|
19
|
+
[pos: number]: Doc;
|
|
20
|
+
}>;
|
|
15
21
|
readonly sourceCode: string;
|
|
16
22
|
readonly modulePath: string;
|
|
17
23
|
}
|
|
@@ -133,10 +139,22 @@ export function tokenizeModule(
|
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
|
|
142
|
+
// Parse the doc comments.
|
|
143
|
+
const posToDoc: { [pos: number]: Doc } = {};
|
|
144
|
+
for (const token of tokens) {
|
|
145
|
+
if (!token.text.startsWith("///")) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const docResult = parseDocComment(token);
|
|
149
|
+
posToDoc[token.position] = docResult.result;
|
|
150
|
+
docResult.errors.forEach((e) => errors.push(e));
|
|
151
|
+
}
|
|
152
|
+
|
|
136
153
|
return {
|
|
137
154
|
result: {
|
|
138
155
|
tokens: tokens.filter((t) => !isRegularComment(t.originalText)),
|
|
139
156
|
tokensWithComments: tokens,
|
|
157
|
+
posToDoc: posToDoc,
|
|
140
158
|
sourceCode: sourceCode,
|
|
141
159
|
modulePath: modulePath,
|
|
142
160
|
},
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare class LanguageServerModuleSet {
|
|
2
|
-
private readonly rootPath;
|
|
3
|
-
constructor(rootPath: string);
|
|
4
|
-
setFileContent(uri: string, content: string): void;
|
|
5
|
-
deleteFile(uri: string): void;
|
|
6
|
-
private reassignModulesToWorkspaces;
|
|
7
|
-
private parseSkirConfig;
|
|
8
|
-
private parseSkirModule;
|
|
9
|
-
/** Finds the workspace which contains the given module URI. */
|
|
10
|
-
private findModuleWorkspace;
|
|
11
|
-
private reassigneModulesTimeout?;
|
|
12
|
-
private readonly moduleBundles;
|
|
13
|
-
private readonly workspaces;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=language_server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"language_server.d.ts","sourceRoot":"","sources":["../src/language_server.ts"],"names":[],"mappings":"AAeA,qBAAa,uBAAuB;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM;IAE7C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IA2BlD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAuB7B,OAAO,CAAC,2BAA2B;IAoBnC,OAAO,CAAC,eAAe;IAwBvB,OAAO,CAAC,eAAe;IAmBvB,+DAA+D;IAC/D,OAAO,CAAC,mBAAmB;IA8B3B,OAAO,CAAC,uBAAuB,CAAC,CAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAmC;IACjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;CAC5D"}
|