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 Details

    • ChoiceRule

      public ChoiceRule​(java.lang.String aName)
    • ChoiceRule

      public ChoiceRule​(java.lang.String name, ChoiceRule... rules)
      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

      public boolean setAction​(ParserAction aAction)
    • setParent

      public boolean setParent​(ChoiceRule aParent)
    • addRule

      public boolean addRule​(ChoiceRule aRule)
    • removeRule

      public boolean removeRule​(ChoiceRule aRule)
    • 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

      public ParserAction getAction()
    • getParent

      public ChoiceRule getParent()
    • getRule

      public ChoiceRule getRule​(int index)
    • getRules

      public ChoiceRule[] getRules()
    • numberOfRules

      public int numberOfRules()
    • hasRules

      public boolean hasRules()
    • indexOfRule

      public int indexOfRule​(ChoiceRule aRule)
    • 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

      public boolean add​(ChoiceRule rule)
      Add sub rule
    • add

      public void add​(int i, ChoiceRule rule)
      Add sub rule at specific index
    • get

      public ChoiceRule get​(int index)
      Get sub rule
    • remove

      public ChoiceRule remove​(int index)
      Remove sub rule at specific index
    • indexOf

      public int indexOf​(ChoiceRule rule)
      Index of sub rule
    • remove

      public void remove​(ChoiceRule rule)
      Remove sub rule
    • size

      public int size()
      Size of sub rules.
    • addToken

      public 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.
    • findPosition

      public Position findPosition​(int lookfor, ParserDataPackage data)
      Given an offset this function constructs the Position object using the ParserDataPackage's linenumbers hashmap
    • addAllTokens

      public void addAllTokens​(Token token, Token self)
      For each sub token in the self token, this menthod adds it to the token Token
    • parse

      public int 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). 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

      public ChoiceRule 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 class java.lang.Object