-
Notifications
You must be signed in to change notification settings - Fork 0
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
Define a parser that consumes a single character #2
Comments
Pushed a few *fs files to the repo with implementation for the single character parser but not sure if that is correct. Could you please take a look? |
What is missing is that it should return the unconsumed part of the string. In addition error message should be associated with a position in the string in order to help the user On Tue, Nov 1, 2016 at 8:51 AM +0100, "Volodymyr Lukashevych" [email protected] wrote: Pushed a few *fs files to the repo with implementation for the single character parser but not sure if that is correct. Could you please take a look? You are receiving this because you authored the thread. |
Pushed changes to a hardcoded char parser so now returning an unconsumed string on Success. But not sure if I got the point about providing information on a position in the string in a Failure case. type Result<'T> =
| Success of 'T*string
| Failure of string
let parseFirstCharHardcodedA str =
let charToMatch = 'a'
if String.IsNullOrEmpty(str) then
Failure "Input is empty"
else
let firstChar = str.[0]
if firstChar = charToMatch then
Success(charToMatch,str.[1..])
else
let errorMessage = sprintf "Expected character is: '%c' but received '%c'" charToMatch firstChar
Failure errorMessage |
If the input is non empty the parser should return the first character.
If the input is empty the parser return a failure.
The text was updated successfully, but these errors were encountered: