]> git.rmz.io Git - my-scheme.git/commit
Parse Strings surrounded by `"`
authorSamir Benmendil <me@rmz.io>
Sun, 14 Jan 2018 00:03:01 +0000 (00:03 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 14 Jan 2018 00:03:01 +0000 (00:03 +0000)
commit10ec228b216032b4d61216414aef8b1e36cf151f
treea4330abc71c7b568f3fe5363b6ac4dbedc07ee45
parentb388d53e751db6d925a39c06dc871c125799b8e5
Parse Strings surrounded by `"`

We need to use a `do-block` because we would like to keep the return
value of a parse in the middle. So we parse a single `char '"'`, parse
`many (noneOf "\"")` and assign the return value to `x` and parse
another `"`.

We apply the `String` constructor to the value of `x` to turn it into a
`LispVal` with `String x`.

Finally we inject the `LispVal` into the `Parser` monad. We need to do
this because each line of a `do-block` needs to be of the same type but
the result of `String x` is a `LispVal`, not a `Parser`. `return` wraps
the `LispVal` up in a `Parser` action that consumes no input.

Consider `a $ b c` as syntactic sugar for `a (b c)`.
app/Main.hs