Commit a06be98d authored by Jeremy Soller's avatar Jeremy Soller

Fix formatting

parent 87f7c3ac
Pipeline #2143 failed with stage
in 1 minute and 1 second
......@@ -5,9 +5,9 @@ extern crate decimal;
#[macro_use]
extern crate failure;
extern crate num;
extern crate rand;
#[cfg(test)]
extern crate test;
extern crate rand;
#[cfg(test)]
mod bench;
......
use error::CalcError;
use rand::Rng;
use token::*;
use value::{Value, IR};
use rand::Rng;
const RECURSION_LIMIT: usize = 10;
......@@ -140,15 +140,15 @@ where
}
Token::Dice => {
let f2 = f_expr(&token_list[index + 1..], env)?;
let dice_rolls:i32 = f1.value.as_float()?.into();
let dice_max:i32 = f2.value.as_float()?.into();
let dice_rolls: i32 = f1.value.as_float()?.into();
let dice_max: i32 = f2.value.as_float()?.into();
if dice_rolls < 1 || dice_max < 1 {
return Err(CalcError::ImpossibleDice);
}
let mut dice_result = 0;
let mut rng = rand::thread_rng();
for _i in 0..dice_rolls {
dice_result += rng.gen_range(1, dice_max+1);
dice_result += rng.gen_range(1, dice_max + 1);
}
f1.value = Value::dec(dice_result);
f1.tokens += f2.tokens + 1;
......
......@@ -144,9 +144,8 @@ pub fn tokenize(input: &str) -> Result<Vec<Token>, CalcError> {
while let Some(&c) = chars.peek() {
match c.check_operator() {
OperatorState::Complete => {
tokens.push(
c.operator_type().ok_or_else(|| InvalidOperator(c))?,
);
tokens
.push(c.operator_type().ok_or_else(|| InvalidOperator(c))?);
chars.next();
}
OperatorState::PotentiallyIncomplete => {
......@@ -180,7 +179,6 @@ pub fn tokenize(input: &str) -> Result<Vec<Token>, CalcError> {
return Err(CalcError::UnrecognizedToken(token_string));
}
}
}
}
Ok(tokens)
......@@ -226,12 +224,9 @@ pub fn tokenize_polish(input: &str) -> Result<Vec<Token>, CalcError> {
while let Some(&c) = chars.peek() {
match c.check_operator() {
OperatorState::Complete => {
let token = c
.operator_type()
.ok_or_else(|| InvalidOperator(c))?;
if token != Token::OpenParen
&& token != Token::CloseParen
{
let token =
c.operator_type().ok_or_else(|| InvalidOperator(c))?;
if token != Token::OpenParen && token != Token::CloseParen {
operators.push(token);
}
chars.next();
......@@ -266,17 +261,17 @@ pub fn tokenize_polish(input: &str) -> Result<Vec<Token>, CalcError> {
if c.is_whitespace() {
chars.next();
} else if c.is_alphabetic() {
values.push(PolishValue::Atom(consume_atom(&mut chars)));
values
.push(PolishValue::Atom(consume_atom(&mut chars)));
break;
} else if c.is_digit(16) || c == '.' {
values.push(PolishValue::Number(consume_number(&mut chars)?));
values.push(PolishValue::Number(consume_number(
&mut chars,
)?));
break;
} else {
let token_string =
consume_until_new_token(&mut chars);
return Err(CalcError::UnrecognizedToken(
token_string,
));
let token_string = consume_until_new_token(&mut chars);
return Err(CalcError::UnrecognizedToken(token_string));
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment