zgclp

Zgclp (Zero-grammar definition command-line parser) is one of Rust's command-line parsers. A normal command-line parser generates a parser from the definition of command-line options that accepts a command line according to its grammar. In contrast, zgclp uses a universal parser to discover what it assumes to be options or arguments from the given command line arguments.

How it works?

Try a sample program by cargo run with something like a command line including options and arguments.

sh $ cargo run foo -bar bal --bra boo Argument "foo" . Option "-b" with argument "ar" . Argument "bal" . Option "--bra" with argument "boo" .

Format of options accepted by zgclp

When you write a single letter of the alphabet as A, B, etc., zgclp accepts the following options.

| Format | Parsed | | --------- | ------------------------------------- | | -A | Option with no argument -A. | | -A BC | Option -A with argument BC. | | -ABC | Option -A with argument BC. | | --AB | Option with no arguments --AB. | | --AB CD | Option --AB with the argument CD. | | --AB=CD | Option --AB with argument CD. | | -- | Separator. |

"But isn't that ambiguous?" If you are wondering, you are correct.

When the command line is

-a bc

zgclp will output the following two interpretations.

How do I use zgclp?

Short Answer:

Copy the boilerplate code examples/zgclp_boilerplate.rs as your main.rs and modify it.

Long Answer:

  1. Call the function arg_parse, giving the command line arguments as an array of strings (&[&str]) and the starting position of parsing.

  2. The return value is a tuple with three values.

If you want to let zgclp to collect (normal) command-line arguments, you can use arg_parse_a (instead of arg_parse) with passing a vector to store the arguments.

See a sample code src/main.rs or a boilerplate examples/zgclp_boilerplate.rs.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Links