From 47d14bfe1dc81d3a2d5a28d1eaf2c7bb920127cd Mon Sep 17 00:00:00 2001 From: Conjunctive Date: Thu, 16 Nov 2023 19:44:48 -0800 Subject: [PATCH] Ignore bodies of text beginning with session keywords --- chat-bots-contrib/test/Spec.hs | 8 ++++++++ chat-bots/src/Data/Chat/Bot/Context.hs | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/chat-bots-contrib/test/Spec.hs b/chat-bots-contrib/test/Spec.hs index 00e1e1d..6888dff 100644 --- a/chat-bots-contrib/test/Spec.hs +++ b/chat-bots-contrib/test/Spec.hs @@ -142,3 +142,11 @@ sessionizedBotSpec = <<>>new body of text that happens to begin with the word new + >>>use body of text that begins with the word use + >>>end body of text that begins with the word end + |] diff --git a/chat-bots/src/Data/Chat/Bot/Context.hs b/chat-bots/src/Data/Chat/Bot/Context.hs index 9513ffd..9186526 100644 --- a/chat-bots/src/Data/Chat/Bot/Context.hs +++ b/chat-bots/src/Data/Chat/Bot/Context.hs @@ -134,7 +134,9 @@ sessionizedParser :: (Text -> Maybe i) -> Parser (SessionInput i) sessionizedParser p = do keyword <- New <$ "new" <|> Use <$ "use" <|> End <$ "end" case keyword of - New -> pure StartSession + New -> do + _ <- endOfInput <|> endOfLine + pure StartSession Use -> do _ <- space n <- decimal <* ": "