Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make no_std compatible #33

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ include = [
members = ["nom-derive-impl"]

[dependencies]
nom = "6.0"
nom = {version = "6.0", default-features = false}
nom-derive-impl = { version="=0.9.1", path="./nom-derive-impl" }
rustversion = "1.0"

[dev-dependencies]
pretty_assertions = "0.7"
trybuild = "1.0"

[features]
alloc = ["nom/alloc"]
default = ["std"]
std = ["alloc", "nom/std"]
2 changes: 1 addition & 1 deletion nom-derive-impl/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn gen_fn_decl(
#ident_e: nom_derive::nom::error::ParseError<&#lft [u8]>
};
fn_where_clause.predicates.push(dep);
let dep: WherePredicate = parse_quote! { #ident_e: std::fmt::Debug };
let dep: WherePredicate = parse_quote! { #ident_e: core::fmt::Debug };
fn_where_clause.predicates.push(dep);
// add error type to function generics
fn_generics = Some(quote!(<#ident_e>));
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::traits::*;
use core::marker::PhantomData;
use nom::error::ParseError;
use nom::{IResult, ToUsize};
use std::marker::PhantomData;

#[derive(Debug, PartialEq)]
pub struct LengthData<L, D> {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
//! `stderr` if the parser fails.
//!
//! [nom]: https://github.com/geal/nom
#![cfg_attr(not(any(test, feature = "std")), no_std)]

pub mod docs;
mod helpers;
Expand Down
14 changes: 10 additions & 4 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use core::convert::TryFrom;
use core::ops::RangeFrom;
use nom::bytes::streaming::take;
use nom::combinator::{complete, map_res, opt};
use nom::error::{Error, FromExternalError, ParseError};
use nom::multi::{many0, many_m_n};
use nom::number::streaming::*;
use nom::sequence::pair;
use nom::*;
use std::convert::TryFrom;
use std::ops::RangeFrom;

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "alloc")]
use alloc::{borrow::ToOwned, string::String, vec::Vec};

pub use nom::{InputLength, Slice};

Expand Down Expand Up @@ -152,11 +158,11 @@ impl_primitive_type!(f64, be_f64, le_f64);

impl<'a, E> Parse<&'a [u8], E> for String
where
E: ParseError<&'a [u8]> + FromExternalError<&'a [u8], std::str::Utf8Error>,
E: ParseError<&'a [u8]> + FromExternalError<&'a [u8], core::str::Utf8Error>,
{
fn parse(i: &'a [u8]) -> IResult<&'a [u8], Self, E> {
let (rem, sz) = <u32>::parse(i)?;
let (rem, s) = map_res(take(sz as usize), std::str::from_utf8)(rem)?;
let (rem, s) = map_res(take(sz as usize), core::str::from_utf8)(rem)?;
Ok((rem, s.to_owned()))
}
}
Expand Down