Chapter 3Grammars

3.1Grammar

The org.nineml.coffeegrinder.parser.Grammar class.

This is an abstract class with two implementations: SourceGrammar and ParserGrammar. The source grammar can be updated, the parser grammar is immutable.

3.1.1Field summary

Public fields for the org.nineml.coffeegrinder.parser.Grammar class.

public static final String logcategory = "Grammar"

3.1.2Constructor summary

Public constructors for the org.nineml.coffeegrinder.parser.Grammar class.

public Grammar()

3.1.3Method summary

Public methods on the org.nineml.coffeegrinder.parser.Grammar class.

public Map<String, String> getMetadataProperies()

Gets the metadata properties.

Metadata properties exist solely for annotations by an application.

public String getMetadataProperty(String name)
throws NullPointerException if the name is null

Gets a metadata property.

Metadata properties exist solely for annotations by an application.

public List<Rule> getRules()

Get the rules currently defined in this grammar.

For a ParserGrammar, this is the final set.

public Map<NonterminalSymbol, List> getRulesBySymbol()

Get the rules currently defined in this grammar organized by symbol.

For a ParserGrammar, this is the final set.

public List<Rule> getRulesForSymbol(NonterminalSymbol symbol)

Get the rules currently defined in this grammar for a particular symbol.

For a ParserGrammar, this is the final set.

public Set<NonterminalSymbol> getSymbols()

Get the currently defined nonterminals in the grammar.

For a ParserGrammar, this is the final set.

public boolean isNullable(Symbol symbol)

Is the symbol nullable?

A TerminalSymbol is never nullable.

For a ParserGrammar, the answer is definitive. For an SourceGrammar, a symbol that isn’t currently nullable could become nullable by the addition of more rules.

3.2SourceGrammar

The org.nineml.coffeegrinder.parser.SourceGrammar class.

This class extends org.nineml.coffeegrinder.parser.Grammar.

A grammar is a list of rules. Each rule defines a non-terminal symbol as a sequence of zero or more symbols (terminals or nonterminals).

A grammar can be used to create a parser. The parser will (successfully) parse inputs that match the rules in the grammar.

3.2.1Field summary

Public fields for the org.nineml.coffeegrinder.parser.SourceGrammar class.

public static final String logcategory = "Grammar"

3.2.2Constructor summary

Public constructors for the org.nineml.coffeegrinder.parser.SourceGrammar class.

public SourceGrammar()

Create a new grammar with default options.

public SourceGrammar(ParserOptions options)
throws NullPointerException if options is null.

Create a new grammar with a specific set of options.

public SourceGrammar(SourceGrammar current)

Create a new grammar from an existing grammar.

3.2.3Method summary

Public methods on the org.nineml.coffeegrinder.parser.SourceGrammar class.

public void addRule(NonterminalSymbol nonterminal List<Symbol> rhs)
throws GrammarException if any nonterminal in the rule is not from this grammar or if the grammar is closed

Add a rule to the grammar.

This is a convenience method that will construct the Rule for you.

Multiple rules can exist for the same NonterminalSymbol. There must be at least one rule for every nonterminal symbol that occurs on the “right hand side” of a rule.

public void addRule(NonterminalSymbol nonterminal Symbol[] rhs)
throws GrammarException if any nonterminal in the rule is not from this grammar or if the grammar is closed

Add a rule to the grammar.

This is a convenience method that will construct the Rule for you.

Multiple rules can exist for the same NonterminalSymbol. There must be at least one rule for every nonterminal symbol that occurs on the “right hand side” of a rule.

public void addRule(Rule rule)
throws GrammarException if any nonterminal in the rule is not from this grammar, or if the grammar is closed

Add a rule to the grammar.

Multiple rules can exist for the same NonterminalSymbol. There should be at least one rule for every nonterminal symbol that occurs on the “right hand side” of a rule. A symbol that is undefined but unreachable from the specified start symbol when parsing, isn’t forbidden by CoffeeGrinder, but it is by CoffeeFilter.

