Class ModelUtility.Rule

java.lang.Object
net.ssehub.easy.dslCore.ModelUtility.Rule
Enclosing class:
ModelUtility<E extends org.eclipse.emf.ecore.EObject,R extends net.ssehub.easy.basics.modelManagement.IModel>

protected static class ModelUtility.Rule extends Object
Cutoff parser rule. All rules are matched in sequence until no rule matches. This is the cutoff point.
Author:
Holger Eichelberger
  • Field Details

    • firsts

      private String[] firsts
    • follows

      private String[] follows
    • terminates

      private String[] terminates
    • optional

      private boolean optional
    • multi

      private boolean multi
    • includesFollows

      private boolean includesFollows
  • Constructor Details

    • Rule

      public Rule(String firsts, String follows)
      Creates a non-optional single-match rule.
      Parameters:
      firsts - the leading keywords, may be multiple alternative ones separated by "|"
      follows - the follow symbols, may be multiple alternative ones separated by "|", may be null to use the following rules
    • Rule

      public Rule(String firsts)
      Creates a non-optional single-match rule with self-setting follows.
      Parameters:
      firsts - the leading keywords, may be multiple alternative ones separated by "|"
    • Rule

      public Rule(String firsts, boolean optional, boolean multi)
      Creates rule with self-setting follows.
      Parameters:
      firsts - the leading keywords, may be multiple alternative ones separated by "|"
      optional - is the rule optional
      multi - is this a multiple matching rule
    • Rule

      public Rule(String firsts, String follows, boolean optional, boolean multi)
      Creates rule.
      Parameters:
      firsts - the leading keywords, may be multiple alternative ones separated by "|"
      follows - the follow symbols, may be multiple alternative ones separated by "|", may be null to use the following rules
      optional - is the rule optional
      multi - is this a multiple matching rule
  • Method Details

    • setFollows

      private void setFollows(String follows)
      Sets the follow symbols.
      Parameters:
      follows - the follow symbols, may be multiple alternative ones separated by "|", may be null to use the following rules
    • terminates

      public ModelUtility.Rule terminates(String terminates)
      Additional optional terminating terminals. Matches like follows but if one of those, considers as part of the current match.
      Parameters:
      terminates - the terminating symbols, may be multiple alternative ones separated by "|", may be null for none
      Returns:
      this for chaining
    • split

      private String[] split(String symbols)
      Splits symbols.
      Parameters:
      symbols - the symbols given as single or multiple alternative, separated by "|" or null
      Returns:
      the splitted symbols, null if symbols was null
    • matches

      private boolean matches(List<String> parts)
      Does this rule match on the given collected parts.
      Parameters:
      parts - the parts
      Returns:
      true for match, false else
    • matchesFirst

      private boolean matchesFirst(String text, String[] firsts)
      Returns whether text starts by one of the firsts.
      Parameters:
      text - the text to match
      firsts - the firsts
      Returns:
      true for match, false else
    • matchesFollow

      private boolean matchesFollow(String text, String[] follows)
      Returns whether text ends by one of the follows.
      Parameters:
      text - the text to match
      follows - the follows
      Returns:
      true for match, false else
    • canMatch

      private boolean canMatch(List<String> parts)
      Does this rule match at all. Must be consistent with matches(List).
      Parameters:
      parts - the parts
      Returns:
      true for potential match, false else
    • isOptional

      private boolean isOptional()
      Is this rule optional?
      Returns:
      true for optional, false else
    • isMulti

      private boolean isMulti()
      May this rule match multiple times?
      Returns:
      true for multi-match, false else
    • instantiate

      public static ModelUtility.Rule[] instantiate(ModelUtility.Rule[] rules, boolean copy)
      Returns rules or an instantiated rule sequence to be used for matching if follows is not defined - then fill it with the firsts of the next rules until a mandatory rule comes up.
      Parameters:
      rules - the rules
      copy - whether the original array and rules shall be returned or whether a new array with potentially the same or instantiated rules shall be returned
      Returns:
      this or an intantiated version
    • instantiate

      public static ModelUtility.Rule[] instantiate(ModelUtility.Rule... rules)
      Shortcut default instantiation of rules.
      Parameters:
      rules - the rules to be instantiated
      Returns:
      the instantiated rules
    • clear

      private void clear(List<String> parts)
      Clears a matched parts list.
      Parameters:
      parts - the parts to clear
    • toString

      public String toString()
      Overrides:
      toString in class Object