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 void
add(int i, ChoiceRule rule)
Add sub rule at specific indexboolean
add(ChoiceRule rule)
Add sub rulevoid
addAllTokens(Token token, Token self)
For each sub token in the self token, this menthod adds it to the token Tokenboolean
addRule(ChoiceRule aRule)
void
addToken(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.void
delete()
ChoiceRule
dontCare()
Don't cares are things like spaces and anonymous rules which arePosition
findPosition(int lookfor, ParserDataPackage data)
Given an offset this function constructs the Position object using the ParserDataPackage's linenumbers hashmapChoiceRule
get(int index)
Get sub ruleParserAction
getAction()
boolean
getDeclared()
boolean
getDontDelete()
java.lang.String
getFirstValue()
For finding the first value of the next terminal in the rule.java.lang.StringBuilder
getFirstValueBuilder()
java.lang.String
getName()
boolean
getNegate()
boolean
getNoSpaces()
boolean
getOptional()
ChoiceRule
getParent()
boolean
getReset()
ChoiceRule
getRule(int index)
ChoiceRule[]
getRules()
boolean
hasRules()
int
indexOf(ChoiceRule rule)
Index of sub ruleint
indexOfRule(ChoiceRule aRule)
boolean
isNoSpaces()
boolean
isOptional()
Computes whether this Rule is optional or not by checking if any of the optional sub rules are optionalint
numberOfRules()
void
optimize()
This function works, however it never called because the recursive decent into theboolean
optimizeCondition()
This function is used in the optimize method to decide whether this rule should be deletedint
parse(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).ChoiceRule
remove(int index)
Remove sub rule at specific indexvoid
remove(ChoiceRule rule)
Remove sub ruleboolean
removeRule(ChoiceRule aRule)
void
resetDeclare()
boolean
setAction(ParserAction aAction)
boolean
setDeclared(boolean aDeclared)
boolean
setDontDelete(boolean aDontDelete)
boolean
setFirstValueBuilder(java.lang.StringBuilder aFirstValueBuilder)
boolean
setName(java.lang.String aName)
boolean
setNegate(boolean aNegate)
boolean
setNoSpaces(boolean aNoSpaces)
boolean
setOptional(boolean aOptional)
boolean
setParent(ChoiceRule aParent)
boolean
setReset(boolean aReset)
void
setSubrules(java.lang.String string)
int
size()
Size of sub rules.java.lang.StringBuilder
toCannotBeString(java.lang.StringBuilder builder)
java.lang.StringBuilder
toDeclareString(java.lang.StringBuilder builder)
java.lang.StringBuilder
toRedoRegexString(java.lang.StringBuilder builder)
java.lang.String
toString()
-
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:
toString
in classjava.lang.Object
-