Struct flood_tide::Lex
source · pub struct Lex<'a> { /* private fields */ }
Expand description
Lexical analyzer
this is analyzing command line arguments, returning tokens.
Examples
#[cfg(not(feature = "long_only"))]
#[cfg(feature = "option_argument")]
{
use flood_tide::{Arg, Lex, Opt, OptNum};
#[rustfmt::skip]
let args = ["-ab", "--barn", "--eat", "jum"];
#[rustfmt::skip]
#[repr(u8)]
#[derive(Debug, PartialEq)]
enum CmdOP { A = 1, Barn, Eat, };
impl CmdOP { pub const fn to(self) -> OptNum { self as OptNum } }
#[rustfmt::skip]
const OPT_ARY: [Opt;3] = [
Opt { sho: b'a', lon: "", has: Arg::No, num: CmdOP::A.to(), },
Opt { sho: b'b', lon: "barn", has: Arg::No, num: CmdOP::Barn.to(), },
Opt { sho: 0u8, lon: "eat", has: Arg::Yes, num: CmdOP::Eat.to(), },
];
#[rustfmt::skip]
const OPT_ARY_SHO_IDX: [(u8,usize);2] = [(b'a',0),(b'b',1)];
let lex = Lex::create_with(&OPT_ARY, &OPT_ARY_SHO_IDX);
let tokens = match lex.tokens_from(&args) {
Ok(t) => t,
Err(e) => unreachable!(),
};
}