Skip to content

Commit

Permalink
Merge pull request #589 from HigherOrderCO/chr
Browse files Browse the repository at this point in the history
Change Num (U32) to Word32; parse Chars as u32 values
  • Loading branch information
VictorTaelin authored Oct 3, 2024
2 parents 0df2cc2 + f451ea0 commit 558ebed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/Kind/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ parseTerm = (do
, parseSet
, parseNum
, parseTxt
, parseChr
, parseHol
, parseMet
, parseRef
Expand Down Expand Up @@ -302,6 +303,23 @@ parseTxt = withSrc $ do
char '"'
return $ Txt txt

parseChr = withSrc $ do
char '\''
chr <- parseEscaped <|> noneOf "'\\"
char '\''
return $ Num (fromIntegral $ ord chr)
where
parseEscaped :: Parser Char
parseEscaped = do
char '\\'
c <- oneOf "\\\'nrt"
return $ case c of
'\\' -> '\\'
'\'' -> '\''
'n' -> '\n'
'r' -> '\r'
't' -> '\t'

parseHol = withSrc $ do
char '?'
nam <- parseName
Expand Down
2 changes: 1 addition & 1 deletion src/Kind/Reduce.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ reduce book fill lv term = red term where
ref nam = Ref nam

txt [] = red (Ref "Base/String/cons")
txt (x:xs) = red (App (App (Ref "Base/String/nil") (Num (ord x))) (Txt xs))
txt (x:xs) = red (App (App (Ref "Base/String/nil") (Num (toEnum (ord x)))) (Txt xs))

nat 0 = Ref "Base/Nat/zero"
nat n = App (Ref "Base/Nat/succ") (nat (n - 1))
Expand Down
5 changes: 3 additions & 2 deletions src/Kind/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import qualified Data.IntMap.Strict as IM
import qualified Data.Map.Strict as M

import Debug.Trace
import Data.Word (Word32)

-- Kind's AST
data Term
Expand Down Expand Up @@ -49,8 +50,8 @@ data Term
-- U32 Type
| U32

-- U32 Value (FIXME: this is wrong, should be Word32)
| Num Int
-- U32 Value
| Num Word32

-- U32 Binary Operation
| Op2 Oper Term Term
Expand Down

0 comments on commit 558ebed

Please sign in to comment.