Float literals too
This commit is contained in:
parent
0dabbc700b
commit
14c09bb40c
@ -440,10 +440,22 @@ impl Parser {
|
|||||||
|
|
||||||
fn float_literal(&mut self) -> ParseResult<Expression> {
|
fn float_literal(&mut self) -> ParseResult<Expression> {
|
||||||
use self::Expression::*;
|
use self::Expression::*;
|
||||||
let digits = self.digits()?;
|
let mut digits = self.digits()?;
|
||||||
match digits.parse::<u64>() {
|
let p = self.peek();
|
||||||
Ok(d) => Ok(UnsignedIntLiteral(d)),
|
if let TokenType::Period = self.peek() {
|
||||||
Err(p) => unimplemented!("Need to handle numbers that don't parse to a Rust u64 {:?}", p),
|
self.next();
|
||||||
|
digits.push_str(".");
|
||||||
|
digits.push_str(&self.digits()?);
|
||||||
|
match digits.parse::<f64>() {
|
||||||
|
Ok(f) => Ok(FloatLiteral(f)),
|
||||||
|
Err(e) => unimplemented!("Float didn't parse with error: {}", e),
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match digits.parse::<u64>() {
|
||||||
|
Ok(d) => Ok(UnsignedIntLiteral(d)),
|
||||||
|
Err(e) => unimplemented!("Need to handle numbers that don't parse to a Rust u64 {}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,9 +463,9 @@ impl Parser {
|
|||||||
use self::TokenType::*;
|
use self::TokenType::*;
|
||||||
let mut ds = String::new();
|
let mut ds = String::new();
|
||||||
loop {
|
loop {
|
||||||
match self.next() {
|
match self.peek() {
|
||||||
Underscore => continue,
|
Underscore => { self.next(); continue; },
|
||||||
DigitGroup(ref s) => ds.push_str(s),
|
DigitGroup(ref s) => { self.next(); ds.push_str(s)},
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user