diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dc63a97c9def747a2fcafbeddcaad172458c0a15..6d656420027821ec9b02cff1c8acee3ae2bde677 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,12 @@ cache: - cargo/ - target/ +format: + script: + - rustup default nightly + - rustup component add rustfmt + - cargo +nightly fmt --all -- --check + linux: image: 'rust:1.31.0' script: diff --git a/Makefile b/Makefile index 491a7daea077fd23fba3474bc7356301522f43af..0db018dc456298b22f1151e216adc28370f32bcd 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,9 @@ clean: distclean: clean rm -rf vendor vendor.tar.xz .cargo git_revision.txt +format: + cargo +nightly fmt --all + tests: cargo +$(TOOLCHAIN) test $(ARGSV) TOOLCHAIN=$(TOOLCHAIN) bash examples/run_examples.sh diff --git a/members/ranges/src/parse.rs b/members/ranges/src/parse.rs index bf746a7d04ce4ff9943b38ff35df986f83784acc..6503d83007b3d74ada5c1589261e93e10027725f 100644 --- a/members/ranges/src/parse.rs +++ b/members/ranges/src/parse.rs @@ -97,8 +97,13 @@ fn count_minimum_digits(a: &str) -> usize { 0 } -fn finish(inclusive: bool, start_str: &str, end_str: &str, step: isize) -> Option<Box<Iterator<Item = small::String>>> { - if let (Ok(start), Ok(end)) = (start_str.parse::<isize>(), end_str.parse::<isize>()) { +fn finish( + inclusive: bool, + start_str: &str, + end_str: &str, + step: isize, +) -> Option<Box<Iterator<Item = small::String>>> { + if let (Ok(start), Ok(end)) = (start_str.parse::<isize>(), end_str.parse::<isize>()) { let step = if step == 1 && start >= end { -step } else { step }; let nb_digits = usize::max(count_minimum_digits(start_str), count_minimum_digits(end_str)); numeric_range(start, end, step, inclusive, nb_digits) diff --git a/src/lib/parser/quotes.rs b/src/lib/parser/quotes.rs index e85c0625cfc0229064b1fdb9e37b45a33e5f74b2..d3275de5e115b7694d5f0761b8963c6a906b0655 100644 --- a/src/lib/parser/quotes.rs +++ b/src/lib/parser/quotes.rs @@ -177,7 +177,7 @@ impl<I: Iterator<Item = u8>> Terminator<I> { .filter(|&c| ![b' ', b'\n'].contains(c)) .is_none() => { - return self.inner.find(|&c| c == b'\n') + return self.inner.find(|&c| c == b'\n'); } b'\\' => { if self.inner.peek() == Some(&b'\n') { diff --git a/src/lib/parser/statement/parse.rs b/src/lib/parser/statement/parse.rs index 8a68a3bf3eff3fca351afb467d3c5fabf037503f..c1c81114063e0a2a73ffe52b39f594011bac3261 100644 --- a/src/lib/parser/statement/parse.rs +++ b/src/lib/parser/statement/parse.rs @@ -38,16 +38,18 @@ pub(crate) fn parse(code: &str) -> Statement { eprintln!("ion: syntax error: incomplete control flow statement"); Statement::Error(FAILURE) } - "let" => { - Statement::Let(LocalAction::List) - } + "let" => Statement::Let(LocalAction::List), _ if cmd.starts_with("let ") => { // Split the let expression and ensure that the statement is valid. let (keys, op, vals) = assignment_lexer(cmd[4..].trim_start()); match vals { Some(vals) => { // If the values exist, then the keys and operator also exists. - Statement::Let(LocalAction::Assign(keys.unwrap().into(), op.unwrap(), vals.into())) + Statement::Let(LocalAction::Assign( + keys.unwrap().into(), + op.unwrap(), + vals.into(), + )) } None => { if op.is_none() { @@ -59,16 +61,18 @@ pub(crate) fn parse(code: &str) -> Statement { } } } - "export" => { - Statement::Export(ExportAction::List) - } + "export" => Statement::Export(ExportAction::List), _ if cmd.starts_with("export ") => { // Split the let expression and ensure that the statement is valid. let (keys, op, vals) = assignment_lexer(cmd[7..].trim_start()); match vals { Some(vals) => { // If the values exist, then the keys and operator also exists. - Statement::Export(ExportAction::Assign(keys.unwrap().into(), op.unwrap(), vals.into())) + Statement::Export(ExportAction::Assign( + keys.unwrap().into(), + op.unwrap(), + vals.into(), + )) } None => { if keys.is_none() { @@ -82,19 +86,17 @@ pub(crate) fn parse(code: &str) -> Statement { } } } - _ if cmd.starts_with("if ") => { - Statement::If { - expression: vec![parse(cmd[3..].trim_start())], - success: Vec::new(), - else_if: Vec::new(), - failure: Vec::new(), - mode: 0, - } - } + _ if cmd.starts_with("if ") => Statement::If { + expression: vec![parse(cmd[3..].trim_start())], + success: Vec::new(), + else_if: Vec::new(), + failure: Vec::new(), + mode: 0, + }, "else" => Statement::Else, _ if cmd.starts_with("else") => { let cmd = cmd[4..].trim_start(); - if !cmd.is_empty() && cmd.starts_with("if ") { + if !cmd.is_empty() && cmd.starts_with("if ") { Statement::ElseIf(ElseIf { expression: vec![parse(cmd[3..].trim_start())], success: Vec::new(), @@ -161,10 +163,7 @@ pub(crate) fn parse(code: &str) -> Statement { Statement::Case(Case { value, binding, conditional, statements: Vec::new() }) } _ if cmd.starts_with("match ") => { - Statement::Match { - expression: cmd[6..].trim_start().into(), - cases: Vec::new(), - } + Statement::Match { expression: cmd[6..].trim_start().into(), cases: Vec::new() } } _ if cmd.starts_with("fn ") => { let cmd = cmd[3..].trim_start(); @@ -181,14 +180,12 @@ pub(crate) fn parse(code: &str) -> Statement { let (args, description) = parse_function(&cmd[pos..]); match collect_arguments(args) { - Ok(args) => { - Statement::Function { - description: description.map(small::String::from), - name: name.into(), - args, - statements: Vec::new(), - } - } + Ok(args) => Statement::Function { + description: description.map(small::String::from), + name: name.into(), + args, + statements: Vec::new(), + }, Err(why) => { eprintln!("ion: function argument error: {}", why); Statement::Error(FAILURE)