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 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

      public boolean setSpacesTerminal​(ChoiceRule aSpacesTerminal)
    • getKey

      public java.lang.String getKey()
    • getOpen

      public java.lang.String getOpen()
    • getClose

      public java.lang.String getClose()
    • getSpacesTerminal

      public ChoiceRule getSpacesTerminal()
    • delete

      public void delete()
      Overrides:
      delete in class ChoiceRule
    • parse

      public 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. 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 class ChoiceRule
    • initialize

      public static void initialize​(java.lang.String input, ParserDataPackage data)
      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 class ChoiceRule
    • getFirstValue

      public java.lang.String getFirstValue()
      the first value of the balanced rule must always be the open key
      Overrides:
      getFirstValue in class ChoiceRule
    • toDeclareString

      public java.lang.StringBuilder toDeclareString​(java.lang.StringBuilder builder)
      Overrides:
      toDeclareString in class ChoiceRule
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class ChoiceRule