Package quickparse.grammar
Class Grammar
java.lang.Object
quickparse.grammar.Grammar
- All Implemented Interfaces:
java.lang.Iterable<Rule>
public class Grammar extends java.lang.Object implements java.lang.Iterable<Rule>
Represents a BNF (Backus-Naur Form) grammar as a set of syntactical rules.
To create a new instance of this class, the method
create() must be used.
A grammar is an iterable object whose elements are the grammar rules.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGrammar.BuilderAllows the construction of agrammar, rule by rule -
Method Summary
Modifier and Type Method Description static Grammar.Buildercreate()Creates a newGrammar.Builderthat allows the construction of a grammar, rule by rule.ConstructSymbolgetAxiom()Gets the axiom of the grammar (i.e., the first symbol from which a parser should start to interpret the grammar)ConstructSymbolgetConstructSymbol(java.lang.String name)Gets theConstructSymbolassociated to the given construct name, if any.java.util.Collection<ConstructSymbol>getConstructSymbols()Gets all the construct symbols that are specified in this grammar.java.util.Set<java.util.regex.Pattern>getIgnoredPatterns()Returns the list of patterns to ignore.java.util.Map<ConstructSymbol,java.util.List<Rule>>getRules()Returns the rules contained in this grammar.java.util.List<Rule>getRules(java.lang.String symbol)Gets all rules used to produce the specified construct (i.e., rules whose head is the specified symbol)java.util.List<Rule>getRules(ConstructSymbol symbol)Gets all rules used to produce the specified construct (i.e., rules whose head is the specified symbol)TokenSymbolgetTokenSymbol(java.lang.String name)Gets theTokenSymbolassociated to the given token name, if any.java.util.Collection<TokenSymbol>getTokenSymbols()Gets all the token symbols that are specified in this grammar.java.util.Iterator<Rule>iterator()java.lang.StringtoString()
-
Method Details
-
getIgnoredPatterns
public java.util.Set<java.util.regex.Pattern> getIgnoredPatterns()Returns the list of patterns to ignore. The ignored patterns usually are spaces and comment patterns (e.g. '//...\n' or '#...\n')- Returns:
- a list of
patterns
-
getRules
Returns the rules contained in this grammar.- Returns:
- A map that associates a
ConstructSymbolto the rules contained in this grammar that produce it.
-
getRules
Gets all rules used to produce the specified construct (i.e., rules whose head is the specified symbol)- Parameters:
symbol- the head of the rules- Returns:
- the list of rules that produce the specified construct
- See Also:
getRules(ConstructSymbol)
-
getRules
Gets all rules used to produce the specified construct (i.e., rules whose head is the specified symbol)- Parameters:
symbol- the head of the rules- Returns:
- the list of rules that produce the specified construct
- See Also:
getRules(String)
-
getTokenSymbols
Gets all the token symbols that are specified in this grammar.- Returns:
- an unmodifiable collection of
TokenSymbol
-
getConstructSymbols
Gets all the construct symbols that are specified in this grammar.- Returns:
- an unmodifiable collection of
ConstructSymbol
-
getTokenSymbol
Gets theTokenSymbolassociated to the given token name, if any.- Parameters:
name- the name of the token- Returns:
- a
TokenSymbolobject
-
getConstructSymbol
Gets theConstructSymbolassociated to the given construct name, if any.- Parameters:
name- the name of the construct- Returns:
- a
ConstructSymbolobject
-
getAxiom
Gets the axiom of the grammar (i.e., the first symbol from which a parser should start to interpret the grammar)- Returns:
- a
ConstructSymbolobject representing the axiom
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
create
Creates a newGrammar.Builderthat allows the construction of a grammar, rule by rule.- Returns:
- a
Grammar.Builderinstance
-
iterator
- Specified by:
iteratorin interfacejava.lang.Iterable<Rule>
-