Skip to content

Commit

Permalink
Fixes missing types in per-parse initializer non-zero repetitions (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hudlow authored Oct 21, 2024
1 parent b044f4a commit 5089ef7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ function toTypeScript(
) {
let rawSource: string | undefined;

let initializer = "";

if (Array.isArray(grammar.initializer)) {
initializer = grammar.initializer.map((i) => i.code).join("\n");
} else if (grammar.initializer?.code !== undefined) {
initializer = grammar.initializer.code;
}

if (grammar.location.source?.length === grammar.location.end.offset) {
// probably the actual source for the grammar
rawSource = grammar.location.source;
Expand Down Expand Up @@ -169,7 +177,7 @@ function toTypeScript(
.map((r) => r.toDefinition())
.join("\n"),
this.name,
getHeaderCode(),
`${getHeaderCode()}\n${initializer}`,
options.additionalFiles,
),
);
Expand Down Expand Up @@ -2430,7 +2438,7 @@ function toTypeScript(
}

const outerOptional =
typeof origin.max?.value !== "number" || origin.min?.value == 0;
typeof origin.min?.value !== "number" || origin.min?.value === 0;
const innerMin =
typeof origin.min?.value === "number" && origin.min.value > 0
? origin.min.value - 1
Expand Down Expand Up @@ -2847,14 +2855,6 @@ function toTypeScript(
const parser = new Parser(grammar);
const reusables = Reusable.getDirectory();

let initializer = "";

if (Array.isArray(grammar.initializer)) {
initializer = grammar.initializer.map((i) => i.code).join("\n");
} else if (grammar.initializer?.code !== undefined) {
initializer = grammar.initializer.code;
}

let code = `
${runtime}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "peggy-ts",
"version": "0.0.1",
"version": "0.0.2",
"description": "TypeScript plugin for Peggy parser generator",
"author": "Dan Hudlow",
"license": "Apache-2.0",
Expand Down

0 comments on commit 5089ef7

Please sign in to comment.