Package org.nineml.coffeegrinder.parser
Class EarleyParser
- java.lang.Object
-
- org.nineml.coffeegrinder.parser.EarleyParser
-
- All Implemented Interfaces:
GearleyParser
public class EarleyParser extends java.lang.Object implements GearleyParser
The Earley parser.The Earley parser compares an input sequence against a grammar and determines if the input is a sentence in the grammar.
This is a fairly literal implementation of the parser in ยง5 of SPPF-Style Parsing From Earley Recognisers.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringlogcategoryThe logging category for log messages about the Earley parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetColumnNumber()Returns the column number of the last character on the last line read by the parser.intgetDefaultPriority()The default priority.ParserGrammargetGrammar()Get the grammar used by this parser.intgetLineNumber()Returns the line number of the last line read by the parser.intgetOffset()Returns the last offset read by the parser.ParserTypegetParserType()Return the parser type.java.lang.StringgetPriorityStyle()The priority style.NonterminalSymbolgetSeed()Get theNonterminalSymbolseed value used by this parser.booleanhasMoreInput()Is there more input?EarleyResultparse(java.lang.String input)Parse an input string against the grammar.EarleyResultparse(java.util.Iterator<Token> input)Parse a sequence of tokens against the grammar.EarleyResultparse(Token[] input)Parse an array of tokens against the grammar.
-
-
-
Field Detail
-
logcategory
public static final java.lang.String logcategory
The logging category for log messages about the Earley parser.- See Also:
- Constant Field Values
-
-
Method Detail
-
getParserType
public ParserType getParserType()
Return the parser type.- Specified by:
getParserTypein interfaceGearleyParser- Returns:
ParserType.Earley
-
getPriorityStyle
public java.lang.String getPriorityStyle()
Description copied from interface:GearleyParserThe priority style.Meaningless if priorities are not used in the grammar.
- Specified by:
getPriorityStylein interfaceGearleyParser- Returns:
- The priority style.
-
getDefaultPriority
public int getDefaultPriority()
Description copied from interface:GearleyParserThe default priority.Meaningless if priorities are not used in the grammar.
- Specified by:
getDefaultPriorityin interfaceGearleyParser- Returns:
- The default priority.
-
getGrammar
public ParserGrammar getGrammar()
Get the grammar used by this parser.- Specified by:
getGrammarin interfaceGearleyParser- Returns:
- the grammar
-
getSeed
public NonterminalSymbol getSeed()
Get theNonterminalSymbolseed value used by this parser.- Specified by:
getSeedin interfaceGearleyParser- Returns:
- the seed
-
parse
public EarleyResult parse(java.lang.String input)
Parse an input string against the grammar.This is a shortcut for parsing a sequence of characters.
- Specified by:
parsein interfaceGearleyParser- Parameters:
input- the input string- Returns:
- a parse result
-
parse
public EarleyResult parse(Token[] input)
Parse an array of tokens against the grammar.You must not change the input array.
- Specified by:
parsein interfaceGearleyParser- Parameters:
input- the input array- Returns:
- a parse result
-
parse
public EarleyResult parse(java.util.Iterator<Token> input)
Parse a sequence of tokens against the grammar.- Specified by:
parsein interfaceGearleyParser- Parameters:
input- the input sequence- Returns:
- a parse result
-
hasMoreInput
public boolean hasMoreInput()
Is there more input?If the parse succeeded, the answer will always be false. But a failed parse can fail because it was unable to process a token or because it ran out of tokens. This method checks if there was any more input after the parse completed.
- Specified by:
hasMoreInputin interfaceGearleyParser- Returns:
- true if parsing failed before the entire input was consumed
-
getLineNumber
public int getLineNumber()
Description copied from interface:GearleyParserReturns the line number of the last line read by the parser.- Specified by:
getLineNumberin interfaceGearleyParser- Returns:
- the line number.
-
getColumnNumber
public int getColumnNumber()
Description copied from interface:GearleyParserReturns the column number of the last character on the last line read by the parser.- Specified by:
getColumnNumberin interfaceGearleyParser- Returns:
- the column number.
-
getOffset
public int getOffset()
Description copied from interface:GearleyParserReturns the last offset read by the parser.- Specified by:
getOffsetin interfaceGearleyParser- Returns:
- the offset.
-
-