-
Notifications
You must be signed in to change notification settings - Fork 0
[modular] Pull out a clap_lex #228
Comments
Comment by pksunkara I agree with the author of From all the examples of clap usage I have seen for the past 2 years, I am confident that we need to keep this as a PEG parser. We can make this PEG parser modular by implementing the plugins proposal in #2832. I would nominate to close this issue (take your time to do research/experimentation) if needed. |
Comment by epage
The
kbnapp also thought it was possible
Could you give a concrete example of why
A future experiment I want to do is something like In general, I would like to raise the bar for all of these non-clap parsers so we can have discussions beyond "does it support non-utf8?" :) These are what I would like to see unlocked by decoupling our lowest level parsing logic from all of the clap's policy. clap-rs/clap#2832 is insufficient for this. I'm also hopeful this will help us reduce bloat, directly and indirectly by
|
Comment by pksunkara I think a simple example here would be |
Comment by epage I get the feeling you are thinking we'd have a signature like pub fn lex(args: &[OsString) -> Vec<Token>; Is that correct? If so, then maybe we aren't using terms correctly but that isn't what
This leaves it to the caller to handle what |
Comment by pksunkara I understand what you are saying now. Let's agree to not call this Once this is implemented, do you envision this to be used by the plugins? |
Comment by epage
So far I've seen little confusion over
I've not seen a case where a plugin would have access to this. The benefits I see to this work are
|
Comment by blyxxyz
It seems you could end up with something tightly coupled to clap if it needs to know about settings like Clap is large and ambitious. If some third-party generic basis already existed then I wouldn't expect clap to use it because it's working at a scale where a bespoke solution is worth the effort. It's like how rustc and GCC use handwritten parsers instead of parser generators. A basis shared by multiple parsers could be a good idea, but I would guess that extracting it from clap isn't the way to go. (Then again, I know almost nothing about clap's internals.) |
Comment by epage My hope is that it doesn't need to know about any settings like that, those would all be driven by the caller. The main risk is that this doesn't simplify our code but makes it more complicated. If it doesn't work then we've learned something. |
Comment by pksunkara
It was more of a general idea, but that library is not lexer. A better name would be
And I envision that the callers here will be plugins. |
Comment by epage
I'm not aware of this fitting in with any of our existing plugin talk (value validation currently being the most concrete). |
Comment by pksunkara We discussed that in clap-rs/clap#2832 (comment). |
Comment by epage
There was not enough detail on that for me to know what its referring to or how it ties into this
All it does is tokenization. All of the policy of how to parse those tokens is up to the caller. That sounds closer to a lexer in name than anything else and calling it a parser would be overselling it. Also, the term "parser" is being used in so many places in clap in different ways, its good for us to look for more specific terms. |
Comment by pksunkara
But we are not planning to do tokenization. We are planning to let them read the items one by one without us categorizing them. That's it. And that's called a parse stream IIUC. Ex: Lexopt does actually categorize those args (and thus tokenize) but as @blyxxyz pointed out, it doesn't handle the corner cases that clap does. |
Comment by epage At least from my searching,
I see what we create being relatively similar to |
Comment by pksunkara
I am not sure how that would work with those corner cases (ex: negative values, multiple values) since we definitely need to leave up the categorization to individual parsers. But I guess it's a design for later. I realise that we are just bikeshedding on the name of this module at this point. But yeah, I felt that the term |
Issue by epage
Tuesday Oct 19, 2021 at 15:42 GMT
Originally opened as clap-rs/clap#2915
Please complete the following tasks
Clap Version
master
Describe your use case
We are looking to modular clap
As previously discussed at clap-rs/clap#2615, one part of this would be pulling out a
clap_lex
crate, similar tolexopt
.Describe the solution you'd like
Clap is a wrapper around
clap_lex
Alternatives, if applicable
Expand
lexopt
for our needs (probably easier to do an extraction refactor)Additional Context
No response
The text was updated successfully, but these errors were encountered: