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
1
vote
1 answer

How can I match an exact tag using the nom library in Rust

I'm working on a tiny duration parsing library written in Rust, and using the nom library. In this library, I define a second parser combinator function. Its responsibility is to parse the various acceptable formats for representing seconds in a…
Oleiade
  • 6,156
  • 4
  • 30
  • 42
1
vote
1 answer

Import a module used by other module in my webpack (nuxt) project

I'm realizing that importing a module (for instance moment.js) that is internally used by third party module (ie a .vue component) gives a build where the module is redundant because imported twice. Is this an expected behavior or I'm missing…
Daniele
  • 829
  • 1
  • 13
  • 23
1
vote
1 answer

How can I parse this program correctly using Rust's parser library nom

I want to parse a program represented by this BNF: := (* "&&" * )* := (* "&" * )* :=…
Kaoru
  • 33
  • 4
1
vote
1 answer

How to force nom to parse the whole input string?

I am working with nom version 6.1.2 and I am trying to parse Strings like A 2 1 2. At the moment I would be happy to at least differentiate between input that fits the requirements and inputs which don't do that. (After that I would like to change…
Heiko
  • 55
  • 5
1
vote
2 answers

Rust function syntax question, example seem in nom

I'm looking at the nom crate for rust, which contains lots of functions to parse bytes/characters. Many of the functions, such as tag(), seen below, process input that's provided not as a parameter to the function, but that appears instead in a…
Sam
  • 33
  • 3
1
vote
1 answer

Mysterious error "one type is more general than the other" when using Box with nom parsers

While trying to solve today's Advent of Code puzzle, I am attempting to use nom to build some dynamic parsers depending on input strings. But in doing so I've come against what to me is a very peculiar problem, which my lack of familiarity to Rust…
Robin Zigmond
  • 17,805
  • 2
  • 23
  • 34
1
vote
0 answers

Don't know how to use nom's dbg_dmp

I have a parser setup where I've injected dbg_dmp to the best of my ability: permutation(( check_eye_color, check_passport_id, check_birth_year, check_issue_year, check_expiry_year, check_hair_color, …
Alper
  • 3,424
  • 4
  • 39
  • 45
1
vote
1 answer

HashMap holding Vec buffer and slice to buffer

I am trying to store into a HashMap the result of a parsing operation on a text file (parsed with nom). The result is comprised of a Vec buffer and some slices over that buffer. The goal is to store those together in a tuple or struct as a value in…
djee
  • 43
  • 6
1
vote
0 answers

Parsing SQLite B-Tree-Page with nom

I am trying to parse a SQLite BTree Page (https://www.sqlite.org/fileformat2.html#btree) with nom. Nom works fine for parsing both headers (the database file header and the btree header), as well as the cell pointer array. I am now stuck on how to…
Hellstorm
  • 562
  • 4
  • 23
1
vote
2 answers

Rust - How to parse UTF-8 alphabetical characters in nom?

I am trying to parse character sequences of alphabetical characters, including german umlauts (ä ö ü) and other alphabetical characters from the UTF-8 charset. This is the parser I tried first: named!( parse(&'a str) -> Self, map!( …
stimulate
  • 1,199
  • 1
  • 11
  • 30
1
vote
1 answer

nom parsing a separate list

I'm trying to parse the following alternate strings with nom5.0 "A-Za-z0-9" or "A-Z|a-z|0-9" I've tried the following but to no avail pub enum Node { Range(Vec), } fn compound_range(input: &[u8]) -> IResult<&[u8], Node> { map( …
Delta_Fore
  • 3,079
  • 4
  • 26
  • 46
1
vote
1 answer

How to parse &str with named parameters?

I am trying to find the best way to parse a &str and extract out the COMMAND_TYPE and named parameters. The named parameters can be anything. Here is the proposed string (it can be changed). COMMAND_TYPE(param1:2222,param2:"the quick \"brown\" fox,…
James
  • 693
  • 1
  • 13
  • 27
1
vote
0 answers

Specifying lifetimes in nom's `named_args` (expected concrete lifetime, found bound)

I'm a Rust beginner, writing a nom parser that can parse lines that are colon-separated KEY: VALUEs. I made a base kv parser with named_args that can parse a key-value pair: named_args!(kv<'a>(key: &'a str)<&'a str, &'a str>, do_parse!( …
1
vote
2 answers

How to parse a slice of u16 input with nom?

Given a raw input stream of &[u16] how can I use nom to parse it taking into account that nom expects &str as input? For instance, given the following data: pub const RAW_INPUT: &[u16] = &[102, 111, 111]; I want to parse it into the string "foo".
Jesuspc
  • 1,664
  • 10
  • 25
1
vote
1 answer

How to parse the Redis RESP bulk string using nom?

I need use nom to parse a RESP request/reply. When I come to bulk-string, such as "$6\r\nfoobar\r\n" or $-1\r\n First, I write functions to extract the len from the data. named!(signed_digits<&str, (Option<&str>, &str)>, pair!( …
1 2 3
8 9