Once added, a rule can never be removed.

public boolean contains(Rule candidate)

Does this grammar contain an equivalent rule?

Two rules are equivalent if they have the same symbol, the same list of right-hand-side symbols, and if the attributes and optionality of every symbol on the right-hand-side are the same in both rules.

public ParserGrammar getCompiledGrammar(NonterminalSymbol seed)

public ParserGrammar getCompiledGrammar(ParserType parserType NonterminalSymbol seed)

public HygieneReport getHygieneReport(NonterminalSymbol seed)

Get a hygiene report for this grammar.

public Map<String, String> getMetadataProperies()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Gets the metadata properties.

Metadata properties exist solely for annotations by an application.

public String getMetadataProperty(String name)
Inherited from org.nineml.coffeegrinder.parser.Grammar
throws NullPointerException if the name is null

Gets a metadata property.

Metadata properties exist solely for annotations by an application.

public NonterminalSymbol getNonterminal(String name)
throws NullPointerException if the name is null.

Return the nonterminal symbol identified by name.

Nonterminal symbols are uniquely identified by their name.

Any string can be used as a name.

public NonterminalSymbol getNonterminal(String name List<ParserAttribute> attributes)
throws NullPointerException if the name is null.

Return the nonterminal symbol identified by name.

Nonterminal symbols are uniquely identified by their name.

Any string can be used as a name.

public NonterminalSymbol getNonterminal(String name ParserAttribute attribute)
throws NullPointerException if the name is null or the attribute is null.

Return the nonterminal symbol identified by name.

Nonterminal symbols are uniquely identified by their name.

Any string can be used as a name.

public GearleyParser getParser(ParserOptions options String seed)

public GearleyParser getParser(ParserOptions options NonterminalSymbol seed)

Get a parser for this grammar.

Returns a parser that will parse an input against the rules that define this grammar.

public ParserOptions getParserOptions()

Gets the parser options.

public List<Rule> getRules()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the rules currently defined in this grammar.

For a ParserGrammar, this is the final set.

public Map<NonterminalSymbol, List> getRulesBySymbol()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the rules currently defined in this grammar organized by symbol.

For a ParserGrammar, this is the final set.

public List<Rule> getRulesForSymbol(NonterminalSymbol symbol)
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the rules currently defined in this grammar for a particular symbol.

For a ParserGrammar, this is the final set.

public Set<NonterminalSymbol> getSymbols()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the currently defined nonterminals in the grammar.

For a ParserGrammar, this is the final set.

public boolean isNullable(Symbol symbol)

Is the symbol nullable?

A TerminalSymbol is never nullable.

For a ParserGrammar, the answer is definitive. For an SourceGrammar, a symbol that isn’t currently nullable could become nullable by the addition of more rules.

public SourceGrammar resolveDuplicates()

Resolve duplicate symbols in the grammar.

This method may return a different SourceGrammar. In this new grammar, all of the unique nonterminals will have unique names. (That is, if a nonterminal A occurs twice in the grammar with different parser attributes, it will have two different names in the resolved grammar.)

This method is public only so that it is possible to know what all of the nonterminals in the parse grammar will be.

public void setMetadataProperty(String name String value)
throws NullPointerException if the name is null

Sets a metadata property.

Metadata properties exist solely for annotations by an application. They have no bearing on the function of the grammar.

3.3Rule

The org.nineml.coffeegrinder.parser.Rule class.

A grammar rule maps a single NonterminalSymbol to zero or more symbols (either Terminals or further Nonterminals).

3.3.1Field summary

Public fields for the org.nineml.coffeegrinder.parser.Rule class.

public final NonterminalSymbol symbol = (runtime initializer)

public final RightHandSide rhs = (runtime initializer)

3.3.2Constructor summary

Public constructors for the org.nineml.coffeegrinder.parser.Rule class.

