Default to 0-ary predicates when omitting arity

This commit is contained in:
Patrick Lühne 2020-02-05 19:42:53 +01:00
parent b6ecf37211
commit ca5cca8701
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 4 additions and 8 deletions

View File

@ -15,7 +15,7 @@ enum Command
#[structopt(long, default_value = "human-readable")]
output_format: anthem::output::Format,
/// Input predicates (examples: p/0, q/2)
/// Input predicates (examples: p, q/2)
#[structopt(long, parse(try_from_str = anthem::parse_predicate_declaration))]
input_predicates: Vec<std::rc::Rc<foliage::PredicateDeclaration>>,

View File

@ -52,11 +52,7 @@ pub fn parse_predicate_declaration(input: &str)
{
let mut parts = input.split("/");
let name = match parts.next()
{
Some(name) => name.to_string(),
None => return Err(crate::Error::new_parse_predicate_declaration()),
};
let name = parts.next().ok_or(crate::Error::new_parse_predicate_declaration())?;
use std::str::FromStr;
@ -64,7 +60,7 @@ pub fn parse_predicate_declaration(input: &str)
{
Some(arity)
=> usize::from_str(arity).map_err(|_| crate::Error::new_parse_predicate_declaration())?,
None => return Err(crate::Error::new_parse_predicate_declaration()),
None => 0,
};
if parts.next().is_some()
@ -74,7 +70,7 @@ pub fn parse_predicate_declaration(input: &str)
Ok(std::rc::Rc::new(foliage::PredicateDeclaration
{
name,
name: name.to_string(),
arity,
}))
}