Skip to content

Instantly share code, notes, and snippets.

Martin Wernstål m4rw3r

Block or report user

Report or block m4rw3r

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
m4rw3r /
Last active Feb 11, 2017 — forked from anonymous/
Shared via Rust Playground
extern crate chomp;
use std::rc::Rc;
use chomp::prelude::{token, SimpleResult, parse_only};
use chomp::ascii::{is_alphanumeric, is_whitespace};
use chomp::types::{Buffer, U8Input};
use chomp::parsers::{take_while1, skip_while};
use chomp::combinators::many;
m4rw3r /
Last active Aug 23, 2016
Benchmarks comparing `feature/input_trait` with `experiment/impl_trait`

experiment/impl_trait is essentially a reimplementation of all the parsers and combinators using the same baseline code as feature/input_trait. The feature/input_trait is intended to be chomp 0.3, and experiment/impl_trait either 1.0 or maybe a new crate chomp2 (useful since feature/input_trait still works on stable while experiment/impl_trait requires the latest nightly version of rustc).

Both share the same reposiotory and dependencies, just two different branches. Same code is used for both tests, with slight adjustment for how parsers are structured.

rustc --version
rustc 1.13.0-nightly (1576de0ce 2016-08-21)


m4rw3r /
Created Aug 19, 2016
impl Trait with Input trait version of the chomp example HTTP-parser
extern crate chomp;
extern crate memmap;
use std::fs::File;
use std::env;
use chomp::types::{Input, Parser};
m4rw3r /
Last active Mar 7, 2016
WIP of pre-RFC for saturating and wrapping integer wrapper types
  • Feature Name: saturating-and-checking-integer-wrapper-types
  • Start Date: (fill me in with today's date, YYYY-MM-DD)
  • RFC PR: (leave this empty)
  • Rust Issue: (leave this empty)


Implement two wrapper-types in std::num which provide two different types of behavior on overflow: saturating arithmetic and always checked arithmetic with the latter signalling a thread panic on

extern crate rsz;
use rsz::{FunctorMut, HKT, MonadMut, Unit};
// Let's say that this type requires to run the closure multiple times,
// so we can only implement the mutable monads.
pub struct Foo<T> {
inner: T,
m4rw3r /
Created Feb 10, 2016
Just a quick implementation of line-numbering where a parser is wrapped to keep track of the number of lines it has parsed so far
use std::marker::PhantomData;
pub trait NumberingType {
type Token;
type Position;
fn update(&mut self, &[Self::Token]);
fn position(&self) -> Self::Position;
m4rw3r / nom_many1_fix_incomplete.diff
Created Nov 27, 2015
Nom: Fix for many1 not propagating incomplete state
View nom_many1_fix_incomplete.diff
diff --git a/src/ b/src/
index 7ea9fbd..607ab25 100644
--- a/src/
+++ b/src/
@@ -1712,14 +1712,27 @@ macro_rules! many1(
let mut res = Vec::new();
let mut input = $i;
- while let $crate::IResult::Done(i,o) = $submac!(input, $($args)*) {
- if i.len() == input.len() {
extern crate combine;
use combine::*;
use combine::primitives::Error;
use combine::combinator::take_while1;
use std::fs::File;
use std::env;
extern crate nom;
use nom::IResult;
use std::env;
use std::fs::File;
struct Request<'a> {
/// Macro emulating `do`-notation for the parser monad, automatically threading the linear type.
/// ```ignore
/// parse!{input;
/// parser("parameter");
/// let value = other_parser();
/// ret do_something(value);
/// }
/// // equivalent to:
You can’t perform that action at this time.