The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Capture A Match That Is Not Followed By A Tag In Rust's nom

TODO: Pull subtitle into page object
Code
//! ```cargo
//! [dependencies]
//! nom = "7.1.3"
//! ```

use nom::bytes::complete::take_until;
use nom::error::Error;
use nom::error::ErrorKind;
use nom::Err;
use nom::IResult;
use nom::bytes::complete::is_not;
use nom::bytes::complete::tag;
use nom::combinator::not;
use nom::combinator::opt;

fn main() {
  assert_eq!(
    Ok((">", "alfa:bravo".to_string())), 
    bool_with_colon("alfa:bravo>")
  );

  assert_eq!(
    Err(Err::Error(Error::new(": echo", ErrorKind::Not))),
    bool_with_colon("delta: echo>")
  );

  println!("done");
}

fn bool_with_colon(source: &str) -> IResult<&str, String> {
  let (source, result) = is_not(">")(source)?;
  let (verify, _) = opt(take_until(":"))(result)?;
  let (_, _) = not(tag(": "))(verify)?;
  Ok((source, result.to_string()))
}
Results
done

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Capture A Match That Is Not Followed By A Tag In Rust's nom

The goal with this one is to looks for 
boolean attributes in Neopolitan that
include a colon in them. This is used for
things like URLs. 

The mechanic is that if there's a colon
without a space it's treated as an
attribute. If there is a space it 
throws an error (becuase it's a 
key value pair at that point)


-- code
-- rust

//! ```cargo
//! [dependencies]
//! nom = "7.1.3"
//! ```

use nom::bytes::complete::take_until;
use nom::error::Error;
use nom::error::ErrorKind;
use nom::Err;
use nom::IResult;
use nom::bytes::complete::is_not;
use nom::bytes::complete::tag;
use nom::combinator::not;
use nom::combinator::opt;

fn main() {
  assert_eq!(
    Ok((">", "alfa:bravo".to_string())), 
    bool_with_colon("alfa:bravo>")
  );

  assert_eq!(
    Err(Err::Error(Error::new(": echo", ErrorKind::Not))),
    bool_with_colon("delta: echo>")
  );

  println!("done");
}

fn bool_with_colon(source: &str) -> IResult<&str, String> {
  let (source, result) = is_not(">")(source)?;
  let (verify, _) = opt(take_until(":"))(result)?;
  let (_, _) = not(tag(": "))(verify)?;
  Ok((source, result.to_string()))
}

-- results/

done

-- /results


-- categories
-- Rust 
-- nom

-- metadata
-- date: 2024-01-08 04:49:41
-- id: 2afqvebx
-- type: post
-- status: published