Implement booleans
This commit is contained in:
parent
e6a5c20d42
commit
0fc8506164
@ -4,7 +4,7 @@ mod terms;
|
||||
|
||||
pub(crate) use helpers::word_boundary;
|
||||
pub use names::{function_name, predicate_name, variable_name};
|
||||
pub use terms::{integer, special_integer, string};
|
||||
pub use terms::{boolean, integer, special_integer, string};
|
||||
|
||||
/*
|
||||
use nom::
|
||||
|
@ -10,6 +10,41 @@ use nom::
|
||||
|
||||
use super::word_boundary;
|
||||
|
||||
fn true_(i: &str) -> IResult<&str, crate::Term>
|
||||
{
|
||||
map
|
||||
(
|
||||
terminated
|
||||
(
|
||||
tag("true"),
|
||||
word_boundary,
|
||||
),
|
||||
|_| crate::Term::true_(),
|
||||
)(i)
|
||||
}
|
||||
|
||||
fn false_(i: &str) -> IResult<&str, crate::Term>
|
||||
{
|
||||
map
|
||||
(
|
||||
terminated
|
||||
(
|
||||
tag("false"),
|
||||
word_boundary,
|
||||
),
|
||||
|_| crate::Term::false_(),
|
||||
)(i)
|
||||
}
|
||||
|
||||
pub fn boolean(i: &str) -> IResult<&str, crate::Term>
|
||||
{
|
||||
alt
|
||||
((
|
||||
true_,
|
||||
false_,
|
||||
))(i)
|
||||
}
|
||||
|
||||
pub fn integer(i: &str) -> IResult<&str, crate::Term>
|
||||
{
|
||||
map
|
||||
@ -175,6 +210,24 @@ mod tests
|
||||
use crate::parse::*;
|
||||
use crate::Term;
|
||||
|
||||
#[test]
|
||||
fn parse_boolean()
|
||||
{
|
||||
assert_eq!(boolean("true"), Ok(("", Term::true_())));
|
||||
assert_eq!(boolean("false"), Ok(("", Term::false_())));
|
||||
assert_eq!(boolean("true false"), Ok((" false", Term::true_())));
|
||||
assert_eq!(boolean("false true"), Ok((" true", Term::false_())));
|
||||
assert_eq!(boolean("true,"), Ok((",", Term::true_())));
|
||||
assert_eq!(boolean("false,"), Ok((",", Term::false_())));
|
||||
assert!(boolean("truefalse").is_err());
|
||||
assert!(boolean("falsetrue").is_err());
|
||||
assert!(boolean("truea").is_err());
|
||||
assert!(boolean("falsea").is_err());
|
||||
assert!(boolean("a").is_err());
|
||||
assert!(boolean("-").is_err());
|
||||
assert!(boolean(" ").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_integer()
|
||||
{
|
||||
@ -216,6 +269,9 @@ mod tests
|
||||
assert!(special_integer("0").is_err());
|
||||
assert!(special_integer("10000").is_err());
|
||||
assert!(special_integer("-10000").is_err());
|
||||
assert!(special_integer("-").is_err());
|
||||
assert!(special_integer("+").is_err());
|
||||
assert!(special_integer("a").is_err());
|
||||
assert!(special_integer(" ").is_err());
|
||||
}
|
||||
|
||||
@ -243,5 +299,9 @@ mod tests
|
||||
assert_eq!(string("\"test 🙂 123\""), Ok(("", Term::string("test 🙂 123".to_string()))));
|
||||
assert!(string("\"test 123\"a").is_err());
|
||||
assert!(string("\"test\\i123\"").is_err());
|
||||
assert!(string("\"test").is_err());
|
||||
assert!(string("test").is_err());
|
||||
assert!(string("-").is_err());
|
||||
assert!(string(" ").is_err());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user