public Rule(NonterminalSymbol symbol Symbol[] rhs)

Construct a new rule mapping the nonterminal to a sequence of symbols.

If the sequence of symbols is empty or null, then the nonterminal maps to “ε”, that is to say, it’s allowed to be absent.

public Rule(NonterminalSymbol symbol List<Symbol> rhs)

Construct a new rule mapping the nonterminal to a sequence of symbols.

If the sequence of symbols is empty or null, then the nonterminal maps to “ε”, that is to say, it’s allowed to be absent.

3.3.3Method summary

Public methods on the org.nineml.coffeegrinder.parser.Rule class.

public boolean epsilonRule()

public boolean equals(Object obj)

public RightHandSide getRhs()

The sequence of symbols that comprise the definition of the rule’s nonterminal.

Note: although a rule may be defined with a null “right hand side”, this method always returns an empty list in such cases.

public List<State> getSlots()

public NonterminalSymbol getSymbol()

The nonterminal symbol defined by this rule.

public int hashCode()

public String toString()

Pretty print a node.

3.4NonterminalSymbol

The org.nineml.coffeegrinder.parser.NonterminalSymbol class.

This class extends org.nineml.coffeegrinder.parser.Symbol.

Every nonterminal must be defined by a Rule in the Grammar.

3.4.1Field summary

Public fields for the org.nineml.coffeegrinder.parser.NonterminalSymbol class.

public final String symbolName = (runtime initializer)

3.4.2Method summary

Public methods on the org.nineml.coffeegrinder.parser.NonterminalSymbol class.

public void addAttribute(ParserAttribute attribute)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute
throws NullPointerException if the attribute is null

Add the specified attribute to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public void addAttributes(Collection<ParserAttribute> attrcoll)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute

Add the specified attributes to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public boolean equals(Object obj)

Test nonterminals for equality.

Two nonterminals are equal if they have the same name.

public ParserAttribute getAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute.

public String getAttributeValue(String name String defaultValue)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute value.

public List<ParserAttribute> getAttributes()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes.

public Map<String, String> getAttributesMap()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes as a map.

public String getName()

The name of this symbol.

public boolean hasAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Check if a specific attribute is specified.

public int hashCode()

Assure that equal nonterminals return the same hash code.

public boolean matches(Symbol input)

Does this symbol match the specified symbol?

public boolean matches(Token input)
overrides Symbol

Does this symbol match the input token?

No, it does not. No nonterminal ever matches an input token.

public String toString()

Pretty print a nonterminal.

3.5TerminalSymbol

The org.nineml.coffeegrinder.parser.TerminalSymbol class.

This class extends org.nineml.coffeegrinder.parser.Symbol.

Terminal symbols match some input token(s) literally.

3.5.1Field summary

Public fields for the org.nineml.coffeegrinder.parser.TerminalSymbol class.

public static final TerminalSymbol EPSILON = (runtime initializer)

public static final TerminalSymbol EOF = (runtime initializer)

public static final TerminalSymbol UNDEFINED = (runtime initializer)

3.5.2Constructor summary

Public constructors for the org.nineml.coffeegrinder.parser.TerminalSymbol class.

public TerminalSymbol(Token token)
throws NullPointerException if the token is null

Make a symbol for the specified token.

public TerminalSymbol(Token token ParserAttribute attribute)
throws NullPointerException if either is null
throws GrammarException if the attribute attempts to make the symbol optional

Make a symbol for the specified token with a given ParserAttribute.

public TerminalSymbol(Token token Collection<ParserAttribute> attributes)
throws NullPointerException if the token is null
throws GrammarException if the attributes attempt to make the symbol optional

Make a symbol for the specified token with the given attributes

3.5.3Method summary

Public methods on the org.nineml.coffeegrinder.parser.TerminalSymbol class.

public void addAttribute(ParserAttribute attribute)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute
throws NullPointerException if the attribute is null

