DRY parser impls

[?]
Jan 13, 2021, 4:02 AM
XZ6Z2D6H7NPJASKMEWI7H6ALRJBH3GHFNHL67PAXQZM3N36W554AC

Dependencies

  • [2] RTDVYLFT Give gemtext parser a more uniform interface wrt other parsers
  • [3] JBZGFYVO Add nom parsers for main types
  • [4] BOFUYB6I Add documentation and implement some feedback from Discord (https://discord.com/channels/273534239310479360/354038657075904544/796256815024701480)
  • [*] 5II6T7YE Add gemini library

Change contents

  • replacement in gemini/src/lib.rs at line 30
    [3.2165][3.2165:2202]()
    use nom::{error::Error, Finish};
    [3.2165]
    [3.2202]
    use nom::{error::Error, Finish, IResult};
  • edit in gemini/src/lib.rs at line 34
    [2.61]
    [3.2277]
    fn handle<I: ToOwned + ?Sized, O>(res: IResult<&I, O>) -> Result<O, Error<I::Owned>> {
    match res.finish() {
    Ok((_, res)) => Ok(res),
    Err(Error { input, code }) => Err({
    let input = input.to_owned();
    Error { input, code }
    }),
    }
    }
  • replacement in gemini/src/lib.rs at line 55
    [3.2647][3.2647:3005]()
    match $name::parse::$name(bytes).finish() {
    Ok((_, res)) => Ok(res),
    Err(Error { input, code }) => Err({
    let input = input.to_owned();
    Error { input, code }
    })
    }
    [3.2647]
    [3.3005]
    handle($name::parse::$name(bytes))
  • replacement in gemini/src/lib.rs at line 76
    [2.357][2.357:606]()
    match gemtext::parse::document(input).finish() {
    Ok((_, b)) => Ok(b),
    Err(Error { input, code }) => Err({
    let input = input.to_string();
    Error { input, code }
    }),
    }
    [2.357]
    [2.606]
    handle(gemtext::parse::document(input))