Sha256: 66230bacd8d36e1559f1dc919ae8eab3515963c4aef85a079ec56218c9a6e676

Contents?: true

Size: 771 Bytes

Versions: 38

Compression:

Stored size: 771 Bytes

Contents

#![allow(dead_code)]
// #![allow(unused_variables)]

use std::str;

use nom::bytes::complete::is_not;
use nom::character::complete::char;
use nom::combinator::{map, map_res};
use nom::multi::fold_many0;
use nom::sequence::delimited;
use nom::IResult;

fn atom<'a>(_tomb: &'a mut ()) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], String> {
  move |input| {
    map(
      map_res(is_not(" \t\r\n"), str::from_utf8),
      ToString::to_string,
    )(input)
  }
}

// FIXME: should we support the use case of borrowing data mutably in a parser?
fn list<'a>(i: &'a [u8], tomb: &'a mut ()) -> IResult<&'a [u8], String> {
  delimited(
    char('('),
    fold_many0(atom(tomb), String::new, |acc: String, next: String| {
      acc + next.as_str()
    }),
    char(')'),
  )(i)
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-28.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-27.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-26.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-25.0.2 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-25.0.1 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-25.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-24.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-23.0.2 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-22.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-21.0.1 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-20.0.2 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-20.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-18.0.3 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-17.0.1 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-17.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-16.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-15.0.1 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-15.0.0 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs
wasmtime-14.0.4 ./ext/cargo-vendor/nom-7.1.3/tests/reborrow_fold.rs