From 2f48e512447e086f46888fb448b748d9197d3237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 12 May 2020 05:09:13 +0200 Subject: [PATCH] Refactor parsing input statement terminator --- src/input/specification.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/input/specification.rs b/src/input/specification.rs index 25a95d3..45d58e1 100644 --- a/src/input/specification.rs +++ b/src/input/specification.rs @@ -212,6 +212,22 @@ fn predicate_arity_specifier<'i>(mut input: &'i str) } } +fn expect_statement_terminator<'i>(mut input: &'i str) -> Result<&'i str, crate::Error> +{ + input = input.trim_start(); + + let mut input_characters = input.chars(); + + if input_characters.next() != Some('.') + { + return Err(crate::Error::new_missing_statement_terminator()) + } + + input = input_characters.as_str(); + + Ok(input) +} + fn input_statement_body<'i>(mut input: &'i str, problem: &crate::Problem) -> Result<&'i str, crate::Error> { @@ -288,18 +304,7 @@ fn input_statement_body<'i>(mut input: &'i str, problem: &crate::Problem) } } - input = input.trim_start(); - - let mut input_characters = input.chars(); - - if input_characters.next() != Some('.') - { - return Err(crate::Error::new_missing_statement_terminator()) - } - - input = input_characters.as_str(); - - Ok(input) + expect_statement_terminator(input) } pub(crate) fn parse_specification(mut input: &str, problem: &crate::Problem)