Class 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 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

      • getPriorityStyle

        public java.lang.String getPriorityStyle()
        Description copied from interface: GearleyParser
        The priority style.

        Meaningless if priorities are not used in the grammar.

        Specified by:
        getPriorityStyle in interface GearleyParser
        Returns:
        The priority style.
      • getDefaultPriority

        public int getDefaultPriority()
        Description copied from interface: GearleyParser
        The default priority.

        Meaningless if priorities are not used in the grammar.

        Specified by:
        getDefaultPriority in interface GearleyParser
        Returns:
        The default priority.
      • 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:
        parse in interface GearleyParser
        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:
        parse in interface GearleyParser
        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:
        parse in interface GearleyParser
        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:
        hasMoreInput in interface GearleyParser
        Returns:
        true if parsing failed before the entire input was consumed
      • getLineNumber

        public int getLineNumber()
        Description copied from interface: GearleyParser
        Returns the line number of the last line read by the parser.
        Specified by:
        getLineNumber in interface GearleyParser
        Returns:
        the line number.
      • getColumnNumber

        public int getColumnNumber()
        Description copied from interface: GearleyParser
        Returns the column number of the last character on the last line read by the parser.
        Specified by:
        getColumnNumber in interface GearleyParser
        Returns:
        the column number.
      • getOffset

        public int getOffset()
        Description copied from interface: GearleyParser
        Returns the last offset read by the parser.
        Specified by:
        getOffset in interface GearleyParser
        Returns:
        the offset.