-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Expose clap_lex #3635
Merged
Merged
feat: Expose clap_lex #3635
Conversation
This file contains 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
Before, we had a generic `next` that provided the next item and peeked at all remaining items. This was to work around the borrow checker for modifying the position while accessing args. We've now split `Input` into `RawArgs` and `ArgsCursor` so we don't have overlapping borrows. This made it so we can split `next` into `next`, `peek`, and `remaining`.
Since we'll need `skip`, it made me wonder how to name `skip` and `previous` to fit together, so I decided to play with `seek`. Its probably over kill but wondering if its better.
The lexer will soon return `RawOsStr` and it'll cost to turn that into an `OsStr`. However, it caches a `str`, so let's just use that.
In considering the design for this, we want: - Ability to modify the argment list while maintaining the `Cursor` for replacements - Allow picking up subcommand parsing in the middle of short flags - Ability to peek at the next item to determine if we want to treat it as a flag or as a value - Ability to detect started short and long arguments for completions Longer term, we also want to consider: - Allowing users to customize the lexer to support different syntaxes
While figuring out the API, `clap_lex` was tested by clap's tests. Now we are focusing on its API directly.
This tempts me to drop our design philosophy but I want to give it more time.
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.
This splits out a
clap_lex
, somewhat inspired bylexopt
. The main difference is thatlexopt
manages all state in one object while we have to split out the state to support:This was also done with an eye towards rust-driven completions. This will let the completion engine reuse the same lexer. The parsers will be different for now but as we learn more about a completion parser, we can look to see if and how we can use the same parser between the two. One side effect of this is that we treat
--
as potentially a long and-
as potentially a short. The problem with this approach is we aren't treating-
as a long as well because there is nothing good for us to return. We might need to reconsider that approach due to the inconsistency.Benefits of factoring out
clap_lex
:Deferred:
---long
) #3309, Support non-Unix options (e.g. find -exec, bash +O shopt, cmd.exe /c, gcc -Wl,) #2468: Ideally we simplify things down to support aBox<dyn Lexer>
which will require some work redesigning the API to take this into accountFixes #2915