Skip to content

Commit 7260ba8

Browse files
committed
rustfmt
1 parent 1a307a2 commit 7260ba8

File tree

14 files changed

+185
-151
lines changed

14 files changed

+185
-151
lines changed

src/clojure_std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub (crate) mod thread;
2-
pub (crate) mod time;
1+
pub(crate) mod thread;
2+
pub(crate) mod time;

src/clojure_std/thread.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::value::{ToValue, Value};
2-
use std::rc::Rc;
3-
use crate::ifn::IFn;
4-
use std::io::Read;
5-
use std::error::Error;
61
use crate::error_message;
7-
use nom::lib::std::convert::TryFrom;
2+
use crate::ifn::IFn;
83
use crate::type_tag::TypeTag;
4+
use crate::value::{ToValue, Value};
5+
use nom::lib::std::convert::TryFrom;
6+
use std::error::Error;
7+
use std::io::Read;
8+
use std::rc::Rc;
99

1010
use std::thread;
1111
use std::time;
@@ -26,13 +26,13 @@ impl IFn for SleepFn {
2626
match arg {
2727
Value::I32(i) => {
2828
std::thread::sleep(time::Duration::new(0, (*i as u32) * 1000000));
29-
return Value::Nil
30-
},
31-
_ => error_message::type_mismatch(TypeTag::I32, args.get(0).unwrap())
29+
return Value::Nil;
30+
}
31+
_ => error_message::type_mismatch(TypeTag::I32, args.get(0).unwrap()),
3232
}
3333
} else {
3434
error_message::wrong_arg_count(1, args.len());
35-
return Value::Nil
35+
return Value::Nil;
3636
}
3737
}
38-
}
38+
}

src/clojure_std/time.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::value::{ToValue, Value};
2-
use std::rc::Rc;
3-
use crate::ifn::IFn;
4-
use std::io::Read;
5-
use std::error::Error;
61
use crate::error_message;
7-
use nom::lib::std::convert::TryFrom;
2+
use crate::ifn::IFn;
83
use crate::type_tag::TypeTag;
4+
use crate::value::{ToValue, Value};
5+
use nom::lib::std::convert::TryFrom;
6+
use std::error::Error;
7+
use std::io::Read;
8+
use std::rc::Rc;
99

1010
use std::thread;
1111
use std::time::{SystemTime, UNIX_EPOCH};
@@ -22,11 +22,14 @@ impl ToValue for NanoTimeFn {
2222
impl IFn for NanoTimeFn {
2323
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
2424
if args.len() == 0 {
25-
let ns = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos();
26-
return Value::F64(ns as f64)
25+
let ns = SystemTime::now()
26+
.duration_since(UNIX_EPOCH)
27+
.unwrap()
28+
.as_nanos();
29+
return Value::F64(ns as f64);
2730
} else {
2831
error_message::wrong_arg_count(0, args.len());
29-
return Value::Nil
32+
return Value::Nil;
3033
}
3134
}
32-
}
35+
}

src/environment.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use crate::clojure_std;
12
use crate::namespace::{Namespace, Namespaces};
23
use crate::repl;
34
use crate::repl::Repl;
45
use crate::rust_core;
5-
use crate::clojure_std;
66
use crate::symbol::Symbol;
77
use crate::value::{ToValue, Value};
88

@@ -109,7 +109,10 @@ impl Environment {
109109
environment.insert(Symbol::intern("eval"), eval_fn.to_rc_value());
110110

111111
// Thread namespace TODO / instead of _
112-
environment.insert(Symbol::intern("Thread_sleep"), thread_sleep_fn.to_rc_value());
112+
environment.insert(
113+
Symbol::intern("Thread_sleep"),
114+
thread_sleep_fn.to_rc_value(),
115+
);
113116

114117
environment.insert(Symbol::intern("System_nanotime"), nanotime_fn.to_rc_value());
115118

@@ -128,7 +131,7 @@ impl Environment {
128131
lexical_eval_fn.to_rc_value(),
129132
);
130133
environment.insert(Symbol::intern("nth"), nth_fn.to_rc_value());
131-
environment.insert(Symbol::intern("assoc"), assoc_fn.to_rc_value());
134+
environment.insert(Symbol::intern("assoc"), assoc_fn.to_rc_value());
132135
environment.insert(Symbol::intern("concat"), concat_fn.to_rc_value());
133136
environment.insert(
134137
Symbol::intern("print-string"),

src/error_message.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@ use crate::value::Value;
44
pub fn type_mismatch(expected: TypeTag, got: &Value) -> Value {
55
Value::Condition(format!(
66
"Type mismatch; Expected instance of {}, Recieved type {}",
7-
expected,
8-
got
7+
expected, got
98
))
109
}
1110

1211
pub fn wrong_arg_count(expected: usize, got: usize) -> Value {
1312
Value::Condition(format!(
1413
"Wrong number of arguments given to function (Given: {}, Expected: {})",
15-
got,
16-
expected
14+
got, expected
1715
))
1816
}
1917

2018
pub fn wrong_varg_count(expected: &[usize], got: usize) -> Value {
2119
Value::Condition(format!(
2220
"Wrong number of arguments given to function (Given: {}, Expected: {:?})",
23-
got,
24-
expected
21+
got, expected
2522
))
2623
}
2724

2825
pub fn zero_arg_count(got: usize) -> Value {
2926
Value::Condition(format!(
30-
"Wrong number of arguments given to function (Given: {})", got))
27+
"Wrong number of arguments given to function (Given: {})",
28+
got
29+
))
3130
}
3231

