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