Crate synom [] [src]

Adapted from nom by removing the IResult::Incomplete variant which:

  • we don't need,
  • is an unintuitive footgun when working with non-streaming use cases, and
  • more than doubles compilation time.

Whitespace handling strategy

As (sy)nom is a parser combinator library, the parsers provided here and that you implement yourself are all made up of successively more primitive parsers, eventually culminating in a small number of fundamental parsers that are implemented in Rust. Among these are punct! and keyword!.

All synom fundamental parsers (those not combined out of other parsers) should be written to skip over leading whitespace in their input. This way, as long as every parser eventually boils down to some combination of fundamental parsers, we get correct whitespace handling at all levels for free.

For our use case, this strategy is a huge improvement in usability, correctness, and compile time over nom's ws! strategy.

Macros

alt

Run a series of parsers, returning the result of the first one which succeeds.

call

Invoke the given parser function with the passed in arguments.

cond

Conditionally execute the given parser.

cond_reduce

Fail to parse if condition is false, otherwise parse the given parser.

delimited

Value surrounded by a pair of delimiters.

do_parse

Run a series of parsers, one after another, optionally assigning the results a name. Fail if any of the parsers fails.

epsilon

Parses nothing and always succeeds.

keyword

Parse a keyword like "fn" or "struct".

many0

Parse zero or more values using the given parser.

map

Transform the result of a parser by applying a function or closure.

named

Define a function from a parser combination.

not

Parses successfully if the given parser fails to parse. Does not consume any of the input.

opt_vec

Turn a failed parse into an empty vector. The argument parser must itself return a vector.

option

Turn a failed parse into None and a successful parse into Some.

peek

Parse a value without consuming it from the input data.

preceded

Parse two things, returning the value of the second.

punct

Parse a piece of punctuation like "+" or "+=".

separated_list

Zero or more values separated by some separator. Does not allow a trailing seperator.

separated_nonempty_list

One or more values separated by some separator. Does not allow a trailing separator.

switch

Pattern-match the result of a parser to select which other parser to run.

tag

Parse the given string from exactly the current position in the input. You almost always want punct! or keyword! instead of this.

take_until

Parse the part of the input up to but not including the given string. Fail to parse if the given string is not present in the input.

terminated

Parse two things, returning the value of the first.

terminated_list

Zero or more values separated by some separator. A trailing separator is allowed.

tuple

Run a series of parsers and produce all of the results in a tuple.

value

Produce the given value without parsing anything. Useful as an argument to switch!.

Enums

IResult

The result of a parser.