Package cruise.umple.parser.rules
Class BalancedRule
java.lang.Object
cruise.umple.parser.rules.ChoiceRule
cruise.umple.parser.rules.BalancedRule
public class BalancedRule extends ChoiceRule
Balanced rules ensure that braces are balanced, that is, that the corresponding brace is matched.
For example {a {b }c }d 'a' is matched with 'd' and 'b' is matched 'c' instead of a with c
-
Constructor Summary
Constructors Constructor Description BalancedRule(java.lang.String aName)
BalancedRule(java.lang.String name, java.lang.String open, ChoiceRule rule, java.lang.String close)
A balanced rule is of the form "open key" rule "close key", for example: { [[classDefinition]]* } This constructor reflect's that form.BalancedRule(java.lang.String name, java.lang.String open, java.lang.String close)
-
Method Summary
Modifier and Type Method Description void
delete()
java.lang.String
getClose()
java.lang.String
getFirstValue()
the first value of the balanced rule must always be the open keyjava.lang.String
getKey()
java.lang.String
getOpen()
ChoiceRule
getSpacesTerminal()
static void
initialize(java.lang.String input, ParserDataPackage data)
initializes the couples, and puts them into the data packageboolean
isOptional()
Balanced rules are never optional, the way to make them optional is to use a Repeatable rule as their parent.int
parse(Token token, int from, int to, java.lang.String input, ParserDataPackage data)
The parsing of the balanced rule is relies on the commuted couples from the ParserDataPackage.boolean
setClose(java.lang.String aClose)
boolean
setKey(java.lang.String aKey)
boolean
setOpen(java.lang.String aOpen)
boolean
setSpacesTerminal(ChoiceRule aSpacesTerminal)
java.lang.StringBuilder
toDeclareString(java.lang.StringBuilder builder)
java.lang.String
toString()
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, toRedoRegexString
-
Constructor Details
-
BalancedRule
public BalancedRule(java.lang.String aName) -
BalancedRule
public BalancedRule(java.lang.String name, java.lang.String open, ChoiceRule rule, java.lang.String close)A balanced rule is of the form "open key" rule "close key", for example: { [[classDefinition]]* } This constructor reflect's that form. -
BalancedRule
public BalancedRule(java.lang.String name, java.lang.String open, java.lang.String close)
-
-
Method Details
-
setKey
public boolean setKey(java.lang.String aKey) -
setOpen
public boolean setOpen(java.lang.String aOpen) -
setClose
public boolean setClose(java.lang.String aClose) -
setSpacesTerminal
-
getKey
public java.lang.String getKey() -
getOpen
public java.lang.String getOpen() -
getClose
public java.lang.String getClose() -
getSpacesTerminal
-
delete
public void delete()- Overrides:
delete
in classChoiceRule
-
parse
The parsing of the balanced rule is relies on the commuted couples from the ParserDataPackage. The only thing that has to be respected is that there cannot be anything besides the couple's open string first so there cannot be whitespace for this parse to work for example: "{ key }" would work, but " { key }" would not. trailing whitespace is accounted for. This is the only rule that does not account for whitespace before it begins.- Overrides:
parse
in classChoiceRule
-
initialize
initializes the couples, and puts them into the data package -
isOptional
public boolean isOptional()Balanced rules are never optional, the way to make them optional is to use a Repeatable rule as their parent.- Overrides:
isOptional
in classChoiceRule
-
getFirstValue
public java.lang.String getFirstValue()the first value of the balanced rule must always be the open key- Overrides:
getFirstValue
in classChoiceRule
-
toDeclareString
public java.lang.StringBuilder toDeclareString(java.lang.StringBuilder builder)- Overrides:
toDeclareString
in classChoiceRule
-
toString
public java.lang.String toString()- Overrides:
toString
in classChoiceRule
-