Skip to content

Parsing

Jonathan edited this page Oct 25, 2020 · 1 revision

Parsing in KWCommands is the first and most important step in Command Dispatch Process, the CommandParser takes the Command Line String and translates into a TokenList of Inputs, then based on this list, it tries to find command and argument combinations that matches the Inputs list.

Parsing FAQ

Could I write a parser extension so I could implement a different Input type?

Currently, no, maybe in the future? I'm not sure. KWCommands Parsing System was written in a way that minor changes would enable it to be extended, but I don't have plans to do so. Also this would make KWCommands have no standard way of writing command line string, but suggestions of new object formats to be integrated in KWCommands are welcome.

Could I change a SingleInput into a ListInput?

Input tokens does not change after parsed, and cannot be changed, but if you look into ListArgumentType, it takes a ListInput, but you could pass a sequence of SingleInput and it treats as ListInput, it happens because ListInput is treated specially, the parsing post-processing wraps SingleInput into ListInput when applicable, but it does not change the original stream of tokens, and it is not particularly for ListArgumentType, this applies to any ArgumentType that takes ListInput. This does not happens with Maps, they must have { and } enclosing them.

Could I parse and retrieve only Input token stream?

Without hacks, no, Input token stream is not currently exposed through API, you surely could access Input token, but only through ArgumentParser, and not the entire stream.