Package cruise.umple.parser.rules
Class ChainRule
java.lang.Object
cruise.umple.parser.rules.ChoiceRule
cruise.umple.parser.rules.ChainRule
public class ChainRule extends ChoiceRule
name : [[rule]] [[rule]]*
Similar to the Choice rule, except all sub rules must be successful when parsing(similar to an 'and' being performed on a hypotheical "isSuccess" for each rule)
Because of the possibility for subrules to be optional, this Rule type must support back tracking, where after a failure, the rule will remove tokens from the growing return token when it needs to reconsider a sub rule as being parsable.
-
Constructor Summary
Constructors Constructor Description ChainRule(java.lang.String aName)
ChainRule(java.lang.String name, ChoiceRule... rules)
Overriding the corresponding constructor -
Method Summary
Modifier and Type Method Description void
delete()
java.lang.String
getFirstValue()
Within the context of a chain rule this function means the very first rule's value, and if that rule is optional, the or of the next one, and so on.boolean
isOptional()
If there exists a subrule that is not optional, this function will return false, otherwise it will return true(i.e.int
parse(Token token, int from, int max, java.lang.String input, ParserDataPackage data)
If each of the subtokens positively parses then this method will return the result of the last parsed sub ruled.Methods inherited from class cruise.umple.parser.rules.ChoiceRule
add, add, addAllTokens, addRule, addToken, dontCare, findPosition, get, getAction, getDeclared, getDontDelete, getFirstValueBuilder, getName, getNegate, getNoSpaces, getOptional, getParent, getReset, getRule, getRules, hasRules, indexOf, indexOfRule, isNoSpaces, numberOfRules, optimize, optimizeCondition, remove, remove, removeRule, resetDeclare, setAction, setDeclared, setDontDelete, setFirstValueBuilder, setName, setNegate, setNoSpaces, setOptional, setParent, setReset, setSubrules, size, toCannotBeString, toDeclareString, toRedoRegexString, toString
-
Constructor Details
-
Method Details
-
delete
public void delete()- Overrides:
delete
in classChoiceRule
-
parse
If each of the subtokens positively parses then this method will return the result of the last parsed sub ruled.- Overrides:
parse
in classChoiceRule
-
isOptional
public boolean isOptional()If there exists a subrule that is not optional, this function will return false, otherwise it will return true(i.e. all sub tokens are optional)- Overrides:
isOptional
in classChoiceRule
-
getFirstValue
public java.lang.String getFirstValue()Within the context of a chain rule this function means the very first rule's value, and if that rule is optional, the or of the next one, and so on.- Overrides:
getFirstValue
in classChoiceRule
-