Repository navigation
Add singleton classes, paren-less command args, and panic hardening - #2
Merged
Merged
Conversation
Close the top three real-world front-end gaps measured against Rails and
Ruby's standard library.
P1 — singleton-class open form. `class << target; body; end` now parses to
a new ast.SingletonClassDef{Target, Body} instead of erroring. Covers the
idiomatic `class << self` class-method block as well as `class << obj` and
arbitrary expression targets.
P2 — paren-less command calls with arguments. parseCommandArgs now reuses
parseOneCallArg, so a command call accepts the same keyword/hash pairs
(`render json: x, status: :ok`), splats, double-splats, block-pass and
multiple positional arguments a parenthesized call does — as a statement and
as an assignment RHS (`x = foo a, b`). canStartCommandArg recognizes the
LABEL and hugging `*`/`**`/`&` starters. A trailing `do…end` now binds to
the command call (MRI precedence) while a braced block still binds to the
nearest call.
P3 — never-panic robustness. Parse converts any non-parseError internal
panic into a clean parse error instead of re-panicking, and negateLiteral
handles a BignumLit operand — fixing the runtime TypeAssertionError crash on
negative integer literals that overflow int64 (e.g.
-9999999999999999999999999999999), the root cause of every panic observed on
real Rails sources.
Measured parse-acceptance delta (full rails/ checkout, 3422 .rb files):
47.1% → 69.6% accepted, 5 panics → 0. Ruby stdlib: 49.4% → 55.9%.
100% statement coverage; go vet clean; CGO-free.
Co-Authored-By: Claude Opus 4.8 <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.
Closes the top three measured front-end gaps against Rails and Ruby's standard library.
P1 — singleton class (
class << self/class << expr)class << target; body; endnow parses to a newast.SingletonClassDef{Target, Body}instead of erroring with "singleton class … is not supported". Supports the idiomaticclass << selfclass-method block,class << objon a local, and arbitrary expression targets (class << obj.thing).MRI-verified repros now passing:
class << self; def x; 1; end; endo = Object.new; class << o; def y; 2; end; endP2 — paren-less command calls with arguments
parseCommandArgsnow reusesparseOneCallArg, so a command call accepts the same forms a parenthesized call does:delegate :a, :b, to: :c,validates :x, presence: true,render json: x, status: :okfoo a, b, c,puts x, yfoo *args,foo **opts,foo &blkhas_many :posts, -> { order(:id) }, dependent: :destroyx = foo a, bcanStartCommandArgrecognizes theLABELand hugging*/**/&starters. A trailingdo…endbinds to the command call (MRI precedence) while a braced{…}block still binds to the nearest call.P3 — never-panic robustness
Parseconverts any non-parseErrorinternal panic into a clean parse error instead of re-panicking.negateLiteralnow handles aBignumLitoperand. This fixes a realruntime.TypeAssertionErrorcrash on a negated integer literal that overflows int64 (e.g.-9999999999999999999999999999999) — the root cause of every panic observed on real Rails sources.Measured parse-acceptance delta
Full
rails/checkout (3422.rbfiles):Ruby stdlib (1511 files): 49.4% → 55.9%, 0 panics throughout.
Quality
go vet ./...clean, CGO-free, no byte-order/arch assumptions🤖 Generated with Claude Code