Lexer and optional arguments
Richard Kimberly Heck
rikiheck at gmail.com
Sat Jan 21 07:15:21 UTC 2023
On 1/20/23 16:44, Daniel wrote:
> On 2022-04-18 19:46, Jean-Marc Lasgouttes wrote:
>> Le 18/03/2022 à 18:45, Daniel a écrit :
>>> Is it possible to have optional arguments read with Lexer? I imagine
>>> something like:
>>>
>>> Command <Parameter1> [<Parameter2>]
>>>
>>> So Parameter1 is necessary but Parameter2 is optional. The Lexer
>>> would only look on the same line for an optional parameter.
>> What is possible is to read one line with eatLine() and then parse
>> it, possibly with the lexer itself.
>
> Maybe someone can give me a hint on how to create a lexer from a
> string that I get via eatLine()?
The eatLine method simply loads the (rest of the) line into an internal
buffer. Then you use getString to get it as a string. E.g.:
lex.eatLine();
string const str = lex.getString();
Now you can do what you want with str. E.g., you can use the split
method from lstrings.h to split the string into pieces delimited by
whitespace, or whatever. Or you can use a regex to parse the string. Etc.
Actually, I wonder if this would work. After you get the required
parameter, call eatLine. This will return true if there's anything left,
I think. If so, then use getString to get it. If not, then there was no
second parameter.
Riki
More information about the lyx-devel
mailing list