Skip to content

parser: fix Base.parse and add errors and diagnostics - #1103

Merged
github-actions[bot] merged 1 commit into
ruby:mainfrom
apiology:parser-base-parse-errors
Oct 17, 2026
Merged

github-actions[bot] merged 1 commit into
ruby:mainfrom
apiology:parser-base-parse-errors

Conversation

@apiology

Copy link
Copy Markdown
Contributor

Claude: This PR was written by Claude Code on behalf of @apiology.

Problem:

Steep rejects documented parser calls:

# test.rb:79:29: [error] Type `::Parser::Base` does not have method `new`
parser = Parser::CurrentRuby.new

begin
  Parser::CurrentRuby.parse("foo(")
# test.rb:94:15: [error] Cannot find the declaration of constant: `SyntaxError`
rescue Parser::SyntaxError => error
  error.diagnostic
end

Code that builds its own parser, configures diagnostics or rescues syntax errors cannot be type-checked.

Solution:

Declare CurrentRuby as singleton(Parser::Base), make Base.parse/parse_with_comments class methods taking a String and the instance versions take a Source::Buffer, and add SyntaxError, UnknownEncodingInMagicComment, Diagnostic, Diagnostic::Engine, Base#diagnostics and Base#version, each matching parser v3.3.12.0.

Base#version is defined in each RubyNN parser, not in base.rb; Base#initialize calls it, so it is declared on Base.

Parser::Base.parse and parse_with_comments are class methods taking a
String; the instance methods take a Source::Buffer. CurrentRuby is a
class, so declare it as singleton(Parser::Base).

Add Parser::SyntaxError, UnknownEncodingInMagicComment, Diagnostic,
Diagnostic::Engine, Base#diagnostics and Base#version, checked against
parser v3.3.12.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GgkyXKEZWpEFXo6ceA5MSw
@apiology
apiology marked this pull request as ready for review October 16, 2026 22:12
@github-actions

Copy link
Copy Markdown

@apiology Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

parser

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@pocke, @kozy4324, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.

@kozy4324 kozy4324 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

APPROVE

@github-actions

Copy link
Copy Markdown

Thanks for your review, @kozy4324!

@apiology, @kozy4324 This PR is ready to be merged.
Just comment /merge to merge this PR.

@apiology

Copy link
Copy Markdown
Contributor Author

/merge

@github-actions
github-actions Bot merged commit 197dea4 into ruby:main Oct 17, 2026
8 checks passed
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.

2 participants