Class EarleyResult
- java.lang.Object
-
- org.nineml.coffeegrinder.parser.EarleyResult
-
- All Implemented Interfaces:
GearleyResult
public class EarleyResult extends java.lang.Object implements GearleyResult
The results of an Earley parse.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EarleyResult
continueParsing()
Continue parsing from the last successfully matched prefix.EarleyResult
continueParsing(GearleyParser newParser)
Continue parsing from the last successfully matched prefix with a new parser.Arborist
getArborist()
Get an arborist to extract trees from the forest.Arborist
getArborist(Axe axe)
Get an arborist to extract trees from the forest.EarleyChart
getChart()
Get the Earley chart for the parse.int
getColumnNumber()
Returns the column number of the last character on the last line read by the parser.ParseForest
getForest()
Return the parse forest created by the parser.Token
getLastToken()
What was the last token parsed?int
getLineNumber()
Returns the line number of the last line read by the parser.int
getOffset()
Returns the last offset read by the parser.EarleyParser
getParser()
Get the parser for this result.long
getParseTime()
How long did the parse take?java.util.Set<TerminalSymbol>
getPredictedTerminals()
Returns the symbols predicted as possibly next in the case where a parse fails.Token[]
getSuffix()
int
getTokenCount()
How many tokens were parsed?boolean
isAmbiguous()
Returns true if the parse was ambiguous.boolean
isInfinitelyAmbiguous()
Returns true if the parse was infinitely ambiguous.boolean
prefixSucceeded()
Did the parse match the beginning of the input?boolean
succeeded()
Did the parse succeed?
-
-
-
Method Detail
-
getParseTime
public long getParseTime()
How long did the parse take?Returns the number of milliseconds required to parse the input. Returns -1 if the timing is unavailable.
- Specified by:
getParseTime
in interfaceGearleyResult
- Returns:
- the parse time
-
getParser
public EarleyParser getParser()
Get the parser for this result.- Specified by:
getParser
in interfaceGearleyResult
- Returns:
- the parser that produced this result.
-
getChart
public EarleyChart getChart()
Get the Earley chart for the parse.After a parse, the Earley chart isn't usually very useful. It's discarded unless the
ParserOptions.getReturnChart()
returnChart} option is enabled.- Returns:
- the Earley chart if it's available, or null otherwise.
-
getForest
public ParseForest getForest()
Description copied from interface:GearleyResult
Return the parse forest created by the parser.This method returns
null
if the parse was unsuccessful.- Specified by:
getForest
in interfaceGearleyResult
- Returns:
- The parse forest.
-
getArborist
public Arborist getArborist()
Description copied from interface:GearleyResult
Get an arborist to extract trees from the forest.The default arborist is created with
Arborist.getArborist(ParseForest)
.- Specified by:
getArborist
in interfaceGearleyResult
- Returns:
- the arborist
-
getArborist
public Arborist getArborist(Axe axe)
Description copied from interface:GearleyResult
Get an arborist to extract trees from the forest.The arborist is created with
Arborist.getArborist(ParseForest, Axe)
.- Specified by:
getArborist
in interfaceGearleyResult
- Parameters:
axe
- the arborists axe- Returns:
- the arborist
-
isAmbiguous
public boolean isAmbiguous()
Description copied from interface:GearleyResult
Returns true if the parse was ambiguous.- Specified by:
isAmbiguous
in interfaceGearleyResult
- Returns:
- true if the parse was ambiguous.
-
isInfinitelyAmbiguous
public boolean isInfinitelyAmbiguous()
Description copied from interface:GearleyResult
Returns true if the parse was infinitely ambiguous.The parse will only be infinitely ambiguous if the grqmmar contained a loop.
- Specified by:
isInfinitelyAmbiguous
in interfaceGearleyResult
- Returns:
- true if the parse was infinitely ambiguous.
-
succeeded
public boolean succeeded()
Did the parse succeed?- Specified by:
succeeded
in interfaceGearleyResult
- Returns:
- true if the parse succeeded
-
prefixSucceeded
public boolean prefixSucceeded()
Did the parse match the beginning of the input?Suppose you're looking for "abb" and you give "abbc" as the input. That parse will fail, but it did succeed on a prefix of the input. This method will return true if the input began with a string that could be successfully parsed.
Prefix parsing is only performed if the
prefixParsing
option is enabled.Note: if the whole parse succeeded, this method returns false.
- Specified by:
prefixSucceeded
in interfaceGearleyResult
- Returns:
- true if a prefix was successfully parsed, false otherwise.
-
getSuffix
public Token[] getSuffix()
-
continueParsing
public EarleyResult continueParsing()
Continue parsing from the last successfully matched prefix.If prefix parsing is enabled, and a prefix was identified, this method will attempt to continue parsing from the next token after the previous prefix parse.
- Specified by:
continueParsing
in interfaceGearleyResult
- Returns:
- a parse result
- Throws:
ParseException
- if this result doesn't indicate that a prefix parse was successful
-
continueParsing
public EarleyResult continueParsing(GearleyParser newParser)
Continue parsing from the last successfully matched prefix with a new parser.If prefix parsing is enabled, and a prefix was identified, this method will attempt to continue parsing from the next token after the previous prefix parse.
- Specified by:
continueParsing
in interfaceGearleyResult
- Parameters:
newParser
- The (next) parser.- Returns:
- a parse result
- Throws:
ParseException
- if this result doesn't indicate that a prefix parse was successful
-
getTokenCount
public int getTokenCount()
How many tokens were parsed?In the case of an unsuccessful parse, restarting may occur before this position.
- Specified by:
getTokenCount
in interfaceGearleyResult
- Returns:
- the number of tokens parsed.
-
getLastToken
public Token getLastToken()
What was the last token parsed?In the case of an unsuccessful parse, restarting may reparse this token.
- Specified by:
getLastToken
in interfaceGearleyResult
- Returns:
- the last (successfully) parsed token.
-
getOffset
public int getOffset()
Description copied from interface:GearleyResult
Returns the last offset read by the parser.- Specified by:
getOffset
in interfaceGearleyResult
- Returns:
- The offset.
-
getLineNumber
public int getLineNumber()
Description copied from interface:GearleyResult
Returns the line number of the last line read by the parser.- Specified by:
getLineNumber
in interfaceGearleyResult
- Returns:
- The line number.
-
getColumnNumber
public int getColumnNumber()
Description copied from interface:GearleyResult
Returns the column number of the last character on the last line read by the parser.- Specified by:
getColumnNumber
in interfaceGearleyResult
- Returns:
- The column number.
-
getPredictedTerminals
public java.util.Set<TerminalSymbol> getPredictedTerminals()
Description copied from interface:GearleyResult
Returns the symbols predicted as possibly next in the case where a parse fails.- Specified by:
getPredictedTerminals
in interfaceGearleyResult
- Returns:
- The set of terminals.
-
-