Add the specified attribute to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public void addAttributes(Collection<ParserAttribute> attrcoll)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute

Add the specified attributes to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public TerminalSymbol ch(char terminal)

Return a token for a string.

This is just a convenience method for a terminal symbol for a TokenCharacter.

public boolean equals(Object obj)

Test tokens for equality.

Two tokens are equal if they represent the same string and have the same attributes.

public ParserAttribute getAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute.

public String getAttributeValue(String name String defaultValue)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute value.

public List<ParserAttribute> getAttributes()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes.

public Map<String, String> getAttributesMap()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes as a map.

public Token getToken()

Get the token associated with this terminal symbol.

public boolean hasAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Check if a specific attribute is specified.

public int hashCode()

Assure that equal tokens return the same hash code.

public boolean matches(Symbol input)
overrides Symbol

Does this symbol match this other symbol?

No, it does not. No terminal ever matches another symbol.

public boolean matches(Token input)

Does this symbol match the specified token?

This is very like equality, but consider that for some kinds of symbols (for example, tokens that match regular expressions) it isn’t really the same as equality.

public TerminalSymbol regex(String regex)

Return a token for a string.

This is just a convenience method for a terminal symbol for a TokenRegex.

public TerminalSymbol s(String terminal)

Return a token for a string.

This is just a convenience method for a terminal symbol for a TokenString.

public String toString()

Pretty print a token.

3.6Symbol

The org.nineml.coffeegrinder.parser.Symbol class.

This class extends org.nineml.coffeegrinder.util.Decoratable.

Symbols match either tokens in the input (for TerminalSymbol symbols) or other symbols (for NonterminalSymbol symbols). For convenience, this interface defines both match methods for all Symbols.

3.6.1Constructor summary

Public constructors for the org.nineml.coffeegrinder.parser.Symbol class.

public Symbol()

Create a symbol with no attributes.

public Symbol(Collection<ParserAttribute> attributes)
throws GrammarException if the attribute names are not unique
throws AttributeException if an attribute has an invalid value

Create a symbol with an initial set of attributes.

3.6.2Method summary

Public methods on the org.nineml.coffeegrinder.parser.Symbol class.

public void addAttribute(ParserAttribute attribute)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute
throws NullPointerException if the attribute is null

Add the specified attribute to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public void addAttributes(Collection<ParserAttribute> attrcoll)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute

Add the specified attributes to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public ParserAttribute getAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute.

public String getAttributeValue(String name String defaultValue)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute value.

public List<ParserAttribute> getAttributes()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes.

public Map<String, String> getAttributesMap()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes as a map.

public boolean hasAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Check if a specific attribute is specified.

public boolean matches(Symbol input)

Does this symbol match the specified symbol?

public boolean matches(Token input)

Does this symbol match the specified token?

This is very like equality, but consider that for some kinds of symbols (for example, tokens that match regular expressions) it isn’t really the same as equality.

3.7Token

The org.nineml.coffeegrinder.tokens.Token class.

This class extends org.nineml.coffeegrinder.util.Decoratable.

This is an abstraction for input tokens. It allows the parser to be used, for example, for both sequences of characters and sequences of strings. (Sequences of anything you like, provided you define the tokens.)

The only thing that’s important about tokens is that we can tell when they match each other. This is not the same as equality becuase, for example, the same regular expression token might match many different input strings.

3.7.1Constructor summary

Public constructors for the org.nineml.coffeegrinder.tokens.Token class.

public Token(Collection<ParserAttribute> attributes)
throws GrammarException if the attribute names are not unique
throws AttributeException if an attribute has an invalid value

A token with attributes.

3.7.2Method summary

Public methods on the org.nineml.coffeegrinder.tokens.Token class.

public void addAttribute(ParserAttribute attribute)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute
throws NullPointerException if the attribute is null

Add the specified attribute to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public void addAttributes(Collection<ParserAttribute> attrcoll)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute

