From 516bc2d21f5e6f95623dc4d90cac050e2210ba05 Mon Sep 17 00:00:00 2001 From: Steven van den Broek Date: Sat, 18 Jul 2020 15:13:34 +0200 Subject: [PATCH] Add possibility to escape underscores --- cards/analysis3.txt | 6 +++--- src/Parser.hs | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cards/analysis3.txt b/cards/analysis3.txt index e014685..42ce513 100644 --- a/cards/analysis3.txt +++ b/cards/analysis3.txt @@ -32,9 +32,9 @@ For any closed surface in D, the domain enclosed by S is completely in D. Exs: s --- # Second derivative test -f_xx * f_yy - f_xy^2 > 0 && f_xx > 0 => local min -f_xx * f_yy - f_xy^2 > 0 && f_xx < 0 => local max -f_xx * f_yy - f_xy^2 < 0 => saddle point +f\_xx * f\_yy - f\_xy^2 > 0 && f\_xx > 0 => local min +f\_xx * f\_yy - f\_xy^2 > 0 && f\_xx < 0 => local max +f\_xx * f\_yy - f\_xy^2 < 0 => saddle point --- diff --git a/src/Parser.hs b/src/Parser.hs index 249037e..bbfb88c 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -83,9 +83,12 @@ pSentence = try pPerforated pPerforated = do (pre, gap) <- pGap Perforated pre gap <$> pSentence - + +chars = escaped <|> anyChar +escaped = char '\\' >> char '_' + pGap = do - pre <- manyTill anyChar $ lookAhead (try gappedSpecialChars) + pre <- manyTill chars $ lookAhead (try gappedSpecialChars) char '_' gaps <- manyTill (noneOf "_|") (lookAhead (try gappedSpecialChars)) `sepBy1` string "|" char '_' @@ -102,7 +105,7 @@ pNormal = do pDef = do header <- pHeader many eol - descr <- manyTill anyChar $ lookAhead (try seperator) + descr <- manyTill chars $ lookAhead (try seperator) return (header, descr) eol = try (string "\n\r") @@ -123,6 +126,7 @@ makeMultipleChoice options = makeMultipleChoice' [] [] 0 options makeMultipleChoice' _ _ _ [] = error ("multiple choice had multiple correct answers: \n" ++ show options) makeMultipleChoice' cs ics i (('-', text) : opts) = makeMultipleChoice' cs (IncorrectOption text : ics) (i+1) opts makeMultipleChoice' cs ics i (('*', text) : opts) = makeMultipleChoice' (CorrectOption i text : cs) ics (i+1) opts + makeMultipleChoice' _ _ _ _ = error "impossible" makeOption :: Char -> String -> Option makeOption kind text