Package cruise.umple.parser.rules
Class ChoiceRule
java.lang.Object
cruise.umple.parser.rules.ChoiceRule
- Direct Known Subclasses:
BalancedRule,ChainRule,RepeatableRule,RootRule,Terminal
public class ChoiceRule
extends java.lang.Object
name : [[rule]] ( | [[rule]] )*
The basic parsing rule. Contains the neccassary components for most other parsing rules to function.
The basic structure is 1 -> * Rules.
Its own parse rule choses one of its sub-rules, and tries to parse that one(it does this in order, so it tries sub rule 0 first and 1 second and so on)
Parsing has three basic components, success of sub rules, token construction and then returning the new parse position
Success of subrules in the case of a Choice Rule is dependent on at least one sub rule being successful(not returning -1)
-
Constructor Summary
Constructors Constructor Description ChoiceRule(java.lang.String aName)ChoiceRule(java.lang.String name, ChoiceRule... rules)For ease of use the ... -
Method Summary
Modifier and Type Method Description voidadd(int i, ChoiceRule rule)Add sub rule at specific indexbooleanadd(ChoiceRule rule)Add sub rulevoidaddAllTokens(Token token, Token self)For each sub token in the self token, this menthod adds it to the token TokenbooleanaddRule(ChoiceRule aRule)voidaddToken(Token parent, Token self, int from, int end, ParserDataPackage data)Adds the self token to the parent token with the proper positions set for the self token.voiddelete()ChoiceRuledontCare()Don't cares are things like spaces and anonymous rules which arePositionfindPosition(int lookfor, ParserDataPackage data)Given an offset this function constructs the Position object using the ParserDataPackage's linenumbers hashmapChoiceRuleget(int index)Get sub ruleParserActiongetAction()booleangetDeclared()booleangetDontDelete()java.lang.StringgetFirstValue()For finding the first value of the next terminal in the rule.java.lang.StringBuildergetFirstValueBuilder()java.lang.StringgetName()booleangetNegate()booleangetNoSpaces()booleangetOptional()ChoiceRulegetParent()booleangetReset()ChoiceRulegetRule(int index)ChoiceRule[]getRules()booleanhasRules()intindexOf(ChoiceRule rule)Index of sub ruleintindexOfRule(ChoiceRule aRule)booleanisNoSpaces()booleanisOptional()Computes whether this Rule is optional or not by checking if any of the optional sub rules are optionalintnumberOfRules()voidoptimize()This function works, however it never called because the recursive decent into thebooleanoptimizeCondition()This function is used in the optimize method to decide whether this rule should be deletedintparse(Token token, int from, int max, java.lang.String input, ParserDataPackage data)Tries to parse, if successful, will add a new Token to the token Token (if this rule is not negated).ChoiceRuleremove(int index)Remove sub rule at specific indexvoidremove(ChoiceRule rule)Remove sub rulebooleanremoveRule(ChoiceRule aRule)voidresetDeclare()booleansetAction(ParserAction aAction)booleansetDeclared(boolean aDeclared)booleansetDontDelete(boolean aDontDelete)booleansetFirstValueBuilder(java.lang.StringBuilder aFirstValueBuilder)booleansetName(java.lang.String aName)booleansetNegate(boolean aNegate)booleansetNoSpaces(boolean aNoSpaces)booleansetOptional(boolean aOptional)booleansetParent(ChoiceRule aParent)booleansetReset(boolean aReset)voidsetSubrules(java.lang.String string)intsize()Size of sub rules.java.lang.StringBuildertoCannotBeString(java.lang.StringBuilder builder)java.lang.StringBuildertoDeclareString(java.lang.StringBuilder builder)java.lang.StringBuildertoRedoRegexString(java.lang.StringBuilder builder)java.lang.StringtoString()
-
Constructor Details
-
ChoiceRule
public ChoiceRule(java.lang.String aName) -
ChoiceRule
For ease of use the ... is used here to help the user to input sub rules
-
-
Method Details
-
setName
public boolean setName(java.lang.String aName) -
setNegate
public boolean setNegate(boolean aNegate) -
setAction
-
setParent
-
addRule
-
removeRule
-
setDontDelete
public boolean setDontDelete(boolean aDontDelete) -
setOptional
public boolean setOptional(boolean aOptional) -
setFirstValueBuilder
public boolean setFirstValueBuilder(java.lang.StringBuilder aFirstValueBuilder) -
setDeclared
public boolean setDeclared(boolean aDeclared) -
setReset
public boolean setReset(boolean aReset) -
setNoSpaces
public boolean setNoSpaces(boolean aNoSpaces) -
getName
public java.lang.String getName() -
getNegate
public boolean getNegate() -
getAction
-
getParent
-
getRule
-
getRules
-
numberOfRules
public int numberOfRules() -
hasRules
public boolean hasRules() -
indexOfRule
-
getDontDelete
public boolean getDontDelete() -
getOptional
public boolean getOptional() -
getFirstValueBuilder
public java.lang.StringBuilder getFirstValueBuilder() -
getDeclared
public boolean getDeclared() -
getReset
public boolean getReset() -
getNoSpaces
public boolean getNoSpaces() -
isNoSpaces
public boolean isNoSpaces() -
delete
public void delete() -
add
Add sub rule -
add
Add sub rule at specific index -
get
Get sub rule -
remove
Remove sub rule at specific index -
indexOf
Index of sub rule -
remove
Remove sub rule -
size
public int size()Size of sub rules. -
addToken
Adds the self token to the parent token with the proper positions set for the self token. -
findPosition
Given an offset this function constructs the Position object using the ParserDataPackage's linenumbers hashmap -
addAllTokens
For each sub token in the self token, this menthod adds it to the token Token -
parse
Tries to parse, if successful, will add a new Token to the token Token (if this rule is not negated). Returns the position where the parser was able to get to. So, if the parse started at 9 and parsed the word "word" it would then be at 13 and would return that value. If there is no sub rule which can parse the input, this function will return -1 to indicate a failure. -
dontCare
Don't cares are things like spaces and anonymous rules which are -
isOptional
public boolean isOptional()Computes whether this Rule is optional or not by checking if any of the optional sub rules are optional -
optimize
public void optimize()This function works, however it never called because the recursive decent into the -
optimizeCondition
public boolean optimizeCondition()This function is used in the optimize method to decide whether this rule should be deleted -
getFirstValue
public java.lang.String getFirstValue()For finding the first value of the next terminal in the rule. Within the context of a choice rule this means any of the choices are a possibility -
resetDeclare
public void resetDeclare() -
toDeclareString
public java.lang.StringBuilder toDeclareString(java.lang.StringBuilder builder) -
toRedoRegexString
public java.lang.StringBuilder toRedoRegexString(java.lang.StringBuilder builder) -
toCannotBeString
public java.lang.StringBuilder toCannotBeString(java.lang.StringBuilder builder) -
setSubrules
public void setSubrules(java.lang.String string) -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-