Skip to content

Commit

Permalink
bug fixed and unicode characters can be written in char and string li…
Browse files Browse the repository at this point in the history
…terals. (#106)
  • Loading branch information
unnohideyuki committed Oct 23, 2020
1 parent 7b45a30 commit f08e547
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion compiler/src/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import Symbol
import Typing (ClassEnv (..), super)

import Control.Monad.State.Strict
import Data.Char
import Data.List (find, intercalate, nub)
import Data.List.Split (splitOn)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust, fromMaybe)
import Debug.Trace
import System.IO
import Text.Printf

emitPreamble :: Handle -> IO ()
emitPreamble h =
Expand Down Expand Up @@ -439,8 +441,11 @@ genAtomExpr (AtomExpr (VarAtom (CompositDict d ds))) = do

genAtomExpr (AtomExpr (LitAtom (LitStr s))) = do
n <- nexti
appendCode $ "Expr t" ++ show n ++ " = RTLib.fromJString(" ++ show s ++ ");"
appendCode $ "Expr t" ++ show n ++ " = RTLib.fromJString(" ++ myshow s ++ ");"
return n
where myshow s = "\"" ++ concatMap esc s ++ "\""
esc c | isPrint c = [c]
| otherwise = "\\" ++ printf "%03o" (fromEnum c)

genAtomExpr (AtomExpr (LitAtom (LitChar c))) = do
n <- nexti
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ haskell :-
<0> \" { act_open_string }
<string> \" { act_close_string }
<string> $graphic # [\" \\] { act_string }
<string> [\xa1 - 0x10ffff] { act_string }
<string> " " { act_string }
<string> "\\&" { skip }
<string> @escape { act_esc_string }
<string> \\ $whitechar+ \\ { skip }
<string> [^\'] { act_string }

-- char
<0> \' $graphic # [\' \\] \' { act_char }
<0> \' [\xa1 - 0x10ffff] \' { act_char }
<0> \' " " \' { act_char }
<0> \' @escape \' { act_esc_char }
<0> \' [^\'] \' { act_char }

-- special symbols
<0> "(" { act_token1 TOParen }
Expand Down
1 change: 1 addition & 0 deletions compiler/test/expected/sample315.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
αβγδεζηθικλμνξοπρςστ
1 change: 1 addition & 0 deletions compiler/test/expected/sample316.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Γειά σου Κόσμε
File renamed without changes.
File renamed without changes.

0 comments on commit f08e547

Please sign in to comment.