David Tolnay | c5ab8c6 | 2017-12-26 16:43:39 -0500 | [diff] [blame] | 1 | //! 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 | |
| 24 | use proc_macro2::TokenStream; |
| 25 | |
| 26 | pub use cursor::*; |
| 27 | |
David Tolnay | 203557a | 2017-12-27 23:59:33 -0500 | [diff] [blame^] | 28 | pub use error::{PResult, ParseError}; |
David Tolnay | c5ab8c6 | 2017-12-26 16:43:39 -0500 | [diff] [blame] | 29 | |
| 30 | pub trait Synom: Sized { |
| 31 | fn parse(input: Cursor) -> PResult<Self>; |
| 32 | |
| 33 | fn description() -> Option<&'static str> { |
| 34 | None |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl Synom for TokenStream { |
| 39 | fn parse(input: Cursor) -> PResult<Self> { |
| 40 | Ok((Cursor::empty(), input.token_stream())) |
| 41 | } |
| 42 | } |