From 0be96dc8514f19fff20a120b7734d740fe4cc1e0 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 8 Nov 2017 18:55:10 -0600 Subject: [PATCH] cargo fmt --- src/ast.rs | 11 ++++++---- src/build.rs | 9 +++++--- src/format.rs | 3 ++- src/parse.rs | 59 ++++++++++++++++++++++++++++++++++----------------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 2e24b4f..590e99b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -80,7 +80,11 @@ impl LocatedNode { // TODO(jwall): This should take a line and a column as argumentsn now. pub fn make_value_node(v: T, line: usize, column: usize) -> LocatedNode { - LocatedNode::new(v, Position{line: line, column: column}) + LocatedNode::new(v, + Position { + line: line, + column: column, + }) } /// Value represents a Value in the UCG parsed AST. @@ -191,8 +195,7 @@ impl PartialEq for Positioned { } } -impl Eq for Positioned { -} +impl Eq for Positioned {} impl Ord for Positioned { fn cmp(&self, other: &Self) -> Ordering { @@ -453,7 +456,7 @@ mod ast_test { #[test] pub fn test_macro_validation_selector_happy_path() { - let def = MacroDef{ + let def = MacroDef { argdefs: vec![ Positioned::new("foo".to_string()) ], diff --git a/src/build.rs b/src/build.rs index 6fa8a3f..62ebcf7 100644 --- a/src/build.rs +++ b/src/build.rs @@ -350,8 +350,7 @@ impl Builder { if self.assets.get(&positioned_sym).is_none() { let mut b = Self::new(); try!(b.build_file(&val)); - let fields: Vec<(Positioned, Rc)> = - b.out.drain().collect(); + let fields: Vec<(Positioned, Rc)> = b.out.drain().collect(); let result = Rc::new(Val::Tuple(fields)); self.assets.entry(positioned_sym).or_insert(result.clone()); self.files.insert(val.clone()); @@ -1142,7 +1141,11 @@ mod test { fn test_let_statement() { let mut b = Builder::new(); let stmt = Statement::Let { - name: Token::new("foo", Position{line: 1, column: 1}), + name: Token::new("foo", + Position { + line: 1, + column: 1, + }), value: Expression::Simple(Value::String(make_value_node("bar".to_string(), 1, 1))), }; b.build_stmt(&stmt).unwrap(); diff --git a/src/format.rs b/src/format.rs index 4684617..16424d9 100644 --- a/src/format.rs +++ b/src/format.rs @@ -52,7 +52,8 @@ impl + Clone> Formatter { } } if self.args.len() != count { - return Err(Box::new(BuildError::FormatError("Too many arguments to string formatter." + return Err(Box::new(BuildError::FormatError("Too many arguments to string \ + formatter." .to_string()))); } return Ok(buf); diff --git a/src/parse.rs b/src/parse.rs index bd5d269..a518260 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -56,7 +56,13 @@ named!(quoted_value( Span ) -> Value, // Helper function to make the return types work for down below. fn triple_to_number(v: (Option, Option, Option)) -> ParseResult { let (pref, mut pref_pos) = match v.0 { - None => ("", Position{line: 0, column: 0}), + None => { + ("", + Position { + line: 0, + column: 0, + }) + } Some(ref bs) => (bs.fragment.borrow(), bs.pos.clone()), }; @@ -69,7 +75,7 @@ fn triple_to_number(v: (Option, Option, Option)) -> ParseRe if v.0.is_none() && has_dot { pref_pos = v.1.unwrap().pos; } - + let suf = match v.2 { None => "", Some(ref bs) => &bs.fragment, @@ -170,12 +176,16 @@ named!(simple_expression( Span ) -> Expression, ) ); -fn tuple_to_binary_expression(tpl: (Span, BinaryExprType, Value, Expression)) -> ParseResult { +fn tuple_to_binary_expression(tpl: (Span, BinaryExprType, Value, Expression)) + -> ParseResult { Ok(Expression::Binary(BinaryOpDef { kind: tpl.1, left: tpl.2, right: Box::new(tpl.3), - pos: Some(Position{line: tpl.0.line as usize, column: tpl.0.offset as usize}), + pos: Some(Position { + line: tpl.0.line as usize, + column: tpl.0.offset as usize, + }), })) } @@ -227,7 +237,7 @@ named!(grouped_expression( Span ) -> Expression, fn assert_nonempty_list(v: Vec) -> ParseResult> { if v.is_empty() { - return Err(Box::new(ParseError::EmptyExpression("Selectors can't be empty.".to_string()))) + return Err(Box::new(ParseError::EmptyExpression("Selectors can't be empty.".to_string()))); } return Ok(v); } @@ -243,7 +253,10 @@ fn tuple_to_copy(t: (Span, SelectorList, FieldList)) -> ParseResult Ok(Expression::Copy(CopyDef { selector: t.1, fields: t.2, - pos: Some(Position{line: t.0.line as usize, column: t.0.offset as usize}), + pos: Some(Position { + line: t.0.line as usize, + column: t.0.offset as usize, + }), })) } @@ -275,7 +288,10 @@ fn tuple_to_macro(mut t: (Span, Vec, Value)) -> ParseResult { }) .collect(), fields: v.val, - pos: Some(Position{line: t.0.line as usize, column: t.0.offset as usize}), + pos: Some(Position { + line: t.0.line as usize, + column: t.0.offset as usize, + }), })) } // TODO(jwall): Show a better version of the unexpected parsed value. @@ -310,7 +326,10 @@ fn tuple_to_select(t: (Span, Expression, Expression, Value)) -> ParseResult)) -> ParseResult { Ok(Expression::Call(CallDef { macroref: sl.val, arglist: t.2, - pos: Some(Position{line: t.0.line as usize, column: t.0.offset as usize}), + pos: Some(Position { + line: t.0.line as usize, + column: t.0.offset as usize, + }), })) } else { Err(Box::new(ParseError::UnexpectedToken("Selector".to_string(), format!("{:?}", t.0)))) @@ -609,7 +631,7 @@ mod test { }, value: Expression::Simple(Value::Float(value_node!(1.0, Position{line: 1, column: 11}))) })); - + let_stmt = "let foo= 1.0;"; assert_eq!(let_statement(LocatedSpan::new(let_stmt)), IResult::Done(LocatedSpan{ @@ -848,13 +870,13 @@ mod test { (Token::new("foo", Position{line: 1, column: 25}), Expression::Simple(Value::Symbol(value_node!("arg1".to_string(), Position{line: 1, column: 31})))), ], - // FIXME(jwall): I think this is incorrect. + // FIXME(jwall): I think this is incorrect. pos: Some(Position{line: 1, column: 0}), }) ) ); - let select_expr = "select foo, 1, { foo = 2 }"; - assert_eq!(expression(LocatedSpan::new(select_expr)), + let select_expr = "select foo, 1, { foo = 2 }"; + assert_eq!(expression(LocatedSpan::new(select_expr)), IResult::Done(LocatedSpan { fragment: "", offset: select_expr.len(), @@ -871,8 +893,8 @@ mod test { }) ) ); - let call_expr = "foo.bar (1, \"foo\")"; - assert_eq!(expression(LocatedSpan::new(call_expr)), + let call_expr = "foo.bar (1, \"foo\")"; + assert_eq!(expression(LocatedSpan::new(call_expr)), IResult::Done(LocatedSpan { fragment: "", offset: call_expr.len(), @@ -889,7 +911,7 @@ mod test { }) ) ); - assert_eq!(expression(LocatedSpan::new("(1 + 1)")), + assert_eq!(expression(LocatedSpan::new("(1 + 1)")), IResult::Done(LocatedSpan { fragment: "", offset: 7, @@ -1180,7 +1202,7 @@ mod test { Expression::Simple(Value::String(value_node!("1".to_string(), Position{line: 1, column: 18})))) ], Position{line: 1, column: 0})))); tuple_expr = "{ foo = 1, bar = {} }"; - assert_eq!(tuple(LocatedSpan::new(tuple_expr)), + assert_eq!(tuple(LocatedSpan::new(tuple_expr)), IResult::Done(LocatedSpan { fragment: "", offset: tuple_expr.len(), @@ -1256,8 +1278,7 @@ mod test { assert!(bad_result.is_err() ); // Valid parsing tree - let input = - LocatedSpan::new("import \"mylib\" as lib;let foo = 1;1+1;"); + let input = LocatedSpan::new("import \"mylib\" as lib;let foo = 1;1+1;"); let result = parse(input); assert!(result.is_done() ); let tpl = result.unwrap();