Package quickparse.grammar
Class Rule
java.lang.Object
quickparse.grammar.Rule
public class Rule extends java.lang.Object implements java.lang.Comparable<Rule>, java.lang.Iterable<Symbol>
Represents a
A rule is an iterable object of
A rule is
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 classRule.BuilderClass that implements the Builder creational design pattern, that is used to build newrules. -
Method Summary
Modifier and Type Method Description intcompareTo(Rule other)booleanequals(java.lang.Object obj)ConstructSymbolgetHead()Gets the construct symbol produced by thisRulejava.util.List<Symbol>getSymbols()Gets the production body of thisRuleinthashCode()static Rule.Builderhead(java.lang.String symbol)Creates a newRule.Builderby initializing it with the given head construct symbol.java.util.Iterator<Symbol>iterator()java.lang.StringtoString()
-
Method Details
-
head
Creates a newRule.Builderby 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.Builderinstance
-
getHead
Gets the construct symbol produced by thisRule- Returns:
- a
ConstructSymbolinstance
-
getSymbols
Gets the production body of thisRule -
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
compareTo
- Specified by:
compareToin interfacejava.lang.Comparable<Rule>
-
iterator
- Specified by:
iteratorin interfacejava.lang.Iterable<Symbol>
-