Skip to content

Commit be6aa24

Browse files
committed
Improvements to parenthesis checking.
* Only enable the check for codeworld-mode. Oops! * Leave blank lines after the warnings, so later console output is readable.
1 parent dd1a8e0 commit be6aa24

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

codeworld-compiler/src/Compile.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ compileSource src out err mode = checkDangerousSource src >>= \case
4242
"Sorry, but your program refers to forbidden language features."
4343
return False
4444
False -> withSystemTempDirectory "buildSource" $ \tmpdir -> do
45-
parenProblem <- not <$> checkParsedCode src err
45+
parenProblem <- case mode of
46+
"codeworld" -> not <$> checkParsedCode src err
47+
_ -> return False
4648
copyFile src (tmpdir </> "program.hs")
4749
baseArgs <- case mode of
4850
"haskell" -> return haskellCompatibleBuildArgs
@@ -55,9 +57,7 @@ compileSource src out err mode = checkDangerousSource src >>= \case
5557
"codeworld" -> filterOutput output
5658
_ -> output
5759

58-
if parenProblem
59-
then when (not (B.null filteredOutput)) (B.appendFile err "\n\n")
60-
else B.writeFile err ""
60+
when (not parenProblem) $ B.writeFile err ""
6161
B.appendFile err filteredOutput
6262

6363
let target = tmpdir </> "program.jsexe"

codeworld-compiler/src/ParseCode.hs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{-# LANGUAGE LambdaCase #-}
2-
{-# LANGUAGE OverloadedStrings #-}
3-
41
{-
52
Copyright 2017 The CodeWorld Authors. All rights reserved.
63
@@ -19,10 +16,6 @@
1916

2017
module ParseCode (checkParsedCode) where
2118

22-
import qualified Data.ByteString as B
23-
import Data.ByteString.Char8 (pack)
24-
import Data.List (intercalate)
25-
import Data.List.Split (splitOn)
2619
import Data.Generics
2720
import Language.Haskell.Exts
2821

@@ -32,7 +25,7 @@ checkParsedCode src err = do
3225
case result of
3326
ParseOk mod -> case getErrors mod of
3427
[] -> return True
35-
errors -> writeFile err (intercalate "\n\n" errors) >> return False
28+
errors -> writeFile err (concatMap (++ "\n\n") errors) >> return False
3629
ParseFailed _ _ -> return True
3730

3831
getErrors :: Module SrcSpanInfo -> [String]
@@ -70,6 +63,7 @@ isGoodPatRhs (PTuple _ _ _) = True
7063
isGoodPatRhs _ = False
7164

7265
formatLocation :: SrcSpanInfo -> String
73-
formatLocation (SrcSpanInfo s _) = "program.hs" ++ ":" ++ show line ++ ":" ++ show col ++ ": "
66+
formatLocation (SrcSpanInfo s _) =
67+
"program.hs" ++ ":" ++ show line ++ ":" ++ show col ++ ": "
7468
where line = srcSpanStartLine s
7569
col = srcSpanStartColumn s

0 commit comments

Comments
 (0)