# LLOne

Llone is a simple, single token lookahead, imperative parser library.
It is built to work closely with `Iterator` and `Result`.
Errors are assumed to be recoverable (when requested) if no tokens have been taken.

## Example

```rs
use llone::*;

fn calculate<'tok>(tokens: &mut Tokens<std::vec::IntoIter<&'tok str>>) -> Result<usize, &'static str> {
    tokens.scry::<_, for<'a> fn(_, &'a mut _) -> _>(|tok| match *tok {
        "(" => Some(|_, tokens| {
            let n = tokens.scry::<_, for<'a> fn(_, &'a mut _) -> _>(|tok| match *tok {
                "*" => Some(|_, tokens| Ok(list(calculate)(tokens)?.into_iter().product())),
                "+" => Some(|_, tokens| Ok(list(calculate)(tokens)?.into_iter().sum())),
                _ => None
            }).ok_or("expected operator").flatten()?;
            some_token(tokens, "expected ending bracket", |tok| (*tok == ")").then_some(()))?;
            Ok(n)
        }),
        tok if tok.chars().all(char::is_numeric) => Some(|tok, _|
            tok.parse::<usize>().map_err(|_| "malformed number")
        ),
        _ => None
    }).ok_or("expected expression").flatten()
}
```

## A Note on Rust Lambdas

Rust will (as of edition 2024) **not** infer your lambdas to have lifetime polymorphic types when it is possible for them to be generic over lifetimes.
Common workarounds include:
- Explicitly typing involved references in lambda arguments `|x: &T|`.
- Explicitly typing with a polymorphic type `for<'a> fn(&'a _) -> _`.

The example makes use of the latter to guide the compiler.

Additionally as of right now rust does not support automatic unification of lambda types using enums, hopefully this can one day be a feature, but for now when it comes to branching with `scry` your options are `fn` or `Box<dyn ...>`.
