Class Rule.Builder

java.lang.Object
quickparse.grammar.Rule.Builder
Enclosing class:
Rule

public static class Rule.Builder
extends java.lang.Object
Class that implements the Builder creational design pattern, that is used to build new rules.
  • Method Summary

    Modifier and Type Method Description
    Rule build()
    Builds the rule.
    Rule.Builder construct​(java.lang.String name)
    Specifies a construct to insert in the body of the rule.
    Rule produces​(java.lang.String... symbols)
    Sets the list of symbols that compose the head construct of the rule.
    Invoking this method is equivalent to invoke one or more times the construct(String) and the token(String, String) methods, and then invoking the build() method to tget the rule.

    An invocation of this method must be done by coding the symbols as plain strings: a Construct Symbol is specified by simply indicating the name of the symbol as string (e.g., "if" or "else"); a Token Symbol is specified by indicating the name of the symbol, followed by a colon and a regular expression that matches it (e.g., "var_name:[a-zA-Z][a-zA-Z0-9\_]*", for a Java variable name) This method can be helpful to simplify the definition of a grammar directly in the code and to render it more readable by humans, respect to invoking many and many times the construct(String) and the token(String, String) methods in the same grammar.
    Rule.Builder token​(java.lang.String name, java.lang.String pattern)
    Specifies a token to insert in the body of the rule.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • produces

      public Rule produces​(java.lang.String... symbols)
      Sets the list of symbols that compose the head construct of the rule.
      Invoking this method is equivalent to invoke one or more times the construct(String) and the token(String, String) methods, and then invoking the build() method to tget the rule.

      An invocation of this method must be done by coding the symbols as plain strings:
      • a Construct Symbol is specified by simply indicating the name of the symbol as string (e.g., "if" or "else");
      • a Token Symbol is specified by indicating the name of the symbol, followed by a colon and a regular expression that matches it (e.g., "var_name:[a-zA-Z][a-zA-Z0-9\_]*", for a Java variable name)
      This method can be helpful to simplify the definition of a grammar directly in the code and to render it more readable by humans, respect to invoking many and many times the construct(String) and the token(String, String) methods in the same grammar.
      Parameters:
      symbols - the body symbols
      Returns:
      a new rule
      See Also:
      construct(String), token(String, String)
    • construct

      public Rule.Builder construct​(java.lang.String name)
      Specifies a construct to insert in the body of the rule. A construct is identified by its name only.
      Parameters:
      name - the construct name
      Returns:
      this same builder
    • token

      public Rule.Builder token​(java.lang.String name, java.lang.String pattern)
      Specifies a token to insert in the body of the rule. A token is identified by its name and by its pattern. The pattern of a token is a Regular Expression that is interpreted by the Java Regular Expression framework.
      Parameters:
      name - the token name
      pattern - the Regular Expression that matches the token symbol.
      Returns:
      this same builder
    • build

      public Rule build()
      Builds the rule.
      Returns:
      a new Rule instance