shithub: MicroHs

Download patch

ref: a37c98d83d1d059021305f25fecb43c63f4dab40
parent: ace94aa2ddfd17ceb707ee98f172209760842576
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Mon Jan 8 13:27:00 EST 2024

Handle numerically encoded input char literals.

--- a/src/MicroHs/Lex.hs
+++ b/src/MicroHs/Lex.hs
@@ -174,8 +174,15 @@
 decodeChar n ('r':cs) = ('\r', n+1, cs)
 decodeChar n ('t':cs) = ('\t', n+1, cs)
 decodeChar n ('b':cs) = ('\b', n+1, cs)
+decodeChar n ('x':cs) = conv 16 (n+1) 0 cs
+decodeChar n ('o':cs) = conv 8 (n+1) 0 cs
+decodeChar n (cs@(c:_)) | isDigit c = conv 10 n 0 cs
 decodeChar n (c  :cs) = (c,    n+1, cs)
 decodeChar n []       = ('X',  n,   [])
+
+conv :: Int -> Int -> Int -> String -> (Char, Int, String)
+conv b k r (c:ds) | isHexDigit c, let { n = digitToInt c }, n < b = conv b (k+1) (r * b + n) ds
+conv _ k r ds = (chr r, k, ds)
 
 isSpec :: Char -> Bool
 isSpec c = elem c "()[],{}`;"
--