public Rule ParseRule()
{
this.SkipBlankLines();
Token token = this.NextToken();
if (token == null)
return null;
this.PushToken(token);
if (token.Type == TokenType.Name && token.Value == "end")
return null;
this.ParseWordLine("rule");
this.ParseWordLine("when");
IList<Fact> conditions = this.ParseFacts();
this.ParseWordLine("then");
IList<Fact> assertions = this.ParseFacts();
this.ParseWordLine("end");
return new Rule(conditions, assertions);
}
public void ParseSimpleConditionRule() { Parser parser = new Parser(new StreamReader("SimpleComparisonRule.txt")); Rule rule = parser.ParseRule(); Assert.IsNotNull(rule); Assert.IsTrue(rule.Conditions.Contains(new ComparisonFact("Temperature", Comparison.Greater, 37))); Assert.IsTrue(rule.Assertions.Contains(new IsFact("HasFever", true))); Assert.IsNull(parser.ParseRule()); }