PageRenderTime 1ms CodeModel.GetById 54ms app.highlight 7ms RepoModel.GetById 4ms app.codeStats 0ms

/FParsec/Error.fsi

https://bitbucket.org/banshee/fparsec-samples
F# | 142 lines | 51 code | 24 blank | 67 comment | 0 complexity | 3069eba1da8f23b3fe0fa127fbf7887f MD5 | raw file
  1// Copyright (c) Stephan Tolksdorf 2007-2009
  2// License: Simplified BSD License. See accompanying documentation.
  3
  4module FParsec.Error
  5
  6val invalidPos : Pos
  7
  8#nowarn "61" // "The containing type can use 'null' as a representation value for its nullary union case. This member will be compiled as a static member."
  9
 10type ErrorMessage =
 11     /// Something expected could not be parsed.
 12     /// This error can be generated with the labeling operator <?>.
 13     /// The constructor argument is a label describing what was expected.
 14     | Expected of string
 15     /// Something unexpected was in the input.
 16     /// This error is primarily generated by the `notFollowedByL`,
 17     /// `notFollowedByChar` and `notFollowedByString` parser primitives.
 18     | Unexpected of string
 19     /// An error that does not fit into the other categories.
 20     /// This error can be generated with the `fail` and `failFatally` primitives.
 21     /// The constructor argument is a string containing the error message.
 22     | Message of string
 23     /// A "compound" failed to parse.
 24     /// Primarily generated by the compound-labelling operator <??>.
 25     /// The constructor arguments are a label for the compound parser and
 26     /// the error (Pos + ErrorMessageList) that caused the compound to fail to parse.
 27     | CompoundError of string * Pos * ErrorMessageList
 28     /// The parser backtracked after an error occurred.
 29     /// This error is primarily generated by the `attempt`, `>>?` and `.>>?` primitives.
 30     /// The constructor argument is the error (Pos + ErrorMessageList) that occurred
 31     /// before the backtracking.
 32     | BacktrackPoint of Pos * ErrorMessageList
 33     /// An error that can be used for application specific error data.
 34     /// Users will have to define their own error printer, as the default printer
 35     /// does not print out `OtherError`s.
 36     /// ATTENTION: The constructor argument is expected to be comparable by
 37     /// F#'s structural comparison function `compare`. `OtherError`s with arguments
 38     /// that are not comparable are ignored by the `ErrorMessageList` methods.
 39     | OtherError of obj
 40
 41/// A list of error messages. The order of error messages in the list carries no meaning.
 42/// Duplicate error messages and empty `Expected`, `Unexpected` and `Message`
 43/// messages have no influence on ordering or equality comparison and are ignored when
 44/// the list is converted to a set.
 45and [<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue);
 46      StructuralEquality(false); StructuralComparison(false)>]
 47    ErrorMessageList  =
 48    | AddErrorMessage of ErrorMessage * ErrorMessageList
 49    | NoErrorMessages
 50    with
 51        member ToSet:   unit -> Set<ErrorMessage>
 52
 53        static member OfSeq: seq<ErrorMessage> -> ErrorMessageList
 54
 55        [<CompilationRepresentation(CompilationRepresentationFlags.Instance)>]
 56        override Equals: obj -> bool
 57        [<CompilationRepresentation(CompilationRepresentationFlags.Instance)>]
 58        override GetHashCode: unit -> int
 59        interface System.IComparable
 60
 61        static member internal GetDebuggerDisplay: ErrorMessageList -> string
 62
 63/// `expectedError label` is equivalent to `AddErrorMessage(Expected(label), NoErrorMessages)`.
 64val expectedError:   string -> ErrorMessageList
 65/// `unexpectedError label` is equivalent to `AddErrorMessage(Unexpected(label), NoErrorMessages)`.
 66val unexpectedError: string -> ErrorMessageList
 67/// `messageError msg` is equivalent to `AddErrorMessage(Message(msg), NoErrorMessages)`.
 68val messageError:    string -> ErrorMessageList
 69/// `otherError obj` is equivalent to `AddErrorMessage(OtherError(obj: obj), NoErrorMessages)`.
 70val otherError:      obj    -> ErrorMessageList
 71
 72/// `backtrackError state error` is a variant of `AddErrorMessage(BacktrackPoint(state.Pos, error), NoErrorMessages)`,
 73/// that only wraps the error in a `BacktrackPoint` if it isn't already a `BacktrackPoint`.
 74val backtrackError:            State<'u> -> ErrorMessageList -> ErrorMessageList
 75
 76/// `compoundError label state error` is a variant of `AddErrorMessage(CompoundError(label, state.Pos, error), NoErrorMessages)`
 77/// that uses the original error position instead of `state.Pos` in case `error` is a `BacktrackPoint`.
 78val compoundError:   string -> State<'u> -> ErrorMessageList -> ErrorMessageList
 79
 80
 81/// `concatErrorMessages error1 error2` concatenates the two error message lists `error1` and `error2`.
 82val concatErrorMessages: ErrorMessageList -> ErrorMessageList -> ErrorMessageList
 83
 84/// `mergeErrors error1 error2` is an optimized variant of `concatErrorMessages error1 error2`
 85/// that avoids the call to concatErrorMessages if `error1` is empty (= `NoErrorMessages`).
 86val inline mergeErrors: ErrorMessageList -> ErrorMessageList -> ErrorMessageList
 87
 88/// `mergeErrorsIfNeeded oldState oldError newState newError` is equivalent to
 89/// `if newState <> State then newError else mergeErrors oldError newError`.
 90val inline mergeErrorsIfNeeded:    State<'u> -> ErrorMessageList
 91                                -> State<'u> -> ErrorMessageList -> ErrorMessageList
 92
 93/// `mergeErrorsIfNeeded3 veryOldState veryOldError oldState oldError newState newError` is equivalent to
 94/// `mergeErrorsIfNeeded oldState (mergeErrorsIfNeeded veryOldState veryOldError oldState oldError) newState newError`.
 95val inline mergeErrorsIfNeeded3:    State<'u> -> ErrorMessageList
 96                                 -> State<'u> -> ErrorMessageList
 97                                 -> State<'u> -> ErrorMessageList -> ErrorMessageList
 98
 99/// Represents a simple container type that brings together the position and error messages of a parser error.
