6.8 FParsec.ErrorMessage

6.8.1 Interface

// FParsecCS.dll

namespace FParsec

type ErrorMessageType = Expected                        = 0
                      | ExpectedString                  = 1
                      | ExpectedCaseInsensitiveString   = 2
                      | Unexpected                      = 3
                      | UnexpectedString                = 4
                      | UnexpectedCaseInsensitiveString = 5
                      | Message                         = 6
                      | NestedError                     = 7
                      | CompoundError                   = 8
                      | Other                           = 9

type ErrorMessage =
  member Type: ErrorMessageType

  override Equals: obj -> bool
  override GetHashCode: unit -> int
  interface System.IEquatable<ErrorMessageList>

// nested types
type ErrorMessage.Expected =
  inherit ErrorMessage
  new: label: string -> ErrorMessage.Expected
  member Label: string

type ErrorMessage.ExpectedString =
  inherit ErrorMessage
  new: string -> ErrorMessage.ExpectedString
  member String: string

type ErrorMessage.ExpectedCaseInsensitiveString =
  inherit ErrorMessage
  new: string -> ErrorMessage.ExpectedCaseInsensitiveString
  member String: string

type ErrorMessage.Unexpected =
  inherit ErrorMessage
  new: label: string -> ErrorMessage.Unexpected
  member Label: string

type ErrorMessage.UnexpectedString =
  inherit ErrorMessage
  new: string -> ErrorMessage.UnexpectedString
  member String: string

type ErrorMessage.UnexpectedCaseInsensitiveString =
  inherit ErrorMessage
  new: string -> ErrorMessage.UnexpectedCaseInsensitiveString
  member String: string

type ErrorMessage.Message =
  inherit ErrorMessage
  new: string -> ErrorMessage.Message
  member String: string

type ErrorMessage.NestedError =
  inherit ErrorMessage

  new:   position: Position * userState: obj * messages: ErrorMessageList
      -> ErrorMessage.NestedError

  member Position:  Position
  member UserState: obj
  member Messages:  ErrorMessageList

type ErrorMessage.CompoundError =
  inherit ErrorMessage

  new:   labelOfCompound: string
       * nestedErrorPosition: Position
       * nestedErrorUserState: obj
       * nestedErrorMessages: ErrorMessageList
      -> ErrorMessage.CompoundError

  member LabelOfCompound: string
  member NestedErrorPosition: Position
  member NestedErrorUserState: obj
  member NestedErrorMessages: ErrorMessageList

type ErrorMessage.Other =
  inherit ErrorMessage
  new: data: obj -> ErrorMessage.Other
  member Data: obj

6.8.2 Remarks

ErrorMessage is the abstract base class for FParsec error messages. Parser functions return ErrorMessage values within an ErrorMessageList.

There are several subtypes of ErrorMessage that represent specific kind of error messages. These subtypes are defined as nested classes within ErrorMessage.

The active patterns and type abbreviations in the FParsec.Error module allow you to treat the ErrorMessage type almost as if it was defined as an F# discriminated union type.

6.8.3 Members

type ErrorMessage

ErrorMessage is the abstract base class for FParsec error messages.

type ErrorMessage =
  member Type: ErrorMessageType

  override Equals: obj -> bool
  override GetHashCode: unit -> int
  interface System.IEquatable<ErrorMessageList>

Please also see the remarks above.

type ErrorMessage.Expected

Parsers report this ErrorMessage when the input does not match the expected input.

type ErrorMessage.Expected =
  inherit ErrorMessage
  new: label: string -> ErrorMessage.Expected
  member Label: string

The string label describes the expected input.

This error message can be generated with the labeling operator <?>.

type ErrorMessage.ExpectedString

Parsers report this ErrorMessage when the input does not match an expected string constant.

type ErrorMessage.ExpectedString =
  inherit ErrorMessage
  new: string -> ErrorMessage.ExpectedString
  member String: string

This ErrorMessage is mainly generated by the pstring parser and its variants.

type ErrorMessage.ExpectedCaseInsensitiveString

Parsers report this ErrorMessage when the input does not match an expected case‐insensitive string constant.

type ErrorMessage.ExpectedCaseInsensitiveString =
  inherit ErrorMessage
  new: string -> ErrorMessage.ExpectedCaseInsensitiveString
  member String: string

This ErrorMessage is mainly generated by the pstringCI parsers and its variants.

type ErrorMessage.Unexpected

Parsers report this ErrorMessage when they encounter some unexpected input.

type ErrorMessage.Unexpected =
  inherit ErrorMessage
  new: label: string -> ErrorMessage.Unexpected
  member Label: string

The string label describes the unexpected input.

This ErrorMessage is mainly generated by the notFollowedByL primitive.

type ErrorMessage.UnexpectedString

Parsers report this ErrorMessage when they encounter an unexpected string constant.

type ErrorMessage.UnexpectedString =
  inherit ErrorMessage
  new: string -> ErrorMessage.UnexpectedString
  member String: string

This ErrorMessage is mainly generated by the notFollowedByString parser.

type ErrorMessage.UnexpectedCaseInsensitiveString

Parsers report this ErrorMessage when they encounter an unexpected case‐insensitive string constant.

type ErrorMessage.UnexpectedCaseInsensitiveString =
  inherit ErrorMessage
  new: string -> ErrorMessage.UnexpectedCaseInsensitiveString
  member String: string

This ErrorMessage is mainly generated by the notFollowedByStringCI parser.

type ErrorMessage.Message

Parsers report this ErrorMessage when an the error does not fit the other ErrorMessage types.

type ErrorMessage.Message =
  inherit ErrorMessage
  new: string -> ErrorMessage.Message
  member String: string

This error message can be generated with the fail and failFatally primitives.

type ErrorMessage.NestedError

Parsers report this ErrorMessage when they backtracked after an error occurred.

type ErrorMessage.NestedError =
  inherit ErrorMessage

  new:   position: Position * userState: obj * messages: ErrorMessageList
      -> ErrorMessage.NestedError

  member Position:  Position
  member UserState: obj
  member Messages:  ErrorMessageList

The Position property describes the stream position where the original error occurred that triggered the backtracking. The UserState property contains the user state value from before the backtracking (upcasted to obj). The Messages property contains the error messages of the original error.

This error message is mainly generated by the attempt, >>? and .>>? primitives.

type ErrorMessage.CompoundError

Parsers report this ErrorMessage when a “compound” failed to parse.

type ErrorMessage.CompoundError =
  inherit ErrorMessage

  new:   labelOfCompound: string
       * nestedErrorPosition: Position
       * nestedErrorUserState: obj
       * nestedErrorMessages: ErrorMessageList
      -> ErrorMessage.CompoundError

  member LabelOfCompound: string
  member NestedErrorPosition: Position
  member NestedErrorUserState: obj
  member NestedErrorMessages: ErrorMessageList

This error message is mainly generated by the compound‐labelling operator <??>.

type ErrorMessage.Other

User‐defined parsers can return this ErrorMessage to report application‐specific error data.

type ErrorMessage.Other =
  inherit ErrorMessage
  new: data: obj -> ErrorMessage.Other
  member Data: obj

To display OtherError values in error messages, you will have to define your own error printer, as ParserError.ToString/WriteTo ignores them.