aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-15 14:27:55 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-15 14:27:55 -0800
commit9dd46d6fbfac371f4489f6fbcce7301a9abfeb36 (patch)
treeb13f1f996e41a0b45ca4d67259e938e7d91247d6 /src
parent931114a13ca2f6b4fe83328899a64ac4aa1956ec (diff)
downloadmilf-rs-9dd46d6fbfac371f4489f6fbcce7301a9abfeb36.tar.gz
milf-rs-9dd46d6fbfac371f4489f6fbcce7301a9abfeb36.zip
Fix parsing leading `+` on numbers
Diffstat (limited to 'src')
-rw-r--r--src/parser.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 721c83c..93aa830 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -254,7 +254,8 @@ impl<'a> Parser<'a> {
Some((pos, 't')) |
Some((pos, 'f')) => self.boolean(pos),
Some((pos, '[')) => self.array(pos),
- Some((pos, '-')) => self.number_or_datetime(pos),
+ Some((pos, '-')) |
+ Some((pos, '+')) => self.number_or_datetime(pos),
Some((pos, ch)) if ch.is_digit(10) => self.number_or_datetime(pos),
_ => {
let mut it = self.cur.clone();
@@ -453,8 +454,8 @@ impl<'a> Parser<'a> {
return Some(Value::String(ret));
}
- fn number_or_datetime(&mut self, start: usize) -> Option<Value> {
- let negative = self.eat('-');
+ fn number_or_datetime(&mut self, mut start: usize) -> Option<Value> {
+ let sign = if self.eat('+') { start += 1; true } else {self.eat('-')};
let mut is_float = false;
loop {
match self.cur.clone().next() {
@@ -473,7 +474,7 @@ impl<'a> Parser<'a> {
} else {
self.input.slice(start, end).parse().map(Float)
}
- } else if !negative && self.eat('-') {
+ } else if !sign && self.eat('-') {
self.datetime(start, end + 1)
} else {
self.input.slice(start, end).parse().map(Integer)