Generalize argument parsing for vimtex#cmd#get functions #2197
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.
vimtex#cmd#get*()
is a family of commands to parse a LaTeX command. The parser is generic and greedy, and it does not guarantee that it parses the "right amount". As it stands, the matching is not good enough, because it is restricted to the following pattern\cmd[...]*{...}*
.This PR changes the parsing to allow the following pattern:
\cmd\([...]\|{...}\|(...)\|<...>\)*
. This will for instance allow commands such as\begin{textblock*}{3in}[0,0](3in,1in)
to be parsed as a single command with 4 different types of arguments. Also, it will allow to parse constructs such as\test{arg}[opt]
.Further, the current matching only "gobbles" the arguments when they follow directly. That is, there is no tolerance for white space or "commented new lines". That is, the following LaTeX snippets are equivalent, but only the first of them is currently properly parsed:
It could be of interest to also relax the current "no whitespace" restriction.
Opinions? @clason @reportaman