From 92ca859da1e61e43446f67806d15c336bddf6a63 Mon Sep 17 00:00:00 2001 From: Alice BRENON <alice.brenon@ens-lyon.fr> Date: Mon, 15 Mar 2021 13:36:35 +0100 Subject: [PATCH] Encode punctuation characters with a <pc> instead of <w> --- lib/Text/TEIWA/Annotation.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Text/TEIWA/Annotation.hs b/lib/Text/TEIWA/Annotation.hs index 39f7b39..12e3aec 100644 --- a/lib/Text/TEIWA/Annotation.hs +++ b/lib/Text/TEIWA/Annotation.hs @@ -10,9 +10,9 @@ module Text.TEIWA.Annotation ( ) where import Control.Monad.Except (MonadError(..)) -import Control.Monad.RWS (RWST, evalRWST, get, put, tell) -import Data.Text.Lazy as Text (Text, breakOn, concat, drop, length, unpack) -import Text.TEIWA.Config (Config) +import Control.Monad.RWS (RWST, evalRWST, get, put, reader, tell) +import Data.Text.Lazy as Text (Text, breakOn, concat, drop, head, length, unpack) +import Text.TEIWA.Config (Config(..)) import Text.TEIWA.Error (Error(..)) type Attributes = [(Text, Text)] @@ -50,11 +50,15 @@ w = token "w" check :: MonadError Error m => Maybe Text -> TokenAnnotation -> (Text, Text) -> Editor m check openingTag expected@(TokenAnnotation {form}) (before, focused) = - let expectedLength = Text.length form in if Text.length focused >= expectedLength - then put (Text.drop expectedLength focused) - *> mapM_ tell [before, maybe "" id openingTag, w expected] + then do + tagged <- reader (handle . punctuation) + put (Text.drop expectedLength focused) + mapM_ tell [before, maybe "" id openingTag, tagged] else throwError (TermNotFound $ Text.unpack form) + where + expectedLength = Text.length form + handle f = (if expectedLength == 1 && f (Text.head form) then pc else w) expected tokenLevel :: MonadError Error m => Maybe Text -> [TokenAnnotation] -> Editor m tokenLevel Nothing [] = pure () -- GitLab