Introduce the 'true' and 'false' conditions

This commit is contained in:
Nat Lasseter
2020-10-21 19:57:14 +01:00
parent 453f421bae
commit 12e37d4335
4 changed files with 40 additions and 0 deletions
+11
View File
@@ -106,6 +106,10 @@ pub enum Cond {
Eof,
/// Not empty
NotEof,
// Always true, for eg. (else? ...)
True,
/// Always false
False,
}
pub fn parse_cond(text: &str, pos: &SourcePosition) -> Result<Cond, CrsnError> {
@@ -134,6 +138,8 @@ pub fn parse_cond(text: &str, pos: &SourcePosition) -> Result<Cond, CrsnError> {
"neof" => Cond::NotEof,
"ov" => Cond::Overflow,
"nov" => Cond::NotOverflow,
"true" | "always" | "else" => Cond::True,
"false" | "never" => Cond::False,
_ => {
return Err(CrsnError::Parse(format!("Unknown cond: {}", text).into(), pos.clone()));
}
@@ -174,6 +180,8 @@ impl Display for Cond {
Cond::Valid => "valid",
Cond::Eof => "eof",
Cond::NotEof => "neof",
Cond::True => "true",
Cond::False => "false",
})
}
}
@@ -214,6 +222,9 @@ impl Not for Cond {
Cond::NotEof => Cond::Eof,
Cond::Eof => Cond::NotEof,
Cond::True => Cond::False,
Cond::False => Cond::True,
}
}
}
+2
View File
@@ -115,6 +115,8 @@ impl StatusFlags {
Cond::NotEmpty => !self.empty,
Cond::Eof => self.eof,
Cond::NotEof => !self.eof,
Cond::True => true,
Cond::False => false,
}
}