Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Delayed type abstract #127

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/Formula/Parsing/Delayed.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DeriveGeneric #-}
module Formula.Parsing.Delayed where

module Formula.Parsing.Delayed (Delayed, delayed, parseDelayed, parseDelayedRaw, withDelayed) where

import Text.Parsec
import Text.Parsec.String (Parser)
Expand All @@ -11,20 +9,20 @@ import Control.Monad.Output (LangM, english, german, OutputMonad)

import LogicTasks.Helpers (reject)

import Data.Typeable (Typeable)
import GHC.Generics (Generic)

newtype Delayed a = Delayed String deriving (Eq, Show, Typeable, Generic)
newtype Delayed a = Delayed String

delayed :: String -> Delayed a
delayed = Delayed

parseDelayed :: Delayed a -> Parser a -> Either ParseError a
parseDelayed (Delayed str) p = parse p "(delayed input)" str
parseDelayed :: Parser a -> Delayed a -> Either ParseError a
parseDelayed = parseDelayedRaw

parseDelayedRaw :: Parser b -> Delayed a -> Either ParseError b
parseDelayedRaw p (Delayed str) = parse p "(answer string)" str

withDelayed :: OutputMonad m => (a -> LangM m) -> Parser a -> Delayed a -> LangM m
withDelayed grade p d =
case parseDelayed d (fully p) of
case parseDelayed (fully p) d of
Left err -> reject $ do
english $ show err
german $ show err
Expand Down
9 changes: 4 additions & 5 deletions src/LogicTasks/Syntax/TreeToFormula.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ import Formula.Util (isSemanticEqual)
import Control.Monad (when)
import Trees.Print (transferToPicture)
import Tasks.TreeToFormula.Config (TreeToFormulaInst(..))
import Formula.Parsing.Delayed (Delayed (..), withDelayed)
import Formula.Parsing.Delayed (Delayed, withDelayed, parseDelayed, parseDelayedRaw)
import Formula.Parsing (Parse(..))
import Trees.Parsing()
import Text.Parsec (parse)
import UniversalParser (tokenSequence)
import ParsingHelpers (fully)

Expand Down Expand Up @@ -78,10 +77,10 @@ start :: TreeFormulaAnswer
start = TreeFormulaAnswer Nothing

partialGrade :: OutputMonad m => TreeToFormulaInst -> Delayed TreeFormulaAnswer -> LangM m
partialGrade inst (Delayed ans) =
case parse (fully $ parser @TreeFormulaAnswer) "(delayed input)" ans of
partialGrade inst ans =
case parseDelayed (fully $ parser @TreeFormulaAnswer) ans of
Right f -> partialGrade' inst f
Left err -> reject $ case parse (fully tokenSequence) "" ans of
Left err -> reject $ case parseDelayedRaw (fully tokenSequence) ans of
Left _ -> do
german $ show err
english $ show err
Expand Down
Loading