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
0
votes
1 answer

Nom 5: creating a combinator using another parser multiple times

Suppose I want to create a combinator which uses another parser multiple times, for example, to parse a string delimited by two kinds of quotes: fn quoted<'a, F: 'a, O, E: ParseError<&'a str>>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O,…
Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296
0
votes
0 answers

Combining macros with the nom library

I am attempting to use the nom library to parse a FEN String. I have used an alt! macro to combine three smaller combinators that operate on a single character. Now I would like to use use that same combinator to parse a string of characters into a…
BBS
  • 1,351
  • 2
  • 12
  • 27
0
votes
1 answer

Why does nom expect a &str when I pass a CompleteStr?

The parser works as expected until I want to parse the h: digit which is always the last digit in the string and the compiler gives me ^ expected &str, found struct `nom::types::CompleteStr` I assume it's because the parser is looking ahead. How…
Pumphouse
  • 2,013
  • 17
  • 26
0
votes
0 answers

Parsing alphanumeric identifiers with underscores and calling from top level parser

Trying to do something similar to this question except allow underscores from the second character onwards. Not just camel case. I can test the parser in isolation successfully but when composed in a higher level parser, I get errors Take the…
candronikos
  • 159
  • 1
  • 13
0
votes
1 answer

Parse an integer to a float using Nom

Nom has an example of parsing a floating point number: named!(unsigned_float , map_res!( map_res!( recognize!( alt!( delimited!(digit, tag!("."), opt!(complete!(digit))) | delimited!(opt!(digit), tag!("."), digit) …
mitnk
  • 3,127
  • 2
  • 21
  • 28
-1
votes
1 answer

Match a slug with Nom

I've been trying for some time to find a decent solution for Nom to recognize the slug as an alpha1. So I could parse something like this fn parse<'a>(text: &'a str) -> IResult<&'a str, &'a str> { delimited(char(':'), slug,…
HelloEdit
  • 64
  • 2
  • 8
-1
votes
1 answer

Does it make any sense to use `nom` to process custom enum types?

I am attempting to implement a parser for a simple query language. The goal is to generate operations from the text and then evaluate them before passing them up the tree. If I understand correctly, I'll have to implement some of the nom traits…
candronikos
  • 159
  • 1
  • 13
-4
votes
1 answer

How to distinguish between minus sign and negative number in nom?

Using the parser generator nom, how can I write a parser which extracts the difference of the minus sign in the terms 1-2 and 1*-2 ? In the first example, I expect the tokens 1, - and 2. In the second the "minus" sign specifies the number being…
Matthias
  • 1,055
  • 2
  • 14
  • 26
1 2 3
8
9