Add the specified attributes to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public ParserAttribute getAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute.

public String getAttributeValue(String name String defaultValue)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute value.

public List<ParserAttribute> getAttributes()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes.

public Map<String, String> getAttributesMap()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes as a map.

public String getValue()

What is this token?

public boolean hasAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Check if a specific attribute is specified.

public boolean matches(Token input)

Does this token match the input?

3.8TokenCharacter

The org.nineml.coffeegrinder.tokens.TokenCharacter class.

This class extends org.nineml.coffeegrinder.tokens.Token.

3.8.1Method summary

Public methods on the org.nineml.coffeegrinder.tokens.TokenCharacter class.

public void addAttribute(ParserAttribute attribute)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute
throws NullPointerException if the attribute is null

Add the specified attribute to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public void addAttributes(Collection<ParserAttribute> attrcoll)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute

Add the specified attributes to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public boolean equals(Object obj)

Test tokens for equality.

Two tokens are equal if they represent the same character.

public TokenCharacter get(int ch)

Create a token for the specified character.

public TokenCharacter get(int ch Collection<ParserAttribute> attributes)

Create a token for the specified character.

public TokenCharacter get(int ch ParserAttribute attribute)

Create a token for the specified character.

public ParserAttribute getAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute.

public String getAttributeValue(String name String defaultValue)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute value.

public List<ParserAttribute> getAttributes()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes.

public Map<String, String> getAttributesMap()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes as a map.

public int getCodepoint()

Return the codepoint value of this token (its character codepoint)

public String getValue()

What is this token?

public boolean hasAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Check if a specific attribute is specified.

public int hashCode()

Assure that equal tokens return the same hash code.

public boolean matches(String input)

Does this token match this string?

public boolean matches(Token input)
overrides Token

Does this token match the input?

This token matches other token characters that have the same character as well as TokenStrings that are one character long and contain the same character.

public String toString()

Pretty print a token.

3.9TokenString

The org.nineml.coffeegrinder.tokens.TokenString class.

This class extends org.nineml.coffeegrinder.tokens.Token.

3.9.1Method summary

Public methods on the org.nineml.coffeegrinder.tokens.TokenString class.

public void addAttribute(ParserAttribute attribute)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute
throws NullPointerException if the attribute is null

Add the specified attribute to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public void addAttributes(Collection<ParserAttribute> attrcoll)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute

Add the specified attributes to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public boolean equals(Object obj)

Test tokens for equality.

Two tokens are equal if they represent the same string.

public TokenString get(String value)

Create a token for the specified string.

public TokenString get(String value Collection<ParserAttribute> attributes)

Create a token for the specified string (with attributes)

public TokenString get(String value ParserAttribute attribute)

Create a token for the specified string (with an attribute)

public ParserAttribute getAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute.

public String getAttributeValue(String name String defaultValue)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute value.

public List<ParserAttribute> getAttributes()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes.

public Map<String, String> getAttributesMap()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes as a map.

public String getValue()

What is this token?

public boolean hasAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Check if a specific attribute is specified.

public int hashCode()

Assure that equal tokens return the same hash code.

public boolean matches(char input)

Does this toke match this character?

public boolean matches(String input)

Does this token match this string?

public boolean matches(Token input)
overrides Token

Does this token match the input?

This token matches other token strings that have the same underlying string. If this is a single character string, it will also match TokenCharacters that are defined with the same character.

public String toString()

Pretty print a token.

3.10TokenRegex

The org.nineml.coffeegrinder.tokens.TokenRegex class.

This class extends org.nineml.coffeegrinder.tokens.Token.

3.10.1Method summary

Public methods on the org.nineml.coffeegrinder.tokens.TokenRegex class.

public void addAttribute(ParserAttribute attribute)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute
throws NullPointerException if the attribute is null

