Refactor parsing input statement terminator

This commit is contained in:
Patrick Lühne 2020-05-12 05:09:13 +02:00
parent 0d63a721c7
commit 2f48e51244
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF

View File

@ -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) fn input_statement_body<'i>(mut input: &'i str, problem: &crate::Problem)
-> Result<&'i str, crate::Error> -> 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(); expect_statement_terminator(input)
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)
} }
pub(crate) fn parse_specification(mut input: &str, problem: &crate::Problem) pub(crate) fn parse_specification(mut input: &str, problem: &crate::Problem)