Skip to content

Commit

Permalink
Modified string and character literals to use codepage
Browse files Browse the repository at this point in the history
  • Loading branch information
LegionMammal978 committed Oct 28, 2020
1 parent 6f0474a commit c820b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions Codepage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ aliases = [('¤', "cur"), ('½', "hlf"), ('↕', "ud"), ('↑', "up"), ('↓',
getCommands :: [Word8] -> String
getCommands = map $ (codepage !!) . fromEnum

-- Get the position of a character in the code page
findByte :: Char -> Int
findByte byte | Just ix <- elemIndex byte codepage = ix
| otherwise = error "Bad byte"

-- Convert a program to list of bytes
getBytes :: String -> [Word8]
getBytes = map $ toEnum . findByte
where findByte byte | Just ix <- elemIndex byte codepage = ix
| otherwise = error "Bad byte"

-- Get the alias of a character
getAlias :: Char -> String
Expand Down
9 changes: 6 additions & 3 deletions Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Expr
import Builtins
import PrattParser
import DecompressString
import Codepage
import Text.Parsec
import Text.Parsec.Char
import Control.Monad (forM, foldM)
Expand Down Expand Up @@ -223,7 +224,9 @@ float = do
character :: Parser (Exp [Lit Scheme])
character = do
quote <- char '\''
c <- anyChar
coded <- anyChar
let c :: Char
c = toEnum $ findByte coded
return $ ELit [Value (show c) $ Scheme [] $ CType [] $ TConc TChar]

-- Parse a string
Expand All @@ -240,11 +243,11 @@ str = do
maybeEscape <- optionMaybe $ char '\\' >> anyChar
case maybeEscape of
Nothing -> return plainText
Just c -> do plainText2 <- content; return $ plainText++c:plainText2
Just c -> do plainText2 <- content; return $ plainText ++ toEnum (findByte c) : plainText2
decode '' = '\n'
decode '¨' = '"'
decode '¦' = '\\'
decode c = c
decode c = toEnum $ findByte c

-- Parse a compressed string
comprstr :: Parser (Exp [Lit Scheme])
Expand Down

0 comments on commit c820b56

Please sign in to comment.