docs: standalone runnable PoC of the grammar engine (#467)#489
Open
SJrX wants to merge 2 commits into
Open
Conversation
A single self-contained Kotlin file (stdlib only, no IntelliJ/project deps) under poc/ that models the new engine so it can be run and stepped through without Gradle: kotlin poc/GrammarEnginePoc.kt # or: kotlinc poc/GrammarEnginePoc.kt -include-runtime -d /tmp/poc.jar && java -jar /tmp/poc.jar # or: open in IntelliJ and Run main() Mirrors the real grammar/ classes (Parse/Stuck/Matcher, Seq/Alt/ZeroOrMore/ZeroOrOne, Lit/Choice/Whitespace, validate, nextTokenChoices) and main() demonstrates: the greedy completeness win, validation + error localization, completion as the same expected-set question, and the raw ParseStep stream you'd see in a debugger. Lives outside the source sets, so it is not compiled into the plugin. Refs #467 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Moved GrammarEnginePoc.kt to src/main/kotlin so IntelliJ runs main() directly, and
reworked it as a teaching aid (this branch is not merged/shipped):
- Seq.parse rewritten with the sequence { } builder (lazy, but plain for-loops + yield
instead of flatMap/map), with clearer names (waysToHere / soFar) and the snapshot
comment explaining why the lazy block must close over a captured value.
- Added eager List-based twins SeqEager / ZeroOrMoreEager that build the full result
up front (no laziness) to make the logic and the recursion easier to follow.
- Demos: eager vs lazy produce identical validate() results; and the eager twin builds
the whole ambiguous space (all 4 full parses of "aaa") where lazy validate stops at
the first.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A single self-contained Kotlin file —
poc/GrammarEnginePoc.kt— that models the new grammar engine with no IntelliJ or project dependencies (Kotlin stdlib only), so you can run it and step through it in a debugger without Gradle.Run it
What it shows
It mirrors the real
grammar/classes (Parse/Stuck/Matcher,Seq/Alt/ZeroOrMore/ZeroOrOne,Lit/Choice/Whitespace,validate,nextTokenChoices) andmain()walks through four demos:Seq(ZeroOrMore("a"), "a")accepts"aa"(the case a single greedy match fails).AF_BOGUS→SemanticError;AF_INET, AF_INET6→SyntaxError(furthest=7, expected=[<ws>]).nextTokenChoices("")/("~")/("AF_INET ")showing "what can come next" is the same expected-set question.ParseStepstream — what you'd actually see in a debugger.Sample output:
The header comment explains the two core ideas (list-of-successes; failure-as-a-value) and maps the PoC names back to the real classes.
Refs #467
🤖 Generated with Claude Code