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 EarleyResultcontinueParsing()Continue parsing from the last successfully matched prefix.EarleyResultcontinueParsing(GearleyParser newParser)Continue parsing from the last successfully matched prefix with a new parser.ArboristgetArborist()Get an arborist to extract trees from the forest.ArboristgetArborist(Axe axe)Get an arborist to extract trees from the forest.EarleyChartgetChart()Get the Earley chart for the parse.intgetColumnNumber()Returns the column number of the last character on the last line read by the parser.ParseForestgetForest()Return the parse forest created by the parser.TokengetLastToken()What was the last token parsed?intgetLineNumber()Returns the line number of the last line read by the parser.intgetOffset()Returns the last offset read by the parser.EarleyParsergetParser()Get the parser for this result.longgetParseTime()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()intgetTokenCount()How many tokens were parsed?booleanisAmbiguous()Returns true if the parse was ambiguous.booleanisInfinitelyAmbiguous()Returns true if the parse was infinitely ambiguous.booleanprefixSucceeded()Did the parse match the beginning of the input?booleansucceeded()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:
getParseTimein interfaceGearleyResult- Returns:
- the parse time
-
getParser
public EarleyParser getParser()
Get the parser for this result.- Specified by:
getParserin 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:GearleyResultReturn the parse forest created by the parser.This method returns
nullif the parse was unsuccessful.- Specified by:
getForestin interfaceGearleyResult- Returns:
- The parse forest.
-
getArborist
public Arborist getArborist()
Description copied from interface:GearleyResultGet an arborist to extract trees from the forest.The default arborist is created with
Arborist.getArborist(ParseForest).- Specified by:
getArboristin interfaceGearleyResult- Returns:
- the arborist
-
getArborist
public Arborist getArborist(Axe axe)
Description copied from interface:GearleyResultGet an arborist to extract trees from the forest.The arborist is created with
Arborist.getArborist(ParseForest, Axe).- Specified by:
getArboristin interfaceGearleyResult- Parameters:
axe- the arborists axe- Returns:
- the arborist
-
isAmbiguous
public boolean isAmbiguous()
Description copied from interface:GearleyResultReturns true if the parse was ambiguous.- Specified by:
isAmbiguousin interfaceGearleyResult- Returns:
- true if the parse was ambiguous.
-
isInfinitelyAmbiguous
public boolean isInfinitelyAmbiguous()
Description copied from interface:GearleyResultReturns true if the parse was infinitely ambiguous.The parse will only be infinitely ambiguous if the grqmmar contained a loop.
- Specified by:
isInfinitelyAmbiguousin interfaceGearleyResult- Returns:
- true if the parse was infinitely ambiguous.
-
succeeded
public boolean succeeded()
Did the parse succeed?- Specified by:
succeededin 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
prefixParsingoption is enabled.Note: if the whole parse succeeded, this method returns false.
- Specified by:
prefixSucceededin 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:
continueParsingin 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:
continueParsingin 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:
getTokenCountin 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:
getLastTokenin interfaceGearleyResult- Returns:
- the last (successfully) parsed token.
-
getOffset
public int getOffset()
Description copied from interface:GearleyResultReturns the last offset read by the parser.- Specified by:
getOffsetin interfaceGearleyResult- Returns:
- The offset.
-
getLineNumber
public int getLineNumber()
Description copied from interface:GearleyResultReturns the line number of the last line read by the parser.- Specified by:
getLineNumberin interfaceGearleyResult- Returns:
- The line number.
-
getColumnNumber
public int getColumnNumber()
Description copied from interface:GearleyResultReturns the column number of the last character on the last line read by the parser.- Specified by:
getColumnNumberin interfaceGearleyResult- Returns:
- The column number.
-
getPredictedTerminals
public java.util.Set<TerminalSymbol> getPredictedTerminals()
Description copied from interface:GearleyResultReturns the symbols predicted as possibly next in the case where a parse fails.- Specified by:
getPredictedTerminalsin interfaceGearleyResult- Returns:
- The set of terminals.
-
-