Module nom
Parser combinator library for building zero-copy parsers.
nom is a parser combinator library that enables building parsers
by combining small, reusable parsing functions.
Rather than using separate grammar definition tools or generating code, nom parsers are written directly in Rust as composable functions. Each parser function takes an input slice and returns either the remaining input with the parsed value, or an error. These small parsers can be combined using combinator functions to build complex parsers that match the structure of your grammar.
Parser combinators have tradeoffs vs. other parser
architectures, but it is nice to have one at hand when you need it,
and nom is well-tested and well-maintained.
And it is fast.
Key features include:
- Zero-copy parsing that works with input slices directly
- Streaming support for incomplete input (useful for network protocols)
- Both byte-oriented and character-oriented parsing
- Rich set of built-in parsers and combinators
- Strong type safety with compile-time validation
Examples
Parsing a simple numeric value:
use ;
let result = parse_number;
assert_eq!;
Combining parsers with sequence operations:
use ;
let result = parse_date;
assert_eq!;
Modules
- bits Bit level parsers
- branch Choice combinators
- bytes Parsers recognizing bytes streams
- character Character specific parsers and combinators
- combinator General purpose combinators
- error Error management
-
lib
Lib module to re-export everything needed from
stdorcore/alloc. This is howserdedoes it, albeit there it is not public. - multi Combinators applying their child parser multiple times
- number Parsers recognizing numbers
-
recipes
Common recipes to build nom parsers
- sequence Combinators applying parsers in sequence
Macros
-
error_node_position
Creates a parse error from a
nom::ErrorKind, the position in the input and the next error in the parsing tree -
error_position
Creates a parse error from a
nom::ErrorKindand the position in the input