Fix slightly too eager parsing of aliases

This commit is contained in:
Tiffany Bennett 2016-08-02 22:09:08 -04:00
parent c136c8a216
commit 15228a373b
2 changed files with 21 additions and 0 deletions

17
src/bin/tokens.rs Normal file
View file

@ -0,0 +1,17 @@
extern crate units_rs;
use units_rs::*;
fn main() {
use std::io::Read;
use std::fs::File;
let mut f = File::open("units.txt").unwrap();
let mut buf = vec![];
f.read_to_end(&mut buf).unwrap();
let string = String::from_utf8_lossy(&*buf);
let mut iter = unit_defs::TokenIterator::new(&*string).peekable();
let res = unit_defs::tokens(&mut iter);
println!("{:#?}", res);
}

View file

@ -223,6 +223,10 @@ fn parse_unknown(mut iter: &mut Iter) {
}
fn parse_alias(mut iter: &mut Iter) -> Option<(Expr, String)> {
match *iter.peek().unwrap() {
Token::Newline | Token::Comment | Token::Eof => return None,
_ => ()
}
let expr = parse_expr(iter);
match iter.next().unwrap() {
Token::TriplePipe => (),