Fix inconsistent unknown option parsing

- Fix an issue where unknown option is wrongly
  lexed as an argument if it's later than an known
  valid option.
- Essentially if `arg1` is only valid option
  `--arg1 value1 --arg2 value2` would not complain
  about `arg2`.
- Fixes #1120
This commit is contained in:
Janne Valkealahti
2024-08-19 17:40:52 +01:00
parent b09939856c
commit 7165e2d46d
4 changed files with 76 additions and 2 deletions

View File

@@ -222,7 +222,13 @@ public interface Lexer {
}
}
else if (isLastTokenOfType(tokenList, TokenType.ARGUMENT)) {
tokenList.add(Token.of(argument, TokenType.ARGUMENT, i2));
int decuceArgumentStyle = decuceArgumentStyle(argument);
if (decuceArgumentStyle < 0) {
tokenList.add(Token.of(argument, TokenType.ARGUMENT, i2));
}
else {
tokenList.add(Token.of(argument, TokenType.OPTION, i2));
}
}
}