Class Result<T>

  • Type Parameters:
    T - the type of the parse result

    public class Result<T>
    extends Object
    Class representing a result of a parser. A result of a parser consists of the parse result and the rest of the input. The parse result is either an real result or an exception. One of the two is not-null.
    Author:
    Herbert Praehofer
    • Field Detail

      • result

        public final T result
        The parse result (maybe null).
      • excpt

        public final Exception excpt
        The exception (maybe null).
      • rest

        public final FList<String> rest
        The list of tokens not parsed yet.
    • Constructor Detail

      • Result

        private Result​(T result,
                       FList<String> rest)
        Private constructor creating a successful result object.
        Parameters:
        result - the parse result
        rest - the rest of input tokens
      • Result

        private Result​(Exception excpt,
                       FList<String> rest)
        Private constructor creating a failed result object.
        Parameters:
        excpt - the exception showing the parse failure
        rest - the rest of input tokens
    • Method Detail

      • success

        public static <T> Result<T> success​(T result,
                                            FList<String> rest)
        Creates a successful result consisting of a parse result and the rest of the input. The exception is null.
        Type Parameters:
        T - the type of the parse result
        Parameters:
        result - the parse result
        rest - the rest of the input
        Returns:
        the result object
      • failure

        public static <T> Result<T> failure​(Exception excpt,
                                            FList<String> rest)
        Creates a failed result consisting of an exception and the rest of the input. The parse result is null.
        Type Parameters:
        T - the type of the parse result (used for type checking)
        Parameters:
        excpt - the exception showing the parse failure
        rest - the rest of the input
        Returns:
        the failed result object
      • successful

        public boolean successful()
        Returns if this object represents a successful result.
        Returns:
        true if this object represents a successful result
      • failed

        public boolean failed()
        Returns if this object represents a failed result.
        Returns:
        true if this object represents a failed result