Package com.tnsai.invariants.rules
Class RuleParser
java.lang.Object
com.tnsai.invariants.rules.RuleParser
Parses conditional rule strings into
ConditionalRule objects.
Supports patterns like:
"DEAD if neighbors < 2""DEAD if neighbors < 2 (underpopulation)""ALIVE if neighbors == 3 (reproduction)""unchanged if neighbors == 2 or 3 (stasis)""state = DEAD when currentState == ALIVE && neighbors < 2"
Supported Rule Formats
Format 1: EFFECT if CONDITION Format 2: EFFECT if CONDITION (DESCRIPTION) Format 3: FIELD = VALUE when CONDITION
- Author:
- TnsAI Team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when rule parsing fails. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisConditionalRule(String text) Checks if a string looks like a conditional rule.Parses a single rule string into a ConditionalRule.Parses multiple rules from an array of strings.
-
Constructor Details
-
RuleParser
public RuleParser()
-
-
Method Details
-
parse
Parses a single rule string into a ConditionalRule.- Parameters:
ruleString- the rule string to parse- Returns:
- parsed ConditionalRule
- Throws:
RuleParser.RuleParseException- if parsing fails
-
parseAll
Parses multiple rules from an array of strings.- Parameters:
ruleStrings- array of rule strings- Returns:
- list of parsed ConditionalRules
-
isConditionalRule
Checks if a string looks like a conditional rule.- Parameters:
text- the text to check- Returns:
- true if it appears to be a conditional rule
-