blob: 5d2d1a4035a6e9e2666cc2275c6895448fc18a9d [file] [log] [blame]
David Tolnayc5ab8c62017-12-26 16:43:39 -05001//! Adapted from [`nom`](https://github.com/Geal/nom) by removing the
2//! `IPResult::Incomplete` variant which:
3//!
4//! - we don't need,
5//! - is an unintuitive footgun when working with non-streaming use cases, and
6//! - more than doubles compilation time.
7//!
8//! ## Whitespace handling strategy
9//!
10//! As (sy)nom is a parser combinator library, the parsers provided here and
11//! that you implement yourself are all made up of successively more primitive
12//! parsers, eventually culminating in a small number of fundamental parsers
13//! that are implemented in Rust. Among these are `punct!` and `keyword!`.
14//!
15//! All synom fundamental parsers (those not combined out of other parsers)
16//! should be written to skip over leading whitespace in their input. This way,
17//! as long as every parser eventually boils down to some combination of
18//! fundamental parsers, we get correct whitespace handling at all levels for
19//! free.
20//!
21//! For our use case, this strategy is a huge improvement in usability,
22//! correctness, and compile time over nom's `ws!` strategy.
23
24use proc_macro2::TokenStream;
25
26pub use cursor::*;
27
David Tolnay203557a2017-12-27 23:59:33 -050028pub use error::{PResult, ParseError};
David Tolnayc5ab8c62017-12-26 16:43:39 -050029
30pub trait Synom: Sized {
31 fn parse(input: Cursor) -> PResult<Self>;
32
33 fn description() -> Option<&'static str> {
34 None
35 }
36}
37
38impl Synom for TokenStream {
39 fn parse(input: Cursor) -> PResult<Self> {
40 Ok((Cursor::empty(), input.token_stream()))
41 }
42}