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