Skip to content

Commit

Permalink
simplify parse and check interpreter run
Browse files Browse the repository at this point in the history
  • Loading branch information
patritzenfeld committed Oct 11, 2024
1 parent 93be743 commit ed2eec2
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions flex-task/src/FlexTask/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,34 +195,35 @@ checkSolution taskData globalCode parseCode checkCode submission picPath = do
runWithPackageDB (loadModules filePaths >> runCheck) >>= sequence
where
runCheck = do
setImportsQ
[ ("Control.OutputCapable.Blocks.Type", Just "OC")
, ("Data.Either", Just "E")
, ("Text.Parsec", Just "P")
, ("Text.Parsec.Error", Just "PE")
, ("Control.OutputCapable.Blocks.Generic.Type", Nothing)
, ("Data.Ratio", Nothing)
]
setImportsQ $
("Control.OutputCapable.Blocks.Type", Just "OBT"):
map (,Nothing)
[ "Data.Either"
, "Text.Parsec"
, "Text.Parsec.Error"
, "Control.OutputCapable.Blocks.Generic.Type"
, "Data.Ratio"
]
setTopLevelModules ["Check", "Parse", "Global"]
interpret checkSyntaxAbort infer

checkSyntaxAbort = [i|
let
showWithFieldNumber :: String -> P.ParseError -> String
showWithFieldNumber :: String -> ParseError -> String
showWithFieldNumber input e = "Error in input field " ++ fieldNum ++ ":" ++ errors
where
fieldNum = show $ length (filter (=='\\a') consumed) `div` 2 + 1
errors = PE.showErrorMessages
errors = showErrorMessages
"or"
"unknown parse error"
"expecting"
"unexpected"
"end of input"
$ PE.errorMessages e
consumed = take (P.sourceColumn $ P.errorPos e) input
$ errorMessages e
consumed = take (sourceColumn $ errorPos e) input

isAbort (OC.Refuse _) = True
isAbort (OC.Assertion False _) = True
isAbort (Refuse _) = True
isAbort (Assertion False _) = True
isAbort _ = False
in
do
Expand All @@ -232,13 +233,13 @@ checkSolution taskData globalCode parseCode checkCode submission picPath = do
(refuse . code . showWithFieldNumber #{input})
(checkSyntax #{tData} #{path})
parsed
synRes <- OC.getOutputSequence syn
synRes <- OBT.getOutputSequence syn
if any isAbort synRes
then
pure (synRes,Nothing)
else do
let sem = checkSemantics #{tData} #{path} (E.fromRight undefined parsed)
semRes <- OC.getOutputSequenceWithRating sem
let sem = checkSemantics #{tData} #{path} (fromRight undefined parsed)
semRes <- OBT.getOutputSequenceWithRating sem
pure (synRes, Just semRes)
|]

Expand Down

0 comments on commit ed2eec2

Please sign in to comment.