Skip to content

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Jul 7, 2025

No description provided.

@soutaro soutaro added this to the RBS 4.0 milestone Jul 7, 2025
@Morriar
Copy link
Contributor

Morriar commented Jul 7, 2025

We're getting more places where we specify what's allowed: allow_selfq, allow_eof, allow_void. Since we already pass the parser everywhere, I wonder if we should add these options as context rather than passing them individually to each method:

parser.context.allow_void

@soutaro
Copy link
Member Author

soutaro commented Jul 8, 2025

@Morriar I'd like to keep allow_void (and allow_selfq) as dedicated parameter. They are not part of the parser’s global state, but rather values that change frequently during parsing. So I don’t think it’s reasonable to write code that preserves and restores the context, like:

parser_context old_context = parser.context;
parser.context.allow_void = true;

parse_type(parser);

parser.context = old_context;

I’m planning to introduce two more flags for parsing self and class/instance types (#2336). These flags are static during parsing, so I agree that making them attributes of the parser makes sense.

@soutaro soutaro force-pushed the type-syntax-error branch 2 times, most recently from 6c54a47 to 9f8a133 Compare July 8, 2025 07:02
@soutaro
Copy link
Member Author

soutaro commented Jul 9, 2025

These flags are static during parsing

Oops — they are constant while parsing a type, but they can change when parsing an entire signature.

@@ -85,6 +85,7 @@ struct parse_type_arg {
rb_encoding *encoding;
rbs_parser_t *parser;
VALUE require_eof;
VALUE void_allowed;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The parse_type_arg is also used for parse_method_type and parse_signature.

Regarding the name allow_void, it is appropriate for type parsing, but for signature parsing, I think there is a possibility that it could be interpreted as allowing or disallowing all uses of void, regardless of the context in which it is used.

For example, looks disallowed to me.

RBS::Parser.parse_method_type("() -> void", allow_void: false)

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes sense. I added two more arg types, parse_method_type_arg and parse_signature_arg, and use them for parse_method_type and parse_signature.

The two structs are identical currently, but a few attributes will be added to parse_method_type_arg to support options for self/instance/class type parsing.

@soutaro soutaro marked this pull request as ready for review July 23, 2025 04:33
@soutaro soutaro added this pull request to the merge queue Jul 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 23, 2025
@soutaro soutaro force-pushed the type-syntax-error branch from 7e79fc4 to 6130ccf Compare July 24, 2025 02:10
@soutaro soutaro enabled auto-merge July 24, 2025 02:10
The `parse_type_list_with_commas` function was added after the first implementation of this PR.
@soutaro soutaro added this pull request to the merge queue Jul 24, 2025
Merged via the queue into master with commit 1940626 Jul 24, 2025
22 checks passed
@soutaro soutaro deleted the type-syntax-error branch July 24, 2025 03:02
ksss added a commit to ksss/rbs that referenced this pull request Jul 27, 2025
ksss added a commit to ksss/rbs that referenced this pull request Jul 27, 2025
ksss added a commit to ksss/rbs that referenced this pull request Jul 28, 2025
ksss added a commit to ksss/rbs that referenced this pull request Aug 1, 2025
ksss added a commit to ksss/rbs that referenced this pull request Aug 1, 2025
ksss added a commit to ksss/rbs that referenced this pull request Aug 8, 2025
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.

3 participants