-
Notifications
You must be signed in to change notification settings - Fork 188
Better argument parser #1425
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
base: master
Are you sure you want to change the base?
Better argument parser #1425
Conversation
|
|
Is this is still relevant? It seems like you removed the callbacks already. |
|
Oh right now I see it, I was only looking at the reference implementation so far. |
|
Yee sorry I figured I will just remove and restore it if requested since it wasn't really usable in form that was included. |
|
I also returned this PR to draft state because I figured I should also try how well autocompletion will fit into that design. |
src/argparse.zig
Outdated
| }, | ||
| success: SuccessT, | ||
|
|
||
| pub fn deinit(self: @This(), allocator: NeverFailingAllocator) void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this function does seem quite easy to miss. It seems you missed it in the reference implementation too.
Maybe a better pattern would be to pass in the result message List. This would allow using regular errors, with their syntax sugar, as well as moving this up one layer into the command code, so we could do the error message handling there. Either way, that would be a bigger rewrite, and doesn't need to be done here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted (and fixed), but I don't fully understand the request unfortunately, I guess we will return to this topic. What I would like to preserve is the fact that this parser can be used both for commands and for CLI parameters for Cubyz executable if useful at some point.
|
Oh I see I didn't push the removal of the callback parameter, sorry for my confusion. |
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
I'd suggest Also if there is only one argument list, I'd suggest to only show the error message without all the extra information. |
|
Ewww being normal |
|
This kind of message with all the variants is only shown for unions, if there is only a struct with one set of arguments it will stop on first error and will report it. |
|
I would leave those, otherwise it is less readable, mind that adding a leading space will not work as good as in Github UI because chat is mach narrower and message is almost guaranteed to wrap. |
|
Okay, I applied the requests. I tried returning optional to indicate that it was not possible to parse the string, but that failed miserably, so now I am returning ParseError instead and it seems to work. |
|
Is this still active? |
|
It is waiting for review |
|
Closing until integrating such feature becomes a priority. |
To appease both parties, programmers and ""normal people"", we should follow the GulfOfMexico standard and start counting at -1 |
IntegratedQuantum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, one thing is for sure I don't have the time and patience to review a 500 line PR.
First up instead of using /tp, I'd suggest to use a simpler command such as /time for demonstration. /time is a lot simpler but still has enough cases to be interesting.
With that the biome code is no longer needed, and I think it should be added in a future PR instead.
| var split = std.mem.splitScalar(u8, args, ' '); | ||
|
|
||
| var tempErrorMessage: ListUnmanaged(u8) = .{}; | ||
| defer tempErrorMessage.deinit(allocator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All local allocations should use the stackAllocator
@codemob-dev we need the fix for #1286
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codemob-dev we need the fix for #1286
Not again...
|
|
||
| const Test = struct { | ||
| var testingAllocator = main.heap.ErrorHandlingAllocator.init(std.testing.allocator); | ||
| var allocator = testingAllocator.allocator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also not needed with #1286








Description
This pull request introduces prototype of declarative, fully comptime argument parser based on introspection. The goal is to use to declaratively describe command syntax and automatically provide autocompletion for each of declared segments.
/tpcommand has been migrated to Parser based design as proof of concept.Example
Declaration of parser for
/tpcommand:Links
Related to: #1380