diff --git a/src/ast.rs b/src/ast.rs index 9eb231c..cf4f0bd 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -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; // 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 is expected to always be a symbol. #[derive(Debug,PartialEq,Clone)] pub struct LocatedNode { @@ -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, diff --git a/src/build.rs b/src/build.rs index f4b1aa9..e07ea11 100644 --- a/src/build.rs +++ b/src/build.rs @@ -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::()); 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] diff --git a/src/convert/mod.rs b/src/convert/mod.rs index 64d947e..c69955f 100644 --- a/src/convert/mod.rs +++ b/src/convert/mod.rs @@ -27,14 +27,12 @@ pub struct ConverterRunner { impl ConverterRunner { pub fn new(typ: &str) -> Result { 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, w: Box) -> io::Result<()> { self.converter.convert(v, w) } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 0aee191..174b2b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); diff --git a/src/parse.rs b/src/parse.rs index 5f7329b..17a046d 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -175,11 +175,11 @@ pub fn selector_or_symbol(input: Span) -> IResult { 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 >(t: (Sp, Vec)) -> ParseResult { - return Ok(Expression::List(ListDef{ +fn tuple_to_list>(t: (Sp, Vec)) -> ParseResult { + return Ok(Expression::List(ListDef { elems: t.1, pos: t.0.into(), })); @@ -555,10 +555,10 @@ pub fn parse(input: Span) -> IResult> { 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> { return IResult::Done(i, out); } -//named!(pub parse( Span ) -> Vec, many1!()); +// named!(pub parse( Span ) -> Vec, 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(