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

How to stop parsing other opts if past opts failed in nom.rs?

Currently i have 2 methods: parse_int and parse_string. They return either one number or one string, respectively. For example, if i have the parser tuple((parse_int, parse_string)), then it will convert " 123 sdf" to (123, "sdf"). My actual parser…
olegshmel
  • 13
  • 2
  • 4
0
votes
1 answer

Specifying only 1 type argument to generic?

In an attempt to write a parser in rust using nom. I ran into this error error[E0283]: type annotations needed --> src/parser.rs:8:22 | 8 | let mut parser = delimited(tag("<"), take_until(">"), tag(">")); | ---------- …
swaltek
  • 143
  • 5
0
votes
0 answers

How to let nom::alt return an impl type?

So I'm trying to tokenize a file. I just started. I implemented the parsing of a StringLiteral, and of a IntegerLiteral. I want my nom parser to return a generic impl of Token, but I'm getting the following error message type mismatch resolving…
Typhaon
  • 828
  • 8
  • 27
0
votes
0 answers

rust nom switch macro

I'm using rust nom 4.0.0 where it supports switch! macro: named!(sw, switch!(take!(4), b"abcd" => tag!("XYZ") | b"efgh" => tag!("123") ) ); However, nom 7.1.1 doesn't support switch! macro and I was wondering if there are other…
MoneyBall
  • 2,343
  • 5
  • 26
  • 59
0
votes
1 answer

Have short error message using nom with nom_locate

I am trying to parse using nom with nom_locate, following this tutorial. I only want output in the format: Error: line 5, column 1 But currently I get: Error: Parsing Failure: ParseError { span: LocatedSpan { offset: 37, line: 5, fragment:…
musicformellons
  • 12,283
  • 4
  • 51
  • 86
0
votes
1 answer

State with nom (>5) and `alt`

After trying some tree structures in Rust, I finally decided to built up a linearized tree, e.g. something like struct AST { exprs: Vec, } enum Expr { LiteralInt(i32), OpAdd(ExprRef, ExprRef), } struct ExprRef(usize); impl AST { …
aphorisme
  • 115
  • 4
0
votes
1 answer

NPM ERR code FETCH_ERROR npm install firebase

i have problem npm install firebase npm install --save firebase npm ERR! code FETCH_ERROR npm ERR! errno FETCH_ERROR npm ERR! invalid json response body at https://registry.npmjs.org/@firebase%2ffirestore reason: Unexpected end of JSON input npm…
0
votes
0 answers

What is the equivalent `nom` parser/combinator for the pattern /.*foobar/

I've been reading through the documentation for nom 6.2.1 and I'm trying to construct a parser which will match any number of characters (including zero) followed by the word foobar: /.*foobar/. nom::bytes::complete::take_until("foobar") almost does…
Huckle
  • 1,810
  • 3
  • 26
  • 40
0
votes
2 answers

Parsing single-quoted strings with backslash-escaped single quotes with nom

This is a variation of Parsing single-quoted string with escaped quotes with Nom 5 and Parse string with escaped single quotes. I want to parse strings like '1 \' 2 \ 3 \\ 4' (a raw sequence of characters) as "1 \\' 2 \\ 3 \\\\ 4" (a Rust string),…
user5365198
  • 103
  • 7
0
votes
1 answer

Parsing a variably space delimited list with nom

How can I consume a list of tokens that may or may not be separated by a space? I'm trying to parse Chinese romanization (pinyin) in the cedict format with nom (6.1.2). For example "ni3 hao3 ma5" which is, due to human error in transcription,…
Brian Kung
  • 3,957
  • 4
  • 21
  • 30
0
votes
1 answer

How can I wrap a nom tag_no_case parser?

I want to wrap tag_no_case parsers with specific string values to be able to re-use them: pub fn schema_parser(???) -> ??? { tag_no_case("schema") } to be used like this preceded(multispace0, schema_parser)(input) I've tried to copy the…
mottosson
  • 3,283
  • 4
  • 35
  • 73
0
votes
1 answer

The remaining data returned by nom::bits::bits is incorrect

I am trying to take 7 bits from &[u8] vector using nom::bits::bits, but I found that the remaining data is incorrect, it seems it must be the integral multiple of 4/8, but I'm not sure. some code like this(nom = 5.12): fn take_7_bits(i: &[u8]) ->…
xiaoai
  • 1,181
  • 2
  • 7
  • 5
0
votes
1 answer

Parsing a Number in nom

I am trying to use nom5 to pass a number of the zinc format https://www.project-haystack.org/doc/Zinc The number format can be like any of the following formats 1, -34, 10_000, 5.4e-45, -5.4e-45, 9.23kg, 74.2°F, 4min, INF, -INF, NaN I believe the…
Glenn Pierce
  • 720
  • 1
  • 6
  • 18
0
votes
0 answers

Begins with non-zero digit using nom?

I'm trying to write a markdown parser using nom and the EBNF shown here. I'm a little stuck as how to express begins with non-zero digit when trying to parse a number. Number = NonZeroDigit { Digit }; NonZeroDigit = "1" | "2" | "3" | "4" | "5" | "6"…
Breedly
  • 12,838
  • 13
  • 59
  • 83
0
votes
1 answer

How to parse matched separators by nom?

I want to parse YMD date in four forms ("20190919", "2019.09.19", "2019-09-19", and "2019/09/19") by nom library. I started with iso8601 parser which parse only "YYYY-MM-DD" form. And I tryed to match separator and reuse it for next matching like in…
Argentumbolo
  • 147
  • 1
  • 7
1 2 3
8
9