Remove vestigial frink definition parser

This commit is contained in:
Tiffany Bennett 2016-08-22 15:03:26 -04:00
parent 2d84daf064
commit 7158fe81e1
2 changed files with 3 additions and 112 deletions

View file

@ -39,7 +39,7 @@ extern crate libc;
#[cfg(feature = "sandbox")]
extern crate ipc_channel;
pub mod unit_defs;
pub mod text_query;
pub mod eval;
pub mod number;
pub mod date;
@ -143,8 +143,8 @@ pub fn load() -> Result<Context, String> {
/// Evaluates a single line within a context.
pub fn one_line(ctx: &mut Context, line: &str) -> Result<String, String> {
let mut iter = unit_defs::TokenIterator::new(line.trim()).peekable();
let expr = unit_defs::parse_expr(&mut iter);
let mut iter = text_query::TokenIterator::new(line.trim()).peekable();
let expr = text_query::parse_expr(&mut iter);
ctx.eval_outer(&expr)
}

View file

@ -4,7 +4,6 @@
use std::str::Chars;
use std::iter::Peekable;
use std::rc::Rc;
use ast::*;
#[derive(Debug, Clone)]
@ -523,111 +522,3 @@ pub fn parse_expr(mut iter: &mut Iter) -> Expr {
_ => left
}
}
fn parse_unknown(mut iter: &mut Iter) {
loop {
match iter.peek().cloned().unwrap() {
Token::Newline | Token::Comment(_) | Token::Eof => break,
_ => iter.next()
};
}
}
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 => (),
_ => return None
};
let name = match iter.next().unwrap() {
Token::Ident(name) => name,
_ => return None
};
match iter.peek().cloned().unwrap() {
Token::Newline | Token::Comment(_) | Token::Eof => (),
_ => return None
};
Some((expr, name))
}
pub fn parse(mut iter: &mut Iter) -> Defs {
let mut map = vec![];
let mut line = 1;
loop {
let mut copy = iter.clone();
if let Some(a) = parse_alias(&mut copy) {
map.push((a.1, Rc::new(Def::Quantity(a.0))));
*iter = copy;
continue
}
match iter.next().unwrap() {
Token::Newline => line += 1,
Token::Comment(lines) => line += lines,
Token::Eof => break,
Token::Ident(name) => {
let def = match iter.next().unwrap() {
Token::ColonDash => {
let expr = parse_expr(iter);
Def::Prefix(expr)
},
Token::DColonDash => {
let expr = parse_expr(iter);
Def::SPrefix(expr)
},
Token::EqBangEq => match iter.next().unwrap() {
Token::Ident(val) => Def::Dimension(val),
_ => Def::Error(format!("Line {}: Malformed dimensionless unit", line))
},
Token::ColonEq => Def::Unit(parse_expr(iter)),
Token::LBrack => {
// NYI
let mut n = 0;
let mut first = true;
loop {
match iter.peek().cloned().unwrap() {
Token::LBrace => n += 1,
Token::RBrace if n == 1 => {
iter.next();
break
},
Token::RBrace => n -= 1,
Token::Newline | Token::Comment(_) if !first && n == 0 => break,
Token::Newline if first => first = false,
Token::Eof => break,
Token::Comment(lines) => line += lines,
_ => ()
}
iter.next();
}
continue
//Def::Error(format!("NYI: functions"))
}
_ => {
parse_unknown(iter);
Def::Error(format!("Line {}: Unknown definition", line))
}
};
map.push((name.clone(), Rc::new(def)));
},
_ => parse_unknown(iter)
};
}
Defs {
defs: map,
}
}
pub fn tokens(mut iter: &mut Iter) -> Vec<Token> {
let mut out = vec![];
loop {
match iter.next().unwrap() {
Token::Eof => break,
x => out.push(x)
}
}
out
}