add \n and \t escapes to the lexer

This commit is contained in:
rhiannon morris 2023-11-03 20:07:59 +01:00
parent d4639a35c6
commit 90cdcfe4da

View file

@ -71,13 +71,15 @@ tmatch : Lexer -> (String -> Token) -> Tokenizer ExtToken
tmatch t f = match t (T . f) tmatch t f = match t (T . f)
||| [todo] escapes other than `\"` and (accidentally) `\\`
export export
fromStringLit : String -> String fromStringLit : String -> String
fromStringLit = pack . go . unpack . drop 1 . dropLast 1 where fromStringLit = pack . go . unpack . drop 1 . dropLast 1 where
go : List Char -> List Char go : List Char -> List Char
go [] = [] go [] = []
go ['\\'] = ['\\'] -- i guess??? go ['\\'] = ['\\'] -- i guess???
go ('\\' :: 'n' :: cs) = '\n' :: go cs
go ('\\' :: 't' :: cs) = '\t' :: go cs
-- [todo] others
go ('\\' :: c :: cs) = c :: go cs go ('\\' :: c :: cs) = c :: go cs
go (c :: cs) = c :: go cs go (c :: cs) = c :: go cs