Float literals too

This commit is contained in:
greg 2017-09-11 02:38:27 -07:00
parent 0dabbc700b
commit 14c09bb40c

View File

@ -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()?;
let p = self.peek();
if let TokenType::Period = self.peek() {
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>() { match digits.parse::<u64>() {
Ok(d) => Ok(UnsignedIntLiteral(d)), Ok(d) => Ok(UnsignedIntLiteral(d)),
Err(p) => unimplemented!("Need to handle numbers that don't parse to a Rust u64 {:?}", p), 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,
} }
} }