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!(),
    };
}

Implementations§

source§

impl<'a> Lex<'a>

source

pub fn create_with( opt_ary: &'a [Opt<'_>], sho_idx_ary: &'a [(u8, usize)] ) -> Lex<'a>

create lexical analyzer

source

pub fn subcmd(self, subcmd_ary: &'a [&'a str]) -> Self

setup subcommand ary

source

pub fn tokens_from(&'a self, args: &'a [&'a str]) -> Result<Tokens<'a>, OpErr>

analyze and return tokens

Trait Implementations§

source§

impl<'a> Debug for Lex<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Lex<'a>

§

impl<'a> Send for Lex<'a>

§

impl<'a> Sync for Lex<'a>

§

impl<'a> Unpin for Lex<'a>

§

impl<'a> UnwindSafe for Lex<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.