3332
pub fn index_out_of_bounds(ind: usize, count: usize) -> Value {

src/keyword.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ use std::hash::Hash;
44

55
#[derive(Hash, PartialEq, Eq, Clone, Debug)]
66
pub struct Keyword {
7-
// In Clojure proper, a Keyword wraps a Symbol to share their ..symbolic functionality
7+
// In Clojure proper, a Keyword wraps a Symbol to share their ..symbolic functionality
88
pub sym: Symbol,
99
}
1010
impl Keyword {
1111
pub fn intern(name: &str) -> Keyword {
1212
Keyword {
13-
sym: Symbol {
14-
name: String::from(name),
15-
}
16-
}
13+
sym: Symbol {
14+
name: String::from(name),
15+
},
16+
}
1717
}
1818
}
1919
impl fmt::Display for Keyword {

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
extern crate nom;
33
extern crate itertools;
44

5+
mod clojure_std;
56
mod environment;
7+
mod error_message;
68
mod ifn;
9+
mod keyword;
710
mod lambda;
811
mod maps;
912
mod namespace;
@@ -13,13 +16,10 @@ mod persistent_vector;
1316
mod reader;
1417
mod repl;
1518
mod rust_core;
16-
mod clojure_std;
1719
mod symbol;
18-
mod keyword;
1920
mod type_tag;
2021
mod util;
2122
mod value;
22-
mod error_message;
2323

2424
fn main() {
2525
//

src/reader.rs

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ use nom::{
1313
Err::Incomplete, IResult, Needed,
1414
};
1515

16+
use crate::keyword::Keyword;
1617
use crate::maps::MapEntry;
1718
use crate::persistent_list::ToPersistentList;
1819
use crate::persistent_list_map::ToPersistentListMap;
1920
use crate::persistent_vector::ToPersistentVector;
2021
use crate::symbol::Symbol;
21-
use crate::keyword::Keyword;
2222
use crate::value::{ToValue, Value};
2323
use std::rc::Rc;
2424

25-
use std::io::BufRead;
26-
use nom::Err::Error;
2725
use nom::error::ErrorKind;
26+
use nom::Err::Error;
27+
use std::io::BufRead;
2828
//
2929
// Note; the difference between ours 'parsers'
3030
// identifier_parser
@@ -78,7 +78,7 @@ fn cons_str(head: char, tail: &str) -> String {
7878
////////////////////////////////////////////////////////////////////////////////////////////////////
7979

8080
////////////////////////////////////////////////////////////////////////////////////////////////////
81-
//
81+
//
8282
// Predicates
8383
//
8484
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -150,12 +150,12 @@ fn is_clojure_whitespace(c: char) -> bool {
150150
c.is_whitespace() || c == ','
151151
}
152152
////////////////////////////////////////////////////////////////////////////////////////////////////
153-
// End predicates
153+
// End predicates
154154
////////////////////////////////////////////////////////////////////////////////////////////////////
155155

156156
///////////////////////////////////////////////////////////////////////////////////////////////////////
157-
//
158-
// Parsers
157+
//
158+
// Parsers
159159
//
160160
//////////////////////////////////////////////////////////////////////////////////////////////////////
161161

@@ -290,32 +290,31 @@ pub fn try_read_i32(input: &str) -> IResult<&str, Value> {
290290
/// false => Value::Boolean(false)
291291
pub fn try_read_bool(input: &str) -> IResult<&str, Value> {
292292
named!(bool_parser<&str,&str>, alt!( tag!("true") | tag!("false")));
293-
let (rest_input,bool) = bool_parser(input)?;
293+
let (rest_input, bool) = bool_parser(input)?;
294294
Ok((rest_input, Value::Boolean(bool.parse().unwrap())))
295295
}
296296

297-
298297
/// Tries to parse &str into Value::double
299298
///
300299
pub fn try_read_f64(input: &str) -> IResult<&str, Value> {
301300
to_value_parser(double_parser)(input)
302301
}
303302

304303
// Perhaps generalize this into reader macros
305-
/// Tries to parse &str into Value::Keyword
304+
/// Tries to parse &str into Value::Keyword
306305
/// Example Successes:
307306
/// :a => Value::Keyword(Keyword { sym: Symbol { name: "a" })
308-
/// :cat-dog => Value::Keyword(Keyword { sym: Symbol { name: "cat-dog" })
307+
/// :cat-dog => Value::Keyword(Keyword { sym: Symbol { name: "cat-dog" })
309308
/// Example Failures:
310-
/// :12 :'a
309+
/// :12 :'a
311310
pub fn try_read_keyword(input: &str) -> IResult<&str, Value> {
312311
named!(keyword_colon<&str, &str>, preceded!(consume_clojure_whitespaces_parser, tag!(":")));
313312

314313
let (rest_input, _) = keyword_colon(input)?;
315-
let (rest_input,symbol) = symbol_parser(rest_input)?;
314+
let (rest_input, symbol) = symbol_parser(rest_input)?;
316315

317316
let keyword_value = Keyword { sym: symbol }.to_value();
318-
Ok((rest_input,keyword_value))
317+
Ok((rest_input, keyword_value))
319318
}
320319

321320
/// Tries to parse &str into Value::Symbol
@@ -421,28 +420,34 @@ pub fn try_read_list(input: &str) -> IResult<&str, Value> {
421420
pub fn try_read_quoted(input: &str) -> IResult<&str, Value> {
422421
named!(quote<&str, &str>, preceded!(consume_clojure_whitespaces_parser, tag!("'")));
423422

424-
let (form,_) = quote(input)?;
423+
let (form, _) = quote(input)?;
425424

426-
let (rest_input,quoted_form_value) = try_read(form)?;
425+
let (rest_input, quoted_form_value) = try_read(form)?;
427426

428-
// (quote value)
429-
Ok((rest_input,
430-
vec![Symbol::intern("quote").to_rc_value(),
431-
quoted_form_value .to_rc_value()].into_list().to_value()))
427+
// (quote value)
428+
Ok((
429+
rest_input,
430+
vec![
431+
Symbol::intern("quote").to_rc_value(),
432+
quoted_form_value.to_rc_value(),
433+
]
434+
.into_list()
435+
.to_value(),
436+
))
432437
}
433438

434439
pub fn try_read(input: &str) -> IResult<&str, Value> {
435440
preceded(
436441
consume_clojure_whitespaces_parser,
437442
alt((
438-
try_read_quoted,
443+
try_read_quoted,
439444
try_read_map,
440445
try_read_string,
441446
try_read_f64,
442447
try_read_i32,
443448
try_read_bool,
444449
try_read_symbol,
445-
try_read_keyword,
450+
try_read_keyword,
446451
try_read_list,
447452
try_read_vector,
448453
)),
@@ -454,7 +459,7 @@ pub fn try_read(input: &str) -> IResult<&str, Value> {
454459

455460
////////////////////////////////////////////////////////////////////////////////////////////////////
456461
//
457-
// Readers
462+
// Readers
458463
//
459464
///////////////////////////////////////////////////////////////////////////////////////////////////
460465

@@ -594,7 +599,7 @@ mod tests {
594599
}
595600

596601
mod integer_parser_tests {
597-
use crate::reader::{integer_parser};
602+
use crate::reader::integer_parser;
598603

599604
#[test]
600605
fn integer_parser_parses_integer_one() {
@@ -623,8 +628,8 @@ mod tests {
623628
}
624629

625630
mod try_read_bool_tests {
626-
use crate::value::Value;
627631
use crate::reader::try_read_bool;
632+
use crate::value::Value;
628633

629634
#[test]
630635
fn try_read_boolean_true_test() {
@@ -633,7 +638,10 @@ mod tests {
633638

634639
#[test]
635640
fn try_read_boolean_false_test() {
636-
assert_eq!(Value::Boolean(false), try_read_bool("false ").ok().unwrap().1);
641+
assert_eq!(
642+
Value::Boolean(false),
643+
try_read_bool("false ").ok().unwrap().1
644+
);
637645
}
638646
}
639647

@@ -743,18 +751,12 @@ mod tests {
743751

744752
#[test]
745753
fn try_read_bool_true_test() {
746-
assert_eq!(
747-
Value::Boolean(true),
748-
try_read("true ").ok().unwrap().1
749-
)
754+
assert_eq!(Value::Boolean(true), try_read("true ").ok().unwrap().1)
750755
}
751756

752757
#[test]
753758
fn try_read_bool_false_test() {
754-
assert_eq!(
755-
Value::Boolean(false),
756-
try_read("false ").ok().unwrap().1
757-
)
759+
assert_eq!(Value::Boolean(false), try_read("false ").ok().unwrap().1)
758760
}
759761
}
760762

@@ -776,7 +778,10 @@ mod tests {
776778
#[test]
777779
fn consume_whitespaces_from_input_no_whitespace() {
778780
let s = "1, 2, 3";
779-
assert_eq!(Some(("1, 2, 3", ())), consume_clojure_whitespaces_parser(&s).ok());
781+
assert_eq!(
782+
Some(("1, 2, 3", ())),
783+
consume_clojure_whitespaces_parser(&s).ok()
784+
);
780785
}
781786
}
782787

0 commit comments

Comments
 (0)