From 56436776274eed71c2b577580c0570035e661a3b Mon Sep 17 00:00:00 2001 From: projectmoon Date: Fri, 21 May 2021 14:44:03 +0000 Subject: [PATCH] Consolidate dice and variable parsers under parser module. --- src/cofd/dice.rs | 2 +- src/cofd/parser.rs | 4 ++-- src/commands/parser.rs | 2 +- src/cthulhu/dice.rs | 6 +++--- src/cthulhu/parser.rs | 9 ++++----- src/error.rs | 4 ++-- src/lib.rs | 1 - src/logic.rs | 2 +- src/{parser.rs => parser/dice.rs} | 0 src/parser/mod.rs | 2 ++ src/{ => parser}/variables.rs | 0 11 files changed, 16 insertions(+), 16 deletions(-) rename src/{parser.rs => parser/dice.rs} (100%) create mode 100644 src/parser/mod.rs rename src/{ => parser}/variables.rs (100%) diff --git a/src/cofd/dice.rs b/src/cofd/dice.rs index 3b465f3..998fcb3 100644 --- a/src/cofd/dice.rs +++ b/src/cofd/dice.rs @@ -1,6 +1,6 @@ use crate::context::Context; use crate::error::{BotError, DiceRollingError}; -use crate::parser::{Amount, Element, Operator}; +use crate::parser::dice::{Amount, Element, Operator}; use itertools::Itertools; use std::convert::TryFrom; use std::fmt; diff --git a/src/cofd/parser.rs b/src/cofd/parser.rs index 8ca5965..56e10fd 100644 --- a/src/cofd/parser.rs +++ b/src/cofd/parser.rs @@ -1,6 +1,6 @@ use crate::cofd::dice::{DicePool, DicePoolModifiers, DicePoolQuality}; use crate::error::BotError; -use crate::parser::{parse_amounts, DiceParsingError}; +use crate::parser::dice::{parse_amounts, DiceParsingError}; use combine::parser::char::{digit, spaces, string}; use combine::{choice, count, many1, one_of, Parser}; @@ -201,7 +201,7 @@ mod tests { #[test] fn dice_pool_complex_expression_test() { - use crate::parser::*; + use crate::parser::dice::*; let modifiers = DicePoolModifiers::custom(DicePoolQuality::Rote, 3); let amounts = vec![ Amount { diff --git a/src/commands/parser.rs b/src/commands/parser.rs index 8d1d1e1..de96022 100644 --- a/src/commands/parser.rs +++ b/src/commands/parser.rs @@ -19,7 +19,7 @@ use crate::commands::{ use crate::cthulhu::parser::{parse_advancement_roll, parse_regular_roll}; use crate::error::BotError; use crate::help::parse_help_topic; -use crate::variables::parse_set_variable; +use crate::parser::variables::parse_set_variable; use combine::parser::char::{char, letter, space}; use combine::{any, many1, optional, Parser}; use nom::Err as NomErr; diff --git a/src/cthulhu/dice.rs b/src/cthulhu/dice.rs index 6712fee..13444dd 100644 --- a/src/cthulhu/dice.rs +++ b/src/cthulhu/dice.rs @@ -1,8 +1,8 @@ use crate::context::Context; use crate::db::Variables; use crate::error::{BotError, DiceRollingError}; -use crate::parser::{Amount, Element}; -use crate::{logic::calculate_single_die_amount, parser::DiceParsingError}; +use crate::logic::calculate_single_die_amount; +use crate::parser::dice::{Amount, DiceParsingError, Element}; use rand::rngs::StdRng; use rand::Rng; use rand::SeedableRng; @@ -420,7 +420,7 @@ pub async fn advancement_roll( mod tests { use super::*; use crate::db::sqlite::Database; - use crate::parser::{Amount, Element, Operator}; + use crate::parser::dice::{Amount, Element, Operator}; use url::Url; macro_rules! dummy_room { diff --git a/src/cthulhu/parser.rs b/src/cthulhu/parser.rs index 27c5274..59de048 100644 --- a/src/cthulhu/parser.rs +++ b/src/cthulhu/parser.rs @@ -1,5 +1,5 @@ use super::dice::{AdvancementRoll, DiceRoll, DiceRollModifier}; -use crate::parser::DiceParsingError; +use crate::parser::dice::DiceParsingError; //TOOD convert these to use parse_amounts from the common dice code. @@ -30,13 +30,13 @@ pub fn parse_regular_roll(input: &str) -> Result { }?; let modifier = parse_modifier(modifiers_str)?; - let amount = crate::parser::parse_single_amount(amounts_str)?; + let amount = crate::parser::dice::parse_single_amount(amounts_str)?; Ok(DiceRoll { modifier, amount }) } pub fn parse_advancement_roll(input: &str) -> Result { let input = input.trim(); - let amounts = crate::parser::parse_single_amount(input)?; + let amounts = crate::parser::dice::parse_single_amount(input)?; Ok(AdvancementRoll { existing_skill: amounts, @@ -45,9 +45,8 @@ pub fn parse_advancement_roll(input: &str) -> Result