Cleanup: formatting and todos

cargo fmt
changed a fixme to a todo
This commit is contained in:
Jeremy Wall 2017-11-29 18:42:33 -06:00
parent 594e14cd0f
commit 389f395383
5 changed files with 53 additions and 45 deletions

View File

@ -54,8 +54,8 @@ macro_rules! value_node {
};
}
pub type FieldList = Vec<(Token, Expression)>; // str is expected to be a symbol
pub type SelectorList = Vec<Token>; // str is expected to always be a symbol.
pub type FieldList = Vec<(Token, Expression)>; // Token is expected to be a symbol
pub type SelectorList = Vec<Token>; // Token is expected to always be a symbol.
#[derive(Debug,PartialEq,Clone)]
pub struct LocatedNode<T> {
@ -497,11 +497,7 @@ mod ast_test {
#[test]
pub fn test_macro_validation_selector_fail() {
let def = MacroDef {
argdefs: vec![Positioned::new("foo".to_string(),
Position {
line: 1,
column: 0,
})],
argdefs: vec![Positioned::new("foo".to_string(), Position {line: 1, column: 0})],
fields: vec![
(Token::new("f1", Position{line: 1, column: 1}), Expression::Binary(BinaryOpDef{
kind: BinaryExprType::Add,

View File

@ -205,7 +205,7 @@ impl Val {
}
return false;
}
pub fn is_list(&self) -> bool {
if let &Val::Tuple(_) = self {
return true;
@ -429,22 +429,22 @@ impl Builder {
let next = it.next().unwrap();
match vref.as_ref() {
&Val::Tuple(_) => {
// This unwrap is safe because we already checked for
// Tuple in the pattern match.
let fs = vref.get_fields().unwrap();
if let Some(vv) = Self::find_in_fieldlist(&next.fragment, fs) {
stack.push_back(vv.clone());
continue;
} else {
// TODO(jwall): A better error for this would be nice.
return Err(Box::new(BuildError::NoSuchSymbol(format!("Unable to \
// This unwrap is safe because we already checked for
// Tuple in the pattern match.
let fs = vref.get_fields().unwrap();
if let Some(vv) = Self::find_in_fieldlist(&next.fragment, fs) {
stack.push_back(vv.clone());
continue;
} else {
// TODO(jwall): A better error for this would be nice.
return Err(Box::new(BuildError::NoSuchSymbol(format!("Unable to \
match selector \
path {:?}",
sl))));
}
}
}
&Val::List(ref elems) => {
// FIXME(jwall): better error reporting here would probably be good.
// TODO(jwall): better error reporting here would probably be good.
let idx = try!(next.fragment.parse::<usize>());
if idx < elems.len() {
stack.push_back(elems[idx].clone());
@ -943,16 +943,23 @@ mod test {
]
))),
])));
b.out.entry(Positioned::new("var2".to_string(),
Position {line: 1, column: 0}))
b.out
.entry(Positioned::new("var2".to_string(),
Position {
line: 1,
column: 0,
}))
.or_insert(Rc::new(Val::Int(2)));
b.out.entry(Positioned::new("var3".to_string(),
Position {line: 1, column: 0}))
.or_insert(Rc::new(Val::Tuple(
vec![(Positioned::new("lvl1".to_string(),
b.out
.entry(Positioned::new("var3".to_string(),
Position {
line: 1,
column: 0,
}))
.or_insert(Rc::new(Val::Tuple(vec![(Positioned::new("lvl1".to_string(),
Position {line: 1, column: 0}),
Rc::new(Val::Int(4)))])));
test_expr_to_val(vec![
(Expression::Simple(Value::Selector(make_value_node(vec![Token::new("var1", Position{line: 1, column: 1})], 1, 1))), Val::Tuple(
vec![
@ -985,8 +992,13 @@ mod test {
#[test]
fn test_eval_selector_list_expr() {
let mut b = Builder::new();
b.out.entry(Positioned::new("var1".to_string(), Position{line: 1, column: 1})).or_insert(Rc::new(Val::List(
vec![
b.out
.entry(Positioned::new("var1".to_string(),
Position {
line: 1,
column: 1,
}))
.or_insert(Rc::new(Val::List(vec![
Rc::new(Val::String("val1".to_string())),
Rc::new(Val::Tuple(vec![
(Positioned::new("var2".to_string(), Position{line: 1, column: 1}),
@ -1001,7 +1013,8 @@ mod test {
Token::new("0", Position{line: 1, column: 1})
], 1, 1))),
Val::String("val1".to_string()))
], b);
],
b);
}
#[test]

View File

@ -27,14 +27,12 @@ pub struct ConverterRunner {
impl ConverterRunner {
pub fn new(typ: &str) -> Result<Self, String> {
if typ == "flags" {
return Ok(ConverterRunner {
converter: Box::new(flags::FlagConverter::new()),
});
return Ok(ConverterRunner { converter: Box::new(flags::FlagConverter::new()) });
}
return Err(format!("Unknown Target output type: {}", typ))
return Err(format!("Unknown Target output type: {}", typ));
}
pub fn convert(&self, v: Rc<Val>, w: Box<Write>) -> io::Result<()> {
self.converter.convert(v, w)
}
}
}

View File

@ -60,7 +60,7 @@ fn main() {
let sym = matches.value_of("sym");
let target = matches.value_of("target").unwrap();
let mut builder = build::Builder::new();
match ConverterRunner::new(target) {
match ConverterRunner::new(target) {
Ok(converter) => {
let result = builder.build_file(file);
if !result.is_ok() {
@ -87,7 +87,7 @@ fn main() {
eprintln!("{}", msg);
process::exit(1);
}
}
}
} else if let Some(matches) = app.subcommand_matches("validate") {
let file = matches.value_of("INPUT").unwrap();
let mut builder = build::Builder::new();

View File

@ -175,11 +175,11 @@ pub fn selector_or_symbol(input: Span) -> IResult<Span, Value> {
match sym {
IResult::Incomplete(i) => {
return IResult::Incomplete(i);
},
}
IResult::Error(_) => {
// TODO(jwall): Maybe be smarter about the error reporting here?
return ws!(input, selector_value);
},
}
IResult::Done(rest, val) => {
return IResult::Done(rest, val);
}
@ -442,8 +442,8 @@ named!(call_expression( Span ) -> Expression,
)
);
fn tuple_to_list<Sp: Into<Position> >(t: (Sp, Vec<Expression>)) -> ParseResult<Expression> {
return Ok(Expression::List(ListDef{
fn tuple_to_list<Sp: Into<Position>>(t: (Sp, Vec<Expression>)) -> ParseResult<Expression> {
return Ok(Expression::List(ListDef {
elems: t.1,
pos: t.0.into(),
}));
@ -555,10 +555,10 @@ pub fn parse(input: Span) -> IResult<Span, Vec<Statement>> {
match ws!(i, statement) {
IResult::Error(e) => {
return IResult::Error(e);
},
}
IResult::Incomplete(i) => {
return IResult::Incomplete(i);
},
}
IResult::Done(rest, stmt) => {
out.push(stmt);
i = rest;
@ -571,12 +571,13 @@ pub fn parse(input: Span) -> IResult<Span, Vec<Statement>> {
return IResult::Done(i, out);
}
//named!(pub parse( Span ) -> Vec<Statement>, many1!());
// named!(pub parse( Span ) -> Vec<Statement>, many1!());
#[cfg(test)]
mod test {
use super::{Statement, Expression, Value, MacroDef, SelectDef, CallDef};
use super::{number, symbol, parse, field_value, selector_value, selector_or_symbol, tuple, grouped_expression, list_expression};
use super::{number, symbol, parse, field_value, selector_value, selector_or_symbol, tuple,
grouped_expression, list_expression};
use super::{copy_expression, macro_expression, select_expression};
use super::{format_expression, call_expression, expression};
use super::{expression_statement, let_statement, import_statement, statement};
@ -1306,7 +1307,7 @@ mod test {
)
)
);
assert_eq!(list_expression(LocatedSpan::new("[1, 1]")),
IResult::Done(LocatedSpan{fragment: "", offset: 6, line: 1},
Expression::List(