Closed kfsone closed 1 year ago
Could you make the grammar as small as possible, so that I can understand what you are mentioning? Thanks!
Grammar <- ( NAME CmdlineArg EOL )* EOI
%whitespace <- [ \t]*
%word <- [a-zA-Z][a-zA-Z0-9_.-]*
~EOL <- ('\r'? '\n')+
~EOI <- ! .
CmdlineArg <- CMDSWITCH ( '=' (STRING / CMDVALUE)? )?
NAME <- < [a-zA-Z_] [a-zA-Z0-9_]* >
STRING <- < '"' ( '\\' !('\r'? '\n') / '""' / [^"\\\r\n] )* '"' >
CMDSWITCH <- < '-' '-'? [a-zA-Z0-9_] [a-zA-Z0-9_.-]* >
CMDVALUE <- < ( '\\' [^\r\n] / [^ \t\r\n\\] )+ >
inputs, correct:
thing1 --switch
thing2 --switch=value
but it also incorrectly allows
thing3 --switch = something
And, demonstration that it currently parses the last, incorrectly:
One work around is to write a token.immediate to do this match, but because it can't use named patterns/named terminals, it results in duplication of grammar segments, and I really don't want to embed the string pattern multiple times -- STRING is used frequently in the real grammar.
As long as you use %whitespace
, there is no way to disallow spaces between tokens. Sorry...
Trying to capture command-line arguments as "switch and value" without allowing whitespace between the two parts.
The following grammar "works", but unfortunately allows spaces between CMDSWITCH and CMDVALUE.
Using '<' ... '>' in CmdArg results in it only producing a single value, however
Is there some way to both prevent whitespace AND still retain the split values?