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.
This is a PR intended for discussion.
I want a token list.
I am implementing a RuboCop extension for RBS. In RuboCop, indentation and spacing are adjusted based on the positions of various tokens such as comments and
(
.Problem
If I try to create these features from the results of
RBS::Parser
, I have to implement complex processing. This includes searching for token positions fromRBS::Location
objects and finding the position information of end-of-line comments from all locations.Example 1: Search space in block.
Example 2: Search space between any token.
I understand that my use case is unique, so I believe there is little need to modify the existing parsing process.
It would be helpful to have a method to obtain a sequence of tokens as a new API.
Use case of token list in RuboCop
https://github.com/rubocop/rubocop/blob/12fd014e255617a08b7b42aa5df0745e7382af88/lib/rubocop/cop/layout/extra_spacing.rb
Proposal for token list API
Low level
I propose a low-level API called
RBS::Parser#_lex
, following the example of_parse_signature
and similar methods. This low-level API aims to obtain the necessary information for a sequence of tokens using minimal C code.It is desirable to be able to obtain all tokens, including comments.
High level
I propose a high-level API called
RBS::Parser#lex
. The namelex
is inspired byPrism#lex
. This high-level API will wrap the sequence of tokens obtained from_lex
, making it more convenient to handle.