Class Terminal

java.lang.Object
cruise.umple.parser.rules.ChoiceRule
cruise.umple.parser.rules.Terminal

public class Terminal
extends ChoiceRule
Terminals are the only rules that actually don't use sub rules, instead, they use regex to compute whether there is a successful parse. for example if the parse position is at "String name;" the terminal which was created with the ~ (alphanumeric) symbol, will parse the String(excluding whitespace) and will return the position so that the next parse position will be "name;"
  • Constructor Details

    • Terminal

      public Terminal​(java.lang.String aName, java.lang.String aRegex)
    • Terminal

      public Terminal​(java.lang.String name, java.lang.String regex, boolean mustSpace)
      mustSpace being true makes sure that there is a space after the regex, false means that there is optional space.
  • Method Details

    • setRegex

      public boolean setRegex​(java.lang.String aRegex)
    • setCannotBe

      public boolean setCannotBe​(java.lang.String aCannotBe)
    • setCannotBePattern

      public boolean setCannotBePattern​(java.util.regex.Pattern aCannotBePattern)
    • setPattern

      public boolean setPattern​(java.util.regex.Pattern aPattern)
    • setPattern2

      public boolean setPattern2​(java.util.regex.Pattern aPattern2)
    • setOnlyValue

      public boolean setOnlyValue​(boolean aOnlyValue)
    • setOptional

      public boolean setOptional​(boolean aOptional)
      Overrides:
      setOptional in class ChoiceRule
    • setLookBack

      public boolean setLookBack​(boolean aLookBack)
    • setCanBeNull

      public boolean setCanBeNull​(boolean aCanBeNull)
    • setStrictRegex

      public boolean setStrictRegex​(boolean aStrictRegex)
    • setFollowingOptional

      public boolean setFollowingOptional​(boolean aFollowingOptional)
    • setFollowing

      public boolean setFollowing​(java.lang.String aFollowing)
    • setCannotHaveNewline

      public boolean setCannotHaveNewline​(boolean aCannotHaveNewline)
    • setMustHaveSpaceFollowing

      public boolean setMustHaveSpaceFollowing​(boolean aMustHaveSpaceFollowing)
    • getRegex

      public java.lang.String getRegex()
      the inner regex(i.e. not the whitespace considerations or the neccessary trailing .*
    • getCannotBe

      public java.lang.String getCannotBe()
      A regex which, if matched by the parse, will cause the terminal to return -1(Failure). This is useful for such cases as a rolename consuming the "sorted" token
    • getCannotBePattern

      public java.util.regex.Pattern getCannotBePattern()
      The pattern associated to the cannotBe attribute
    • getPattern

      public java.util.regex.Pattern getPattern()
      The main pattern, which is checked first for passing
    • getPattern2

      public java.util.regex.Pattern getPattern2()
      Usually null except in the case where you have a premodifier-less token [token] and then an optional rule of some kind, which means that the first parse should try to parse as if the second rule is present, that is the regex becomes regex+nextRule.getFirstValue()
    • getOnlyValue

      public boolean getOnlyValue()
      If true this is a STATIC token, which are things like braces and keywords
    • getOptional

      public boolean getOptional()
      isOptional will return this value for Terminal
      Overrides:
      getOptional in class ChoiceRule
    • getLookBack

      public boolean getLookBack()
      (not used)
    • getCanBeNull

      public boolean getCanBeNull()
      for determining whether "" is an acceptable parse
    • getStrictRegex

      public boolean getStrictRegex()
    • getFollowingOptional

      public boolean getFollowingOptional()
    • getFollowing

      public java.lang.String getFollowing()
    • getCannotHaveNewline

      public boolean getCannotHaveNewline()
    • getMustHaveSpaceFollowing

      public boolean getMustHaveSpaceFollowing()
    • delete

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

      public int parse​(Token token, int from, int max, java.lang.String input, ParserDataPackage data)
      Returns the result of the regex matching the input string. Where the parseResult is the futurthest including spaces.
      Overrides:
      parse in class ChoiceRule
    • onlyValue

      public ChoiceRule onlyValue()
      onlyValue is used for determining if the terminal is a token or a STATIC.
    • space

      public static void space​(java.lang.String string)
      to set the space (for the grammar it's " \t", for the UmpleGrammar " \t\n"
    • isOptional

      public boolean isOptional()
      returns optional
      Overrides:
      isOptional in class ChoiceRule
    • getFirstValue

      public java.lang.String getFirstValue()
      Description copied from class: ChoiceRule
      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
      Overrides:
      getFirstValue in class ChoiceRule
    • redoRegex

      public void redoRegex​(java.lang.String regex)
      re-initializes the regex
    • redoRegex

      public void redoRegex​(java.lang.String regex, java.lang.String following, boolean optional)
      re-initializes the regex with a given value that can follow the regex(this value should be commuted with getFirstValue).
    • cannotHaveNewline

      public void cannotHaveNewline()
      This function removes the argument string from the regex
    • toDeclareString

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

      public java.lang.StringBuilder toRedoRegexString​(java.lang.StringBuilder builder)
      Overrides:
      toRedoRegexString in class ChoiceRule
    • toCannotBeString

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

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