-
Notifications
You must be signed in to change notification settings - Fork 81
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
Refactor and add tests for console command parsing #1459
Conversation
There's one (fairly trivial) conflict here, but this seems good to me from a quick skim over things |
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.
Looking forward to seeing this rebased so it can be merged
return begin; | ||
} | ||
|
||
std::pair<pfConsoleCmdGroup*, std::optional<ST::string>> pfConsoleParser::ParseGroupAndName() |
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.
Slight preference for this to be an std::tuple
because of std::pair
implying the usage of a map. But that's just a preference because a lot of implementations just have pair
use tuple
.
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.
Ah hm, is there a convention that std::pair
is specifically for map-related things? I assumed it was just a specialized alternative to a 2-element std::tuple
, but I don't know the stdlib too well...
(I'll get the rebase done this weekend probably) |
Although they share a bit of code, the core logic is quite different.
This code could only be reached when *line == '\0', so strlen(line) was always 0 and the addition did nothing.
This way the input buffer no longer needs to be modified, because the returned tokens are copied and not returned "in-place" from the buffer.
In preparation for refactoring and extending it into a more usable standalone parser.
This avoids having to pass a non-const reference into every call and allows signaling errors in a less dirty way.
Should now handle embedded zero bytes correctly (as if anyone cares...).
These have to be coupled, because command name parts can also be separated using spaces instead of dots/underscores.
Anything that needs possibly partial or ambiguous lookups (help, tab completion) still needs the complex API that parses "as far as possible".
02cee5b
to
9d5e3a1
Compare
Converts the very "old C-like" console command parsing code into its own class that has a bit more structure and uses modern C++ data types. Also, unit tests!
Aside from cleaning up the code, my motivation here is to allow parsing console commands without actually executing them. This would be especially useful for parsing .ini files - thinking of server.ini or cases like in #1244.
Suggestions for improving the parsing API are welcome. It has to be a bit complex unfortunately, to support situations where the input should only be partially parsed (e. g. tab completion), and because of the wacky command name syntax where parsing depends on which commands are defined...