Add the specified attribute to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public void addAttributes(Collection<ParserAttribute> attrcoll)
Inherited from org.nineml.coffeegrinder.util.Decoratable
throws AttributeException if you attempt to change the value of an attribute
throws AttributeException if you pass an illegal attribute

Add the specified attributes to the attributes collection.

Once added, an attribute cannot be removed, nor can its value be changed.

public boolean equals(Object obj)

public TokenRegex get(String expr)

Create a token for the specified regular expression.

public TokenRegex get(String expr Collection<ParserAttribute> attributes)

Create a token for the specified regular expression (with attributes)

public TokenRegex get(String expr ParserAttribute attribute)
throws NullPointerException if the attribute is null

Create a token for the specified regular expression (with an attribute)

public ParserAttribute getAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute.

public String getAttributeValue(String name String defaultValue)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get a specific token attribute value.

public List<ParserAttribute> getAttributes()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes.

public Map<String, String> getAttributesMap()
Inherited from org.nineml.coffeegrinder.util.Decoratable

Get all the token’s attributes as a map.

public String getValue()

What is this token?

public boolean hasAttribute(String name)
Inherited from org.nineml.coffeegrinder.util.Decoratable

Check if a specific attribute is specified.

public int hashCode()

public String matches(String input)

public boolean matches(Token input)
overrides Token

Does this token match the input token?

A regular expression token matches a TokenCharacter or TokenString if the regular expression matches the value. Returns fals for all other kinds of tokens.

public String toString()

3.11ParserGrammar

The org.nineml.coffeegrinder.parser.ParserGrammar class.

This class extends org.nineml.coffeegrinder.parser.Grammar.

A grammar is a list of rules. Each rule defines a non-terminal symbol as a sequence of zero or more symbols (terminal or nonterminal).

A grammar can be used to create a parser for that grammar. The ParserGrammar is derived from a SourceGrammar. The ParserGrammar is immutable.

3.11.1Field summary

Public fields for the org.nineml.coffeegrinder.parser.ParserGrammar class.

public final boolean usesRegex = (runtime initializer)

3.11.2Method summary

Public methods on the org.nineml.coffeegrinder.parser.ParserGrammar class.

public Set<Symbol> getFirst(Symbol symbol)

Return the set of “first” symbols for the specified symbol

The first symbols of a nonterminal are all those symbols that can appear “first” in a matching parse for that nonterminal. The first set of a terminal symbol is just the symbol itself.

public Set<Symbol> getFollow(Symbol symbol)

public HygieneReport getHygieneReport()

Get a hygiene report for this compiled grammar.

public Map<String, String> getMetadataProperies()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Gets the metadata properties.

Metadata properties exist solely for annotations by an application.

public String getMetadataProperty(String name)
Inherited from org.nineml.coffeegrinder.parser.Grammar
throws NullPointerException if the name is null

Gets a metadata property.

Metadata properties exist solely for annotations by an application.

public GearleyParser getParser()

Get a parser for this grammar.

Returns a parser that will parse an input against the rules that define this grammar.

public ParserOptions getParserOptions()

public List<Rule> getRules()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the rules currently defined in this grammar.

For a ParserGrammar, this is the final set.

public Map<NonterminalSymbol, List> getRulesBySymbol()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the rules currently defined in this grammar organized by symbol.

For a ParserGrammar, this is the final set.

public List<Rule> getRulesForSymbol(NonterminalSymbol symbol)
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the rules currently defined in this grammar for a particular symbol.

For a ParserGrammar, this is the final set.

public NonterminalSymbol getSeed()

public Set<NonterminalSymbol> getSymbols()
Inherited from org.nineml.coffeegrinder.parser.Grammar

Get the currently defined nonterminals in the grammar.

For a ParserGrammar, this is the final set.

public boolean isNullable(Symbol symbol)

Is the symbol nullable?

A TerminalSymbol is never nullable.

For a ParserGrammar, the answer is definitive. For an SourceGrammar, a symbol that isn’t currently nullable could become nullable by the addition of more rules.