Questions tagged [nom]

Nom is a parser combinators library written in Rust.

Nom is a parser combinators library written in Rust. Its goal is to provide tools to build safe parsers without compromising the speed or memory consumption. To that end, it uses extensively Rust's strong typing, zero copy parsing, push streaming, pull streaming, and provides macros and traits to abstract most of the error prone plumbing.

128 questions
4
votes
3 answers

How to use nom take_while and is_digit for a &str input

I'm trying to learn nom and have a problem where take_while does not accept is_digit or any other is_xxxx. I have rows that I want to parse that looks like this #123 = ABCDEF (...); where I want to get the '123' part (and eventually the ABCDEF and…
mottosson
  • 3,283
  • 4
  • 35
  • 73
4
votes
3 answers

How to parse complete f32 with nom?

There is a function float_s that parses floats in stream mod (can return Incomplete). I want to use CompleteStr as input type instead. How I can achieve that? Simple approach fails with complains about &str and CompleteStr…
magras
  • 1,709
  • 21
  • 32
3
votes
2 answers

Nom parser fails to not consume invalid input

My test parse_line_repeat is crashing in the last line (which is invalid to such point) instead of returning it as a remainder as show in the test itself. I have tried using tuple instead of pair and many0 instead of many1, the first got solved by…
Delfin
  • 157
  • 7
3
votes
2 answers

Lifetime issue with nom_supreme tag parser in a closure

I'm using the nom parser to parse a language. On top of that I'm using nom_supreme for some quality of life improvements (e.g. error handling). It is going well, but I'm stuck on one puzzle which I'm hoping that someone can help me with. First for…
Sean Dawson
  • 5,587
  • 2
  • 27
  • 34
3
votes
1 answer

How to propagate Nom fail context out of many0?

I have a Nom parser that parses strings but fails on keywords. The parser below correctly fails when given a keyword. But the error message that says it failed because it encountered a keyword does not propagate. The problem is that while label…
sshine
  • 15,635
  • 1
  • 41
  • 66
3
votes
1 answer

How to have a separator in nom with an optional terminating separator?

I'd like to parse both of these with nom: [ a, b, c ] [ a, b, c, ] Currently I have this code which parses the first but not the second (the first function is a recipe from the nom docs which just parses whitespace): //…
Maximilian
  • 7,512
  • 3
  • 50
  • 63
3
votes
1 answer

How to use Rust nom to write a parser for this kind of structure text?

I have the following data let data = r#"title1 title1 line1 title1 line2 sep/ title2 title2 line1 title2 line2 title2 line3 sep/ title3 title3 line1 sep/"#; Basically it represents three entries: struct Entry { title: String, body:…
Just a learner
  • 26,690
  • 50
  • 155
  • 234
3
votes
1 answer

Cannot infer type for type parameter `I` declared on the function `tuple` when parsing with nom

I am trying to use nom's tuple function. The documentation presents the following example: use nom::sequence::tuple; use nom::character::complete::{alpha1, digit1}; let parser = tuple((alpha1, digit1, alpha1)); When I try it out, I get a compile…
WhiteStork
  • 385
  • 1
  • 15
3
votes
1 answer

How can I take N bits of byte in nom?

I am trying to write a HTTP2 parser with nom. I'm implementing the HPACK header compression, but having trouble understanding how to work with bit fields in nom. For example, the Indexed Header Field Representation starts with the first bit as 1. fn…
Hellstorm
  • 562
  • 4
  • 23
3
votes
2 answers

How to transform a u128 integer to an Uuid with nom

I have binary data packet with a UUID (16 bytes), a 1 byte type field and 4 bytes containing a float value. How to parse with nom and get as result a tuple (Uuid, u8, f32)? use nom::{ combinator::map_res, number::complete::le_f32,…
attdona
  • 17,196
  • 7
  • 49
  • 60
3
votes
2 answers

Parse multiline comment with nom

I'm trying to write a nom parser that recognizes multiline comments... /* yo! */ ...and consumes/discards (same thing, right?) the result: use nom::{ bytes::complete::{tag, take_until}, error::{ErrorKind, ParseError}, sequence::preceded, …
mottosson
  • 3,283
  • 4
  • 35
  • 73
3
votes
1 answer

Binary file parsing with nom 5.0

Problem There is a file that has multiple headers inside it, but to me, it only matters one and the data after it. This header repeats itself multiple times through the file. Its magic number is: A3046 in ASCII, or 0x65 0x51 0x48 0x54 0x52 in…
jimmy
  • 43
  • 1
  • 5
3
votes
2 answers

Catch string between tags with nom delimited

I'm trying to learn to use nom (5.0.1) and want to get the string between two tags: use nom::{ bytes::complete::{tag_no_case, take_while}, character::{is_alphanumeric}, error::{ParseError}, sequence::{delimited}, IResult, }; fn…
mottosson
  • 3,283
  • 4
  • 35
  • 73
3
votes
1 answer

Rust Nom: many and end of input

I'm trying to get familiar with Nom, currently version 5, where there is no CompleteStr and other things, so related questions aren't so helpful. How can I parse something like "@pook Some free text @another_pook And another…
fevgenym
  • 568
  • 7
  • 20
3
votes
1 answer

How do I parse uppercase strings in Nom?

I'm writing parsers in Nom 5 using functions, not macros. My goal is to write a parser that recognizes a string composed entirely of uppercase characters. Ideally, it would have the same return signature as alpha1. use nom::{ …
Adam
  • 482
  • 1
  • 4
  • 12
1
2
3
8 9