Class EarleyResult

java.lang.Object
org.nineml.coffeegrinder.parser.EarleyResult
All Implemented Interfaces:
GearleyResult

public class EarleyResult extends Object implements GearleyResult
The results of an Earley parse.
  • Method Details

    • 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 interface GearleyResult
      Returns:
      the parse time
    • getParser

      public EarleyParser getParser()
      Get the parser for this result.
      Specified by:
      getParser in interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      Returns:
      true if the parse was infinitely ambiguous.
    • succeeded

      public boolean succeeded()
      Did the parse succeed?
      Specified by:
      succeeded in interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      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 interface GearleyResult
      Returns:
      The column number.
    • getPredictedTerminals

      public 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 interface GearleyResult
      Returns:
      The set of terminals.
    • getPath

      public EarleyPath getPath()
      Get last few matches from a failed parse.

      The path will be null for a successful parse.

      Returns:
      the path