Chapter 3. Grammars
3.1. Grammar
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.1. Field summary
Public fields for the org.nineml.coffeegrinder.parser.Grammar class.
public static final String logcategory ="Grammar"
3.1.2. Constructor summary
Public constructors for the org.nineml.coffeegrinder.parser.Grammar class.
public Grammar()
3.1.3. Method summary
Public methods on the org.nineml.coffeegrinder.parser.Grammar class.
publicMap<String, String>getMetadataProperies()Gets the metadata properties.
Metadata properties exist solely for annotations by an application.
publicStringgetMetadataProperty(String name)- throws
NullPointerExceptionif the name is null Gets a metadata property.
Metadata properties exist solely for annotations by an application.
publicList<Rule>getRules()Get the rules currently defined in this grammar.
For a ParserGrammar, this is the final set.
publicMap<NonterminalSymbol, List>getRulesBySymbol()Get the rules currently defined in this grammar organized by symbol.
For a ParserGrammar, this is the final set.
publicList<Rule>getRulesForSymbol(NonterminalSymbol symbol)Get the rules currently defined in this grammar for a particular symbol.
For a ParserGrammar, this is the final set.
publicSet<NonterminalSymbol>getSymbols()Get the currently defined nonterminals in the grammar.
For a ParserGrammar, this is the final set.
publicbooleanisNullable(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.2. SourceGrammar
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.1. Field summary
Public fields for the org.nineml.coffeegrinder.parser.SourceGrammar class.
public static final String logcategory ="Grammar"
3.2.2. Constructor 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
NullPointerExceptionif 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.3. Method summary
Public methods on the org.nineml.coffeegrinder.parser.SourceGrammar class.
public void addRule(NonterminalSymbol nonterminal List<Symbol> rhs)- throws
GrammarExceptionif 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
GrammarExceptionif 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
GrammarExceptionif 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.
publicbooleancontains(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.
publicParserGrammargetCompiledGrammar(NonterminalSymbol seed)publicParserGrammargetCompiledGrammar(ParserType parserType NonterminalSymbol seed)publicHygieneReportgetHygieneReport(NonterminalSymbol seed)Get a hygiene report for this grammar.
publicMap<String, String>getMetadataProperies()- Inherited from
org.nineml.coffeegrinder.parser.Grammar Gets the metadata properties.
Metadata properties exist solely for annotations by an application.
publicStringgetMetadataProperty(String name)- Inherited from
org.nineml.coffeegrinder.parser.Grammar - throws
NullPointerExceptionif the name is null Gets a metadata property.
Metadata properties exist solely for annotations by an application.
publicNonterminalSymbolgetNonterminal(String name)- throws
NullPointerExceptionif 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.
publicNonterminalSymbolgetNonterminal(String name List<ParserAttribute> attributes)- throws
NullPointerExceptionif 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.
publicNonterminalSymbolgetNonterminal(String name ParserAttribute attribute)- throws
NullPointerExceptionif 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.
publicGearleyParsergetParser(ParserOptions options String seed)publicGearleyParsergetParser(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.
publicParserOptionsgetParserOptions()Gets the parser options.
publicList<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.
publicMap<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.
publicList<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.
publicSet<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.
publicbooleanisNullable(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.
publicSourceGrammarresolveDuplicates()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
NullPointerExceptionif 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.3. Rule
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.1. Field 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.2. Constructor 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.3. Method summary
Public methods on the org.nineml.coffeegrinder.parser.Rule class.
publicbooleanepsilonRule()publicbooleanequals(Object obj)publicRightHandSidegetRhs()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.
publicList<State>getSlots()publicNonterminalSymbolgetSymbol()The nonterminal symbol defined by this rule.
publicinthashCode()publicStringtoString()Pretty print a node.
3.4. NonterminalSymbol
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.1. Field summary
Public fields for the org.nineml.coffeegrinder.parser.NonterminalSymbol class.
public final String symbolName =(runtime initializer)
3.4.2. Method summary
Public methods on the org.nineml.coffeegrinder.parser.NonterminalSymbol class.
public void addAttribute(ParserAttribute attribute)- Inherited from
org.nineml.coffeegrinder.util.Decoratable - throws
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif you pass an illegal attribute - throws
NullPointerExceptionif 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
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif 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.
publicbooleanequals(Object obj)Test nonterminals for equality.
Two nonterminals are equal if they have the same name.
publicParserAttributegetAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute.
publicStringgetAttributeValue(String name String defaultValue)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute value.
publicList<ParserAttribute>getAttributes()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes.
publicMap<String, String>getAttributesMap()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes as a map.
publicStringgetName()The name of this symbol.
publicbooleanhasAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Check if a specific attribute is specified.
publicinthashCode()Assure that equal nonterminals return the same hash code.
publicbooleanmatches(Symbol input)Does this symbol match the specified symbol?
publicbooleanmatches(Token input)- overrides
Symbol Does this symbol match the input token?
No, it does not. No nonterminal ever matches an input token.
publicStringtoString()Pretty print a nonterminal.
3.5. TerminalSymbol
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.1. Field 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.2. Constructor summary
Public constructors for the org.nineml.coffeegrinder.parser.TerminalSymbol class.
public TerminalSymbol(Token token)- throws
NullPointerExceptionif the token is null Make a symbol for the specified token.
public TerminalSymbol(Token token ParserAttribute attribute)- throws
NullPointerExceptionif either is null - throws
GrammarExceptionif 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
NullPointerExceptionif the token is null - throws
GrammarExceptionif the attributes attempt to make the symbol optional Make a symbol for the specified token with the given attributes
3.5.3. Method summary
Public methods on the org.nineml.coffeegrinder.parser.TerminalSymbol class.
public void addAttribute(ParserAttribute attribute)- Inherited from
org.nineml.coffeegrinder.util.Decoratable - throws
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif you pass an illegal attribute - throws
NullPointerExceptionif 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
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif 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.
publicTerminalSymbolch(char terminal)Return a token for a string.
This is just a convenience method for a terminal symbol for a TokenCharacter.
publicbooleanequals(Object obj)Test tokens for equality.
Two tokens are equal if they represent the same string and have the same attributes.
publicParserAttributegetAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute.
publicStringgetAttributeValue(String name String defaultValue)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute value.
publicList<ParserAttribute>getAttributes()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes.
publicMap<String, String>getAttributesMap()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes as a map.
publicTokengetToken()Get the token associated with this terminal symbol.
publicbooleanhasAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Check if a specific attribute is specified.
publicinthashCode()Assure that equal tokens return the same hash code.
publicbooleanmatches(Symbol input)- overrides
Symbol Does this symbol match this other symbol?
No, it does not. No terminal ever matches another symbol.
publicbooleanmatches(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.
publicTerminalSymbolregex(String regex)Return a token for a string.
This is just a convenience method for a terminal symbol for a TokenRegex.
publicTerminalSymbols(String terminal)Return a token for a string.
This is just a convenience method for a terminal symbol for a TokenString.
publicStringtoString()Pretty print a token.
3.6. Symbol
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.1. Constructor 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
GrammarExceptionif the attribute names are not unique - throws
AttributeExceptionif an attribute has an invalid value Create a symbol with an initial set of attributes.
3.6.2. Method summary
Public methods on the org.nineml.coffeegrinder.parser.Symbol class.
public void addAttribute(ParserAttribute attribute)- Inherited from
org.nineml.coffeegrinder.util.Decoratable - throws
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif you pass an illegal attribute - throws
NullPointerExceptionif 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
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif 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.
publicParserAttributegetAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute.
publicStringgetAttributeValue(String name String defaultValue)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute value.
publicList<ParserAttribute>getAttributes()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes.
publicMap<String, String>getAttributesMap()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes as a map.
publicbooleanhasAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Check if a specific attribute is specified.
publicbooleanmatches(Symbol input)Does this symbol match the specified symbol?
publicbooleanmatches(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.7. Token
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.1. Constructor summary
Public constructors for the org.nineml.coffeegrinder.tokens.Token class.
public Token(Collection<ParserAttribute> attributes)- throws
GrammarExceptionif the attribute names are not unique - throws
AttributeExceptionif an attribute has an invalid value A token with attributes.
3.7.2. Method summary
Public methods on the org.nineml.coffeegrinder.tokens.Token class.
public void addAttribute(ParserAttribute attribute)- Inherited from
org.nineml.coffeegrinder.util.Decoratable - throws
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif you pass an illegal attribute - throws
NullPointerExceptionif 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
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif 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.
publicParserAttributegetAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute.
publicStringgetAttributeValue(String name String defaultValue)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute value.
publicList<ParserAttribute>getAttributes()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes.
publicMap<String, String>getAttributesMap()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes as a map.
publicStringgetValue()What is this token?
publicbooleanhasAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Check if a specific attribute is specified.
publicbooleanmatches(Token input)Does this token match the input?
3.8. TokenCharacter
The org.nineml.coffeegrinder.tokens.TokenCharacter class.
This class extends org.nineml.coffeegrinder.tokens.Token.
3.8.1. Method summary
Public methods on the org.nineml.coffeegrinder.tokens.TokenCharacter class.
public void addAttribute(ParserAttribute attribute)- Inherited from
org.nineml.coffeegrinder.util.Decoratable - throws
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif you pass an illegal attribute - throws
NullPointerExceptionif 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
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif 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.
publicbooleanequals(Object obj)Test tokens for equality.
Two tokens are equal if they represent the same character.
publicTokenCharacterget(int ch)Create a token for the specified character.
publicTokenCharacterget(int ch Collection<ParserAttribute> attributes)Create a token for the specified character.
publicTokenCharacterget(int ch ParserAttribute attribute)Create a token for the specified character.
publicParserAttributegetAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute.
publicStringgetAttributeValue(String name String defaultValue)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute value.
publicList<ParserAttribute>getAttributes()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes.
publicMap<String, String>getAttributesMap()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes as a map.
publicintgetCodepoint()Return the codepoint value of this token (its character codepoint)
publicStringgetValue()What is this token?
publicbooleanhasAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Check if a specific attribute is specified.
publicinthashCode()Assure that equal tokens return the same hash code.
publicbooleanmatches(String input)Does this token match this string?
publicbooleanmatches(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.
publicStringtoString()Pretty print a token.
3.9. TokenString
The org.nineml.coffeegrinder.tokens.TokenString class.
This class extends org.nineml.coffeegrinder.tokens.Token.
3.9.1. Method summary
Public methods on the org.nineml.coffeegrinder.tokens.TokenString class.
public void addAttribute(ParserAttribute attribute)- Inherited from
org.nineml.coffeegrinder.util.Decoratable - throws
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif you pass an illegal attribute - throws
NullPointerExceptionif 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
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif 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.
publicbooleanequals(Object obj)Test tokens for equality.
Two tokens are equal if they represent the same string.
publicTokenStringget(String value)Create a token for the specified string.
publicTokenStringget(String value Collection<ParserAttribute> attributes)Create a token for the specified string (with attributes)
publicTokenStringget(String value ParserAttribute attribute)Create a token for the specified string (with an attribute)
publicParserAttributegetAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute.
publicStringgetAttributeValue(String name String defaultValue)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute value.
publicList<ParserAttribute>getAttributes()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes.
publicMap<String, String>getAttributesMap()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes as a map.
publicStringgetValue()What is this token?
publicbooleanhasAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Check if a specific attribute is specified.
publicinthashCode()Assure that equal tokens return the same hash code.
publicbooleanmatches(char input)Does this toke match this character?
publicbooleanmatches(String input)Does this token match this string?
publicbooleanmatches(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.
publicStringtoString()Pretty print a token.
3.10. TokenRegex
The org.nineml.coffeegrinder.tokens.TokenRegex class.
This class extends org.nineml.coffeegrinder.tokens.Token.
3.10.1. Method summary
Public methods on the org.nineml.coffeegrinder.tokens.TokenRegex class.
public void addAttribute(ParserAttribute attribute)- Inherited from
org.nineml.coffeegrinder.util.Decoratable - throws
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif you pass an illegal attribute - throws
NullPointerExceptionif 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
AttributeExceptionif you attempt to change the value of an attribute - throws
AttributeExceptionif 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.
publicbooleanequals(Object obj)publicTokenRegexget(String expr)Create a token for the specified regular expression.
publicTokenRegexget(String expr Collection<ParserAttribute> attributes)Create a token for the specified regular expression (with attributes)
publicTokenRegexget(String expr ParserAttribute attribute)- throws
NullPointerExceptionif the attribute is null Create a token for the specified regular expression (with an attribute)
publicParserAttributegetAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute.
publicStringgetAttributeValue(String name String defaultValue)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get a specific token attribute value.
publicList<ParserAttribute>getAttributes()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes.
publicMap<String, String>getAttributesMap()- Inherited from
org.nineml.coffeegrinder.util.Decoratable Get all the token’s attributes as a map.
publicStringgetValue()What is this token?
publicbooleanhasAttribute(String name)- Inherited from
org.nineml.coffeegrinder.util.Decoratable Check if a specific attribute is specified.
publicinthashCode()publicStringmatches(String input)publicbooleanmatches(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.
publicStringtoString()
3.11. ParserGrammar
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.1. Field summary
Public fields for the org.nineml.coffeegrinder.parser.ParserGrammar class.
public final boolean usesRegex =(runtime initializer)
3.11.2. Method summary
Public methods on the org.nineml.coffeegrinder.parser.ParserGrammar class.
publicSet<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.
publicSet<Symbol>getFollow(Symbol symbol)publicHygieneReportgetHygieneReport()Get a hygiene report for this compiled grammar.
publicMap<String, String>getMetadataProperies()- Inherited from
org.nineml.coffeegrinder.parser.Grammar Gets the metadata properties.
Metadata properties exist solely for annotations by an application.
publicStringgetMetadataProperty(String name)- Inherited from
org.nineml.coffeegrinder.parser.Grammar - throws
NullPointerExceptionif the name is null Gets a metadata property.
Metadata properties exist solely for annotations by an application.
publicGearleyParsergetParser()Get a parser for this grammar.
Returns a parser that will parse an input against the rules that define this grammar.
publicParserOptionsgetParserOptions()publicList<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.
publicMap<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.
publicList<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.
publicNonterminalSymbolgetSeed()publicSet<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.
publicbooleanisNullable(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.