I am facing an issue when using nom, and nom_locate, I am trying to use the many0 from nom, but the input type that it takes in &[u8] where as I had created a custom struct for tokens and spans for nom_locate, and this is my code for the token struct
#[derive(Debug, Clone, PartialEq)]
pub struct Token<'a> {
pub token_type: TokenType<'a>,
pub span: Span<'a>,
}
pub type Span<'a> = LocatedSpan<&'a str>;
#[derive(Debug, Clone, PartialEq)]
pub enum TokenType<'a> {
// Keywords
KeywordClass,
KeywordImplements,
KeywordNamespace,
KeywordThis,
KeywordCtx,
Identifier(&'a str),
}
How can I implement Input trait from nom for this issue? Or should I be even trying this? Is there an alternative??
fn parse_relation_block<'a>(input: &'a [Token<'a>]) -> ParseResult<'a, Vec<Relation<'a>>> {
// Expect "related: {"
let (input, _) = expect_token_with_value(TokenType::Identifier("related")).parse(input)?;
let (input, _) = expect_token(TokenType::OperatorColon).parse(input)?;
let (input, _) = expect_token(TokenType::BraceLeft).parse(input)?;
// Parse relation entries
let (input, relations_opt) = many0(alt((
map(parse_relation_entry, Some),
map(expect_token(TokenType::Semicolon), |_| None),
)))
.parse(input)?;
let (input, _) = expect_token(TokenType::BraceRight).parse(input)?;
//
// // Filter out None values (from semicolons)
let relations = relations_opt.into_iter().flatten().collect();
//
Ok((input, relations))
}