cargo fmt

This commit is contained in:
Jeremy Wall 2017-11-08 18:55:10 -06:00
parent 4f3cc3dbf6
commit 0be96dc851
4 changed files with 55 additions and 27 deletions

View File

@ -80,7 +80,11 @@ impl<T> LocatedNode<T> {
// TODO(jwall): This should take a line and a column as argumentsn now.
pub fn make_value_node<T>(v: T, line: usize, column: usize) -> LocatedNode<T> {
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<T: PartialEq> PartialEq for Positioned<T> {
}
}
impl<T: Eq> Eq for Positioned<T> {
}
impl<T: Eq> Eq for Positioned<T> {}
impl<T: Ord> Ord for Positioned<T> {
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())
],

View File

@ -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<String>, Rc<Val>)> =
b.out.drain().collect();
let fields: Vec<(Positioned<String>, Rc<Val>)> = 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();

View File

@ -52,7 +52,8 @@ impl<V: Into<String> + Clone> Formatter<V> {
}
}
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);

View File

@ -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<Token>, Option<Token>, Option<Token>)) -> ParseResult<Value> {
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()),
};
@ -170,12 +176,16 @@ named!(simple_expression( Span ) -> Expression,
)
);
fn tuple_to_binary_expression(tpl: (Span, BinaryExprType, Value, Expression)) -> ParseResult<Expression> {
fn tuple_to_binary_expression(tpl: (Span, BinaryExprType, Value, Expression))
-> ParseResult<Expression> {
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<T>(v: Vec<T>) -> ParseResult<Vec<T>> {
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<Expression>
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>, Value)) -> ParseResult<Expression> {
})
.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<Expr
val: Box::new(t.1),
default: Box::new(t.2),
tuple: 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.
@ -361,7 +380,10 @@ fn tuple_to_call(t: (Span, Value, Vec<Expression>)) -> ParseResult<Expression> {
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))))
@ -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();