Class Rule

java.lang.Object
quickparse.grammar.Rule
All Implemented Interfaces:
java.lang.Comparable<Rule>, java.lang.Iterable<Symbol>

public class Rule
extends java.lang.Object
implements java.lang.Comparable<Rule>, java.lang.Iterable<Symbol>
Represents a grammar production rule. A grammar rule is composed by an head symbol, which is the construct produced by the rule, and a body, which is the list of the construct or token symbols that compose the head construct.
A rule is an iterable object of symbols.
A rule is comparable to other rules, basing on their generality:
  • A rule is more general than another if it has longer body than the other;
  • Two rule that have the same body size, are compared respect to the order in which they have been created.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  Rule.Builder
    Class that implements the Builder creational design pattern, that is used to build new rules.
  • Method Summary

    Modifier and Type Method Description
    int compareTo​(Rule other)  
    boolean equals​(java.lang.Object obj)  
    ConstructSymbol getHead()
    Gets the construct symbol produced by this Rule
    java.util.List<Symbol> getSymbols()
    Gets the production body of this Rule
    int hashCode()  
    static Rule.Builder head​(java.lang.String symbol)
    Creates a new Rule.Builder by initializing it with the given head construct symbol.
    java.util.Iterator<Symbol> iterator()  
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • head

      public static Rule.Builder head​(java.lang.String symbol)
      Creates a new Rule.Builder by initializing it with the given head construct symbol.
      Parameters:
      symbol - the head symbol, which is the construct that the rule produces.
      Returns:
      a new Rule.Builder instance
    • getHead

      public ConstructSymbol getHead()
      Gets the construct symbol produced by this Rule
      Returns:
      a ConstructSymbol instance
    • getSymbols

      public java.util.List<Symbol> getSymbols()
      Gets the production body of this Rule
      Returns:
      the list of symbols that produce the head construct
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • compareTo

      public int compareTo​(Rule other)
      Specified by:
      compareTo in interface java.lang.Comparable<Rule>
    • iterator

      public java.util.Iterator<Symbol> iterator()
      Specified by:
      iterator in interface java.lang.Iterable<Symbol>