Skip to content
Snippets Groups Projects
Commit 92ca859d authored by Alice Brenon's avatar Alice Brenon
Browse files

Encode punctuation characters with a <pc> instead of <w>

parent f3fdb961
No related branches found
No related tags found
No related merge requests found
...@@ -10,9 +10,9 @@ module Text.TEIWA.Annotation ( ...@@ -10,9 +10,9 @@ module Text.TEIWA.Annotation (
) where ) where
import Control.Monad.Except (MonadError(..)) import Control.Monad.Except (MonadError(..))
import Control.Monad.RWS (RWST, evalRWST, get, put, tell) import Control.Monad.RWS (RWST, evalRWST, get, put, reader, tell)
import Data.Text.Lazy as Text (Text, breakOn, concat, drop, length, unpack) import Data.Text.Lazy as Text (Text, breakOn, concat, drop, head, length, unpack)
import Text.TEIWA.Config (Config) import Text.TEIWA.Config (Config(..))
import Text.TEIWA.Error (Error(..)) import Text.TEIWA.Error (Error(..))
type Attributes = [(Text, Text)] type Attributes = [(Text, Text)]
...@@ -50,11 +50,15 @@ w = token "w" ...@@ -50,11 +50,15 @@ w = token "w"
check :: MonadError Error m => Maybe Text -> TokenAnnotation -> (Text, Text) -> Editor m check :: MonadError Error m => Maybe Text -> TokenAnnotation -> (Text, Text) -> Editor m
check openingTag expected@(TokenAnnotation {form}) (before, focused) = check openingTag expected@(TokenAnnotation {form}) (before, focused) =
let expectedLength = Text.length form in
if Text.length focused >= expectedLength if Text.length focused >= expectedLength
then put (Text.drop expectedLength focused) then do
*> mapM_ tell [before, maybe "" id openingTag, w expected] tagged <- reader (handle . punctuation)
put (Text.drop expectedLength focused)
mapM_ tell [before, maybe "" id openingTag, tagged]
else throwError (TermNotFound $ Text.unpack form) 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 :: MonadError Error m => Maybe Text -> [TokenAnnotation] -> Editor m
tokenLevel Nothing [] = pure () tokenLevel Nothing [] = pure ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment