Factor out handling of leading whitespace
diff --git a/src/lit.rs b/src/lit.rs
index 6caba80..c4860bc 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -130,7 +130,7 @@
pub mod parsing {
use super::*;
use escape::{cooked_char, cooked_string, raw_string};
- use space::whitespace;
+ use space::skip_whitespace;
use nom::IResult;
use unicode_xid::UnicodeXID;
@@ -194,7 +194,6 @@
));
named!(float -> Lit, do_parse!(
- option!(whitespace) >>
value: float_string >>
suffix: alt!(
tag!("f32") => { |_| FloatTy::F32 }
@@ -207,10 +206,7 @@
));
named!(pub int -> (u64, IntTy), tuple!(
- preceded!(
- option!(whitespace),
- digits
- ),
+ digits,
alt!(
tag!("isize") => { |_| IntTy::Isize }
|
@@ -242,7 +238,9 @@
keyword!("false") => { |_| Lit::Bool(false) }
));
- fn float_string(input: &str) -> IResult<&str, String> {
+ fn float_string(mut input: &str) -> IResult<&str, String> {
+ input = skip_whitespace(input);
+
let mut chars = input.chars().peekable();
match chars.next() {
Some(ch) if ch >= '0' && ch <= '9' => {}
@@ -318,6 +316,8 @@
}
pub fn digits(mut input: &str) -> IResult<&str, u64> {
+ input = skip_whitespace(input);
+
let base = if input.starts_with("0x") {
input = &input[2..];
16