Skip to content

List options - #29

Merged
streamich merged 3 commits into
masterfrom
list-options
Jun 7, 2026
Merged

streamich merged 3 commits into
masterfrom
list-options

Conversation

@streamich

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings June 7, 2026 12:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configurable list parsing options to the grammar/codegen so list nodes can express bounded repetition and optional separators, enabling more concise grammars for common “delimited list” patterns.

Changes:

  • Extend ListNode with min, max, and sep options.
  • Update list parser codegen to enforce min/max and optionally parse separators with backtracking for trailing delimiters.
  • Add unit tests covering min/max constraints, separator behavior, and grammar-level integration.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

File Description
src/types.ts Adds min, max, and sep fields to ListNode.
src/codegen/CodegenList.ts Implements min/max enforcement and optional separator parsing in generated list parsers.
src/codegen/CodegenGrammar.ts Wires ListNode.sep through to CodegenList so separators work in full grammars.
src/codegen/tests/CodegenList.spec.ts Adds tests for bounded lists, separators, backtracking, debug trace balancing, and AST behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const rChild = codegen.var();
const rChildren = codegen.var('[]');
const min = node.min ?? 0;
const max = node.max ?? 0;
Comment on lines +59 to +82
if (dSepParser) {
const rSep = codegen.var();
const rSepPos = codegen.var();
codegen.js(`${rChild} = ${dParser}(ctx, pos);`);
codegen.if(`${rChild} && ${rChild}.end !== pos`, () => {
codegen.js(`${rChildren}.push(${rChild});`);
codegen.js(`pos = ${rChild}.end;`);
codegen.js(`${rCount}++;`);
const maxCondition = max > 0 ? ` && ${rCount} < ${max}` : '';
codegen.while(`1${maxCondition}`, () => {
codegen.js(`${rSepPos} = pos;`);
codegen.js(`${rSep} = ${dSepParser}(ctx, pos);`);
codegen.js(`if (!${rSep} || ${rSep}.end === pos) break;`);
codegen.js(`pos = ${rSep}.end;`);
codegen.js(`${rChild} = ${dParser}(ctx, pos);`);
codegen.js(`if (!${rChild} || ${rChild}.end === pos) {`);
codegen.js(`pos = ${rSepPos}; break;`);
codegen.js(`}`);
codegen.js(`${rChildren}.push(${rSep}, ${rChild});`);
codegen.js(`pos = ${rChild}.end;`);
codegen.js(`${rCount}++;`);
});
});
} else {
Comment on lines +83 to +92
codegen.while(`${rChild} = ${dParser}(ctx, pos)`, () => {
codegen.js(`if (${rChild}.end === pos) break;`);
codegen.js(`${rChildren}.push(${rChild});`);
codegen.js(`pos = ${rChild}.end;`);
codegen.js(`${rCount}++;`);
if (max > 0) {
codegen.js(`if (${rCount} >= ${max}) break;`);
}
});
}
Comment on lines +127 to +128
});
});
@streamich
streamich merged commit 145aa06 into master Jun 7, 2026
2 checks passed
@streamich
streamich deleted the list-options branch June 7, 2026 13:00
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants