Class Grammar.Builder

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

public static class Grammar.Builder
extends java.lang.Object
Allows the construction of a grammar, rule by rule
  • Constructor Summary

    Constructors 
    Constructor Description
    Builder()  
  • Method Summary

    Modifier and Type Method Description
    Grammar.Builder addRule​(Rule rule)
    Adds a rule to the grammar.
    Grammar.Builder addRule​(Rule.Builder ruleBuilder)
    Adds a new rule to the grammar, taking a rule builder as input.
    Grammar build()
    Builds the grammar.
    Grammar build​(java.lang.String axiom)
    Builds the grammar, setting up the given construct symbol as axiom.
    Grammar.Builder ignorePatterns​(java.lang.String... patterns)
    Adds the given patterns to the ignored ones of the grammar that is being built.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • addRule

      public Grammar.Builder addRule​(Rule.Builder ruleBuilder)
      Adds a new rule to the grammar, taking a rule builder as input. This method invokes the Rule.Builder.build() method on the given rule builder, first. Then, it adds the new rule to the grammar.
      Parameters:
      ruleBuilder - a rule builder
      Returns:
      this same builder
    • addRule

      public Grammar.Builder addRule​(Rule rule)
      Adds a rule to the grammar.
      Parameters:
      rule - the rule to add.
      Returns:
      this same builder
    • ignorePatterns

      public Grammar.Builder ignorePatterns​(java.lang.String... patterns)
      Adds the given patterns to the ignored ones of the grammar that is being built.
      Parameters:
      patterns - the patterns the grammar must ignore
      Returns:
      this same builder
    • build

      public Grammar build()
      Builds the grammar. This method sets the axiom of the grammar to be the head of the first rule added to the builder.
      Returns:
      the new grammar
    • build

      public Grammar build​(java.lang.String axiom)
      Builds the grammar, setting up the given construct symbol as axiom. This method is useful if and only if when the head of the fist rule added to the grammar is not the axiom.
      Parameters:
      axiom - the string representation of the construct symbol that must be set as axiom for the grammar
      Returns:
      the new grammar