Zero-grammer definition command-line parser

Overview

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?

Do a cargo build and run target/debug/zgclp with something like command line arguments.

> target/debug/zgclp 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.

  • The option -a appears with no arguments (the next bc is a normal command line argument that has nothing to do with the option -a).
  • The option -a appears with the argument bc.

How do I use zgclp?

  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.

  • The first value indicates whether the result of the parse is an option or a normal argument, etc.
  • The second value indicates the increment to the next parse start position if the result is interpreted as an option with no arguments, otherwise None.
  • The third value is the increment to the next parsing start position and the argument string, if the parsing result is interpreted as an option with arguments. Otherwise, None.

See a sample code: src/main.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

You might also like...
Statically sized matrix using a definition with const generics

Statically sized matrix using a definition with const generics

Event-sourcing Schema Definition Language

ESDL Event-sourcing Schema Definition Language Schema definition language for defining aggregates, commands, events & custom types. Heavily inspired b

Interface definition generator and standard for Move packages.

Move IDL Interface definition generator and standard for Move packages. Documentation is currently extremely sparse but will be improved in the near f

Serde definition of Cargo.toml structure

Deserialize Cargo.toml This is a definition of fields in Cargo.toml files for serde. It allows reading of Cargo.toml data, and serializing it using TO

Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

RISC Zero is a zero-knowledge verifiable general computing platform based on zk-STARKs and the RISC-V microarchitecture.

RISC Zero WARNING: This software is still experimental, we do not recommend it for production use (see Security section). RISC Zero is a zero-knowledg

gRPC client/server for zero-knowledge proof authentication Chaum Pederson Zero-Knowledge Proof in Rust

gRPC client/server for zero-knowledge proof authentication Chaum Pederson Zero-Knowledge Proof in Rust. Chaum Pederson is a zero-knowledge proof proto

The Zero Knowledge Whitelist Tool is a powerful utility for managing an address whitelist using Zero-Knowledge (ZK) proofs.
The Zero Knowledge Whitelist Tool is a powerful utility for managing an address whitelist using Zero-Knowledge (ZK) proofs.

zk_whitelist: A Zero Knowledge Whitelist Tool The Zero Knowledge Whitelist Tool is a powerful utility for managing an address whitelist using Zero-Kno

A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

A fast, extensible, command-line arguments parser

parkour A fast, extensible, command-line arguments parser. Introduction 📚 The most popular argument parser, clap, allows you list all the possible ar

Minimalist pedantic command line parser

Lexopt Lexopt is an argument parser for Rust. It tries to have the simplest possible design that's still correct. It's so simple that it's a bit tedio

A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Simple command line flag parser for rust.

easy_flag Simple command line flag parser for rust. use easy_flag::FlagSet; fn main() - Result(), String{ let mut help = false; let mut my

A simple, lightweight and extensible command line argument parser for rust codebases

A simple, lightweight and extensible command line argument parser for rust codebases. This crate aims to provide you with an easy-to-use and extensibl

A zero-copy parser for the contents of the __unwind_info section of a mach-O binary.

A parser for Apple's Compact Unwinding Format, which is used in the __unwind_info section of mach-O binaries.

Parser and test runner for testing compatable common Ethereum full node tests against Polygon Zero's EVM.

EVM Test Parses and runs compatible common Ethereum tests from ethereum/tests against Polygon Zero's EVM. Note: This repo is currently very early in d

A minimal and fast zero-copy parser for the PE32+ file format.

peview A minimal and fast zero-copy parser for the PE32+ file format. Goal This project aims to offer a more light weight and easier to use alternativ

Yet Another Parser library for Rust. A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing strings and slices.

Yap: Yet another (rust) parsing library A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing input.

Owner
Toshihiro Kamiya
Toshihiro Kamiya
A command line tool for renaming your ipa files quickly and easily.

ipa_renamer A command line tool for renaming your ipa files quickly and easily. Usage ipa_renamer 0.0.1 A command line tool for renaming your ipa file

Noah Hsu 31 Dec 31, 2022
Neural network transition-based dependency parser (in Rust)

dpar Introduction dpar is a neural network transition-based dependency parser. The original Go version can be found in the oldgo branch. Dependencies

Daniël de Kok 41 Jan 25, 2022
A HDPSG-inspired symbolic natural language parser written in Rust

Treebender A symbolic natural language parsing library for Rust, inspired by HDPSG. What is this? This is a library for parsing natural or constructed

Theia Vogel 32 Dec 26, 2022
Makdown-like text parser.

Makdown-like text parser.

Ryo Nakamura 1 Dec 7, 2021
A WHATWG-compliant HTML5 tokenizer and tag soup parser

html5gum html5gum is a WHATWG-compliant HTML tokenizer. use std::fmt::Write; use html5gum::{Tokenizer, Token}; let html = "<title >hello world</tit

Markus Unterwaditzer 129 Dec 30, 2022
Find all your TODO notes with one command!

Todo_r Find all your notes with one command! Todo_r is a simple rust command line utility that keeps track of your todo items in code. It is pronounce

Lavi Blumberg 34 Apr 22, 2022
JiaShiwen 12 Nov 5, 2022
A position (finance) definition that has some good algebraic properties.

Positions A position (finance) definition with some good algebraic properties. API Docs Example Add positions as a dependency of your project. [depend

Nouzan 2 Nov 8, 2022
An experimental IPC interface definition language for Hubris.

Idol: interface definitions for Hubris This is an experimental interface definition language for defining IPC interfaces between tasks in a Hubris app

Oxide Computer Company 8 Oct 19, 2022
Dade is data definition for Rust structures.

dade dade is data definition for Rust structures. For the easy handle of data, the following will support it. Data validation. Data schema conforms Js

odd 3 May 1, 2022