Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming ParseResult fields. #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions FParsec/CharParsers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ let float32OfHexString = HexFloat.SingleFromHexString

[<StructuredFormatDisplay("{StructuredFormatDisplay}")>]
type ParserResult<'Result,'UserState> =
| Success of 'Result * 'UserState * Position
| Failure of string * ParserError * 'UserState
| Success of result: 'Result * state: 'UserState * endPosition: Position
| Failure of message: string * error: ParserError * state: 'UserState
with
member private t.StructuredFormatDisplay =
match t with
| Success(r,_,_) ->
| Success(result=r) ->
if typeof<'Result> = typeof<unit> then "Success: ()"
else sprintf "Success: %A" r
| Failure(msg,_,_) ->
| Failure(message=msg) ->
sprintf "Failure:\n%s" msg

let internal applyParser (parser: Parser<'Result,'UserState>) (stream: CharStream<'UserState>) =
Expand Down
8 changes: 4 additions & 4 deletions FParsec/CharParsers.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ open Primitives

/// Values of this type are returned by the runParser functions (not by `Parser<_,_>` functions).
type ParserResult<'Result,'UserState> =
/// Success(result, userState, endPos) holds the result and the user state returned by a successful parser,
/// Success(result, state, endPosition) holds the result and the user state returned by a successful parser,
/// together with the position where the parser stopped.
| Success of 'Result * 'UserState * Position
/// Failure(errorAsString, error, suserState) holds the parser error and the user state returned by a failing parser,
| Success of result: 'Result * state: 'UserState * endPosition: Position
/// Failure(message, error, suserState) holds the parser error and the user state returned by a failing parser,
/// together with a string representation of the parser error.
| Failure of string * ParserError * 'UserState
| Failure of message: string * error: ParserError * state: 'UserState

/// `runParserOnString p ustate streamName str` runs the parser `p` directly on the content of the string `str`,
/// starting with the initial user state `ustate`. The `streamName` is used in error messages to describe
Expand Down
6 changes: 3 additions & 3 deletions Samples/Calculator/calculator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ let calculate s = run completeExpression s

let equals expectedValue r =
match r with
| Success (v, _, _) when v = expectedValue -> ()
| Success (v, _, _) -> failwith "Math is hard, let's go shopping!"
| Failure (msg, err, _) -> printf "%s" msg; failwith msg
| Success (result=v) when v = expectedValue -> ()
| Success _ -> failwith "Math is hard, let's go shopping!"
| Failure (message=msg) -> printf "%s" msg; failwith msg

let test() =
calculate "10.5 + 123.25 + 877" |> equals 1010.75
Expand Down
4 changes: 2 additions & 2 deletions Samples/FSharpParsingSample/FParsecVersion/main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let main(argv: string[]) =

let myProg =
match result with
| Success (v, _, _) -> v
| Failure (msg, _, _) ->
| Success (result=v) -> v
| Failure (message=msg) ->
System.Console.WriteLine(msg)
exit 1

Expand Down
4 changes: 2 additions & 2 deletions Samples/JSON/main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ let main(args: string[]) =
let result = parseJsonFile args[0] System.Text.Encoding.UTF8
// for the moment we just print out the AST
match result with
| Success (v, _, _) ->
| Success (result=v) ->
printf "The AST of the input file is:\n%A\n" v
0
| Failure (msg, err, _) ->
| Failure (message=msg) ->
printfn "%s" msg
1

Expand Down
4 changes: 2 additions & 2 deletions Samples/PEG/main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ let main(args: string[]) =
let result = runParserOnFile Parser.pGrammar () fileName System.Text.Encoding.UTF8
// for the moment we just print out the AST
match result with
| Success (v, _, _) -> printf "The ast for the input file is:\n%A\n" v
| Failure (msg, err, _) -> printf "%s\n" msg
| Success (result=v) -> printf "The ast for the input file is:\n%A\n" v
| Failure (message=msg) -> printf "%s\n" msg
0
4 changes: 2 additions & 2 deletions Samples/Tutorial/tutorial.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ open FParsec

let test p str =
match run p str with
| Success(result, _, _) -> printfn "Success: %A" result
| Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg
| Success(result=result) -> printfn "Success: %A" result
| Failure(message=errorMsg) -> printfn "Failure: %s" errorMsg

test pfloat "1.25"
test pfloat "1.25E 2"
Expand Down
10 changes: 5 additions & 5 deletions Test/CharParsersTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ let testSpecialCharParsers() =
let count p = many p |>> List.fold (fun c x -> c + 1) 0

match run (count unicodeNewline) "\n\r\r\n\u0085\u2028\u2029\r\n" with
| Success(c,_,pos) -> c |> Equal 7; pos.Index |> Equal 9L; pos.Line |> Equal 8L; pos.Column |> Equal 1L
| Success(result=c;endPosition=pos) -> c |> Equal 7; pos.Index |> Equal 9L; pos.Line |> Equal 8L; pos.Column |> Equal 1L
| Failure _ -> Fail()

spaces |> ROk "" 0 ()
Expand All @@ -162,17 +162,17 @@ let testSpecialCharParsers() =
unicodeSpaces1 |> ROk " \u200A" 2 ()

match run spaces "\n \r\t\t\r\n\n " with
| Success(_, _, pos) -> pos.Index |> Equal 9L; pos.Line |> Equal 5L; pos.Column |> Equal 2L
| Success(endPosition=pos) -> pos.Index |> Equal 9L; pos.Line |> Equal 5L; pos.Column |> Equal 2L
| _ -> Fail()
match run spaces1 "\n \r\t\t\r\n\n " with
| Success(_, _, pos) -> pos.Index |> Equal 9L; pos.Line |> Equal 5L; pos.Column |> Equal 2L
| Success(endPosition=pos) -> pos.Index |> Equal 9L; pos.Line |> Equal 5L; pos.Column |> Equal 2L
| _ -> Fail()

match run unicodeSpaces "\n \r\t\t\r\n\n \u0085\u000C\u2028\u2029 \r\n\t\u200A" with
| Success(_, _, pos) -> pos.Index |> Equal 18L; pos.Line |> Equal 9L; pos.Column |> Equal 3L
| Success(endPosition=pos) -> pos.Index |> Equal 18L; pos.Line |> Equal 9L; pos.Column |> Equal 3L
| _ -> Fail()
match run unicodeSpaces1 "\n \r\t\t\r\n\n \u0085\u000C\u2028\u2029 \r\n\t\u200A" with
| Success(_, _, pos) -> pos.Index |> Equal 18L; pos.Line |> Equal 9L; pos.Column |> Equal 3L
| Success(endPosition=pos) -> pos.Index |> Equal 18L; pos.Line |> Equal 9L; pos.Column |> Equal 3L
| _ -> Fail()

eof |> ROk "" 0 ()
Expand Down
4 changes: 2 additions & 2 deletions Test/IdentifierValidatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,8 +1812,8 @@ open FParsec

let testCharPredicates() =
let xidStartRanges, xidContinueRanges = match Parser.parseXIdRanges() with
| CharParsers.Success(ranges, _, _ ) -> ranges
| CharParsers.Failure(msg,_,_) -> failwith msg
| CharParsers.Success(result=ranges) -> ranges
| CharParsers.Failure(message=msg) -> failwith msg

let checkPredicate fBmp fSmp ranges =
let mutable lastLast = -1
Expand Down