-
Easy chaining of monadic actions.
Ie. separating two monadic actions should chain them together with
bind(a, |_| b)
. -
Simple bind of a value to an ident.
This should probably also allow any monadic action and not just calls to functions, eg. something like:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Source<'a> { | |
fn get(&mut self) -> Option<u8>; | |
fn mark(&self) -> &'a [u8]; | |
fn restore(&mut self, &'a [u8]); | |
} | |
struct Slice<'a>(&'a [u8]); | |
impl<'a> Source<'a> for Slice<'a> { | |
fn get(&mut self) -> Option<u8> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod parser { | |
use std::fmt::Debug; | |
#[derive(Debug)] | |
pub enum Error<T> { | |
DidNotSatisfy(T) | |
} | |
#[derive(Debug)] | |
enum State<T, E> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate parser; | |
use parser::{Parser, Error}; | |
use std::fs::File; | |
use std::env; | |
#[derive(Debug)] | |
struct Request<'a> { | |
method: &'a [u8], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate nom; | |
use nom::IResult; | |
use std::env; | |
use std::fs::File; | |
#[derive(Debug)] | |
struct Request<'a> { | |
method: &'a [u8], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! http parser comparable to the http-parser found in attoparsec's examples. | |
//! | |
//! Reads data in the following format: | |
//! | |
//! ```text | |
//! GET /robot.txt HTTP/1.1 | |
//! Host: localhost | |
//! Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 | |
//! | |
//! ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiling my_own v0.1.0 (file:///Users/m4rw3r/Desktop/attoparsec/examples/my_own) | |
#![feature(no_std)] | |
#![no_std] | |
#[prelude_import] | |
use std::prelude::v1::*; | |
#[macro_use] | |
extern crate std as std; | |
#[macro_use] | |
extern crate parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/examples/http_parser.rs b/examples/http_parser.rs | |
index 5c31b35..196763e 100644 | |
--- a/examples/http_parser.rs | |
+++ b/examples/http_parser.rs | |
@@ -41,17 +41,17 @@ fn is_not_space(c: u8) -> bool { c != b' ' } | |
fn is_end_of_line(c: u8) -> bool { c == b'\r' || c == b'\n' } | |
fn is_http_version(c: u8) -> bool { c >= b'0' && c <= b'9' || c == b'.' } | |
-fn end_of_line<'a>(p: Empty<'a, u8>) -> Parser<'a, u8, u8, Error<u8>> { | |
- or(mdo!{p, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate combine; | |
use combine::*; | |
use std::fs::File; | |
use std::env; | |
// Seems like combine does not support any kind of zero-copy parsing | |
#[derive(Debug, Clone)] | |
struct Request { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate combine; | |
use combine::*; | |
use combine::combinator::{take_while1, range}; | |
use combine::primitives::Error; | |
use std::fs::File; | |
use std::env; | |