Anonymous avatar Anonymous committed a15ab75

Always read text from files as UTF-8.

Comments (0)

Files changed (2)

PLexceptGOTOdotNET.lhs

 
 > module PLexceptGOTOdotNET where
 
+> import System.IO
 > import Text.ParserCombinators.Parsec
 > import qualified Data.Map as Map
 
 
 Drivers for the parser.
 
+> workOnFile fn fileName = do
+>     handle <- openFile fileName ReadMode
+>     hSetEncoding handle utf8
+>     contents <- hGetContents handle
+>     outputText <- return $ fn contents
+>     putStrLn outputText
+
 > pa s = case parse program "" s of
 >     Left perr -> show perr
 >     Right prog -> show prog
 
-> parseFile fileName = do
->     programText <- readFile fileName
->     outputText <- return $ pa programText
->     putStrLn outputText
+> parseFile = workOnFile pa
 
 Environments
 ------------
 >     Left perr -> show perr
 >     Right prog -> show $ toList $ eval empty prog
 
-> runFile fileName = do
->     programText <- readFile fileName
->     outputText <- return $ run programText
->     putStrLn outputText
+> runFile = workOnFile run
 
 Static Analyzer
 ---------------
 >     in
 >         ((x':xs'), id'')
 
-Helper function for the test suite.
+Helper functions for the test suite.
 
-> testLoopLabeling s = case parse program "" s of
+> loopLabel s = case parse program "" s of
 >     Left perr -> show perr
 >     Right prog -> show (labelLoops prog 0)
 
+> loopLabelFile = workOnFile loopLabel
+
 Gather all variables used in the program.  This includes internal variables
 to be used as loop counters.  This assumes loops have already been labeled.
 
 >     Left perr -> show perr
 >     Right prog -> translate prog
 
-> compileFile fileName = do
->     programText <- readFile fileName
->     outputText <- return $ compile programText
->     putStrLn outputText
+> compileFile = workOnFile compile

PLexceptGOTOdotNET.markdown

 
     -> Functionality "Parse PL-{GOTO} Program" is implemented by
     -> shell command
-    -> "ghc -e "do c <- readFile \"%(test-file)\"; putStrLn $ PLexceptGOTOdotNET.pa c" PLexceptGOTOdotNET.lhs"
+    -> "ghc PLexceptGOTOdotNET.lhs -e "workOnFile pa \"%(test-file)\"""
 
     | n ← 0;
     = Block [AssignZero "n"]
 
     -> Functionality "Evaluate PL-{GOTO} Program" is implemented by
     -> shell command
-    -> "ghc -e "do c <- readFile \"%(test-file)\"; putStrLn $ PLexceptGOTOdotNET.run c" PLexceptGOTOdotNET.lhs"
+    -> "ghc PLexceptGOTOdotNET.lhs -e "runFile \"%(test-file)\"""
 
     | n ← 0;
     = [("n",0)]
 
     -> Functionality "Label PL-{GOTO} Loops" is implemented by
     -> shell command
-    -> "ghc -e "do c <- readFile \"%(test-file)\"; putStrLn $ PLexceptGOTOdotNET.testLoopLabeling c" PLexceptGOTOdotNET.lhs"
+    -> "ghc PLexceptGOTOdotNET.lhs -e "loopLabelFile \"%(test-file)\"""
 
     | n ← 0; m ← 0; LOOP n;
     |     LOOP m;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.