Skip to content

Commit 5089ef7

Browse files
author
Dan Hudlow
authored
Fixes missing types in per-parse initializer non-zero repetitions (#1)
1 parent b044f4a commit 5089ef7

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ function toTypeScript(
3737
) {
3838
let rawSource: string | undefined;
3939

40+
let initializer = "";
41+
42+
if (Array.isArray(grammar.initializer)) {
43+
initializer = grammar.initializer.map((i) => i.code).join("\n");
44+
} else if (grammar.initializer?.code !== undefined) {
45+
initializer = grammar.initializer.code;
46+
}
47+
4048
if (grammar.location.source?.length === grammar.location.end.offset) {
4149
// probably the actual source for the grammar
4250
rawSource = grammar.location.source;
@@ -169,7 +177,7 @@ function toTypeScript(
169177
.map((r) => r.toDefinition())
170178
.join("\n"),
171179
this.name,
172-
getHeaderCode(),
180+
`${getHeaderCode()}\n${initializer}`,
173181
options.additionalFiles,
174182
),
175183
);
@@ -2430,7 +2438,7 @@ function toTypeScript(
24302438
}
24312439

24322440
const outerOptional =
2433-
typeof origin.max?.value !== "number" || origin.min?.value == 0;
2441+
typeof origin.min?.value !== "number" || origin.min?.value === 0;
24342442
const innerMin =
24352443
typeof origin.min?.value === "number" && origin.min.value > 0
24362444
? origin.min.value - 1
@@ -2847,14 +2855,6 @@ function toTypeScript(
28472855
const parser = new Parser(grammar);
28482856
const reusables = Reusable.getDirectory();
28492857

2850-
let initializer = "";
2851-
2852-
if (Array.isArray(grammar.initializer)) {
2853-
initializer = grammar.initializer.map((i) => i.code).join("\n");
2854-
} else if (grammar.initializer?.code !== undefined) {
2855-
initializer = grammar.initializer.code;
2856-
}
2857-
28582858
let code = `
28592859
${runtime}
28602860

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "peggy-ts",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "TypeScript plugin for Peggy parser generator",
55
"author": "Dan Hudlow",
66
"license": "Apache-2.0",

0 commit comments

Comments
 (0)