100[<Sealed>]
101type ParserError =
102    new: Pos * ErrorMessageList -> ParserError
103
104    member Pos:   Pos
105    member Error: ErrorMessageList
106
107    override ToString: unit -> string
108
109    /// Returns a string representation of the ParserError.
110    /// For each error location the printed position information is augmented with the line of
111    /// text surrounding the error position together with a '^'-marker pointing to the exact location
112    /// of the error in the input stream.
113    /// The given CharStream must contain the original input for which the parser error was generated.
114    /// Newlines in the returned string are represented by System.Environment.Newline.
115    member ToString: streamWhereErrorOccurred: CharStream -> string
116
117    /// Writes a string representation of the ParserError to the given TextWriter value.
118    ///
119    /// The format of the position information can be customized by specifying the positionPrinter
120    /// argument. The given function is expected to print a representation of the passed Pos value
121    /// to the passed TextWriter value. If possible, it should indent text lines with the passed string
122    /// and take into account the maximum column count (including indention) passed as the last argument.
123    ///
124    /// If a value for the optional CharStream argument is given, the printed position
125    /// information is augmented with the the line of text surrounding the error position
126    /// together with a '^'-marker pointing to the exact location of the error in the input stream.
127    /// The given CharStream must contain the original input for which the parser error was generated.
128    member WriteTo:   textWriter: System.IO.TextWriter
129                    * ?positionPrinter: (System.IO.TextWriter -> Pos -> string -> int -> unit)
130                    * ?columnWidth: int * ?initialIndention: string * ?indentionIncrement: string
131                    * ?streamWhereErrorOccurred: CharStream
132                    -> unit
133
134/// Prints the line of text surrounding the given index in the stream and
135/// marks the position of the index with a caret (^) on a second line.
136/// The output is indented with the given string and is restricted to the
137/// given columWidth (including the indention).
138val printErrorLine: CharStream -> index: int64 -> System.IO.TextWriter -> indentionString: string -> columnWidth: int -> unit
139
140
141/// Internal helper function that needs to be public because it gets called from inline functions.
142val _raiseInfiniteLoopException: string -> State<'u> -> 'a