Skip to content

Petitparser Prototype (DO NOT MERGE)#50

Draft
cesarParra wants to merge 9 commits into
mainfrom
petitparser
Draft

Petitparser Prototype (DO NOT MERGE)#50
cesarParra wants to merge 9 commits into
mainfrom
petitparser

Conversation

@cesarParra

Copy link
Copy Markdown
Owner

No description provided.

cesarParra and others added 9 commits July 3, 2026 15:33
All 279 tests pass. The doc-comment grammar is line-oriented (description +
@tag block tags) with @ protected inside backticks/inline-tags/balanced braces
and {@hidden} regions dropped. sanitizeDocContent reused for normalisation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
All 279 tests pass. New parser extracts declaration structure (types, members,
modifiers, annotations, doc comments, signatures, type refs) and skips
method/constructor/trigger bodies as balanced blocks. Model objects built
directly via plain constructors, so the ANTLR-coupled TypeRefContext factory
and fromAnnotationContext (and the tests covering them) are untouched.

Known prototype gaps (not exercised by the repointed entry points): group
comments (@START-Group / // @START-Group), interface method coverage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fixes: preserve whitespace inside annotation string-literal values (ANTLR
concatenates tokens, strings are atomic); reproduce ANTLR array rawDeclaration
quirk. tool/diff/diff.dart runs a 49-case corpus through both parsers and
diffs the JSON output.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
petitparser composes the Apex and Apexdoc grammars over one character stream,
so each doc comment is now parsed eagerly during the Apex parse and attached
directly to the model — no lazy re-parse. Parsing runs in the per-declaration
builders (once, on the winning alternative), not in the backtracking _prefix
rule. A malformed doc is isolated into an error DocComment and never fails the
Apex parse. Output byte-identical: 279/279 tests, 49/49 differential parity.

Laziness dropped intentionally: JSON output serialises every docComment, so
all docs are parsed regardless.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The Apexdoc doc-comment parser is now a composable Parser<DocComment>
(ApexdocPpParser.wrapped) that matches the /** ... */ wrapper in-grammar and is
embedded directly in the Apex grammar's _prefix rule. Doc comments are parsed
from the source stream in the same parse as the declarations — the Apex parser
makes zero calls to a standalone doc parser.

To keep the composed doc parser running once per declaration, _prefix was
factored out of the member/type backtracking alternations and made
isMember-agnostic (raw modifier keywords, classified later), so one parsed
prefix serves both members and inner types. A cheap O(1) _docStart discriminator
replaces the full-scan block-comment guard. Malformed docs are isolated into an
error DocComment inside _content.

Byte-identical output: 279/279 tests, 49/49 differential parity with ANTLR.

Before this change: 6fa019c. See PETITPARSER_MIGRATION_LOG.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tool/benchmark/benchmark.dart compares both full pipelines (source to JSON) over
a real corpus (--dir). The ANTLR baseline is faithful: original ANTLR Apex
parser + original two-stage ANTLR Apexdoc parser (both still on this branch).

On a 2975-file Salesforce project: ~1.45x faster end to end, ~99.5% byte-
identical JSON, 1/2975 parse failures.

Fixes surfaced by running against real code (unit tests + 49-case differential
still green):
- inner virtual/abstract class modifier (isMember classification per site)
- generic collection literals in field initializers (~99 of 100 failures)
- space before type args in a type name
- unquoted annotation element values
- dotted generic type refs
- apexdoc: throws/param name split at NAME token, keyword prefix matching

See PETITPARSER_MIGRATION_LOG.md and tool/benchmark/README.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Orients a new agent: what the POC proved, benchmark + correctness results,
tradeoffs (win/lose), test-coverage gaps to fill in the real work, the path to
delete ANTLR, commit map, and reproduction commands.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant