mirror of
https://github.com/chrisdone/duet.git
synced 2024-10-05 15:58:04 +03:00
Add parsers
This commit is contained in:
parent
c8d85590c9
commit
f6c19caf0c
@ -1,16 +1,29 @@
|
||||
data Tuple a b = Tuple a b
|
||||
data Result a = OK a String | Error String
|
||||
data Parser a = Parser (String -> Result a)
|
||||
parseBool =
|
||||
Parser
|
||||
(\string ->
|
||||
case take 4 string of
|
||||
"True" -> OK True (drop 4 string)
|
||||
"True" ->
|
||||
case drop 4 string of
|
||||
!rest -> OK True rest
|
||||
_ ->
|
||||
case take 5 string of
|
||||
"False" -> OK False (drop 5 string)
|
||||
"False" ->
|
||||
case drop 5 string of
|
||||
!rest -> OK False rest
|
||||
_ -> Error (append "Expected a bool, but got: " string))
|
||||
runParser =
|
||||
\p s ->
|
||||
case p of
|
||||
Parser f -> f s
|
||||
main = runParser parseBool "TrueFalse"
|
||||
bind =
|
||||
\m f ->
|
||||
Parser
|
||||
(\s ->
|
||||
case runParser m s of
|
||||
OK a rest -> runParser (f a) rest
|
||||
Error err -> Error err)
|
||||
pure = \a -> Parser (OK a)
|
||||
main = runParser (bind parseBool (\x -> bind parseBool (\y -> pure (Tuple x y)))) "TrueFalse"
|
||||
|
@ -101,7 +101,7 @@ displayRenamerException specialTypes =
|
||||
IdentifierNotInVarScope scope name label ->
|
||||
"Not in variable scope " ++
|
||||
curlyQuotes (printit defaultPrint name) ++
|
||||
" (AST tree label: "++show label ++")"++
|
||||
-- " (AST tree label: "++show label ++")"++
|
||||
"\n" ++
|
||||
"Nearest names in scope:\n\n" ++
|
||||
intercalate
|
||||
|
Loading…
Reference in New Issue
Block a user