write-you-a-scheme-v2 / scheme

Write You a Scheme
https://www.wespiser.com/writings/wyas/home.html
MIT License
552 stars 114 forks source link

Parsec w/ T.Text #2

Closed adamwespiser closed 8 years ago

adamwespiser commented 8 years ago

@sdiehl, having problems getting the parser to work creating LispVal values of strings

gce-work:scheme$ stack build && stack exec scheme
Repl> '(a)
List [Atom "a"]
Repl> '("a")
Parser "<stdin>" (line 1, column 4):
unexpected "a"
expecting end of "\"" or literal string
Repl> '(\"a\")
Parser "<stdin>" (line 1, column 4):
unexpected '\\'
expecting end of "("

It looks like the Parsec standard lisp parser is taking a different approach: https://hackage.haskell.org/package/lispparser-0.3.1/docs/src/Text-ParserCombinators-Parsec-Lisp.html

any insight on parsing in double quoted strings from the repl into LispVal?

sdiehl commented 8 years ago

Use this in your parser

parseString :: Parser LispVal
parseString = do
  x <- strLit
  return $ String x
Repl> '("a")
List [String "a"]
Repl> "foo"
String "foo"
Repl> '("foo \"inner quote\" ")
List [String "foo \"inner quote\" "]
adamwespiser commented 8 years ago

that's great! see https://github.com/write-you-a-scheme-v2/scheme/commit/05855b1e9c2943f8f3f9e912feb3895ca004181d for working solution.