From fed9f38d30f0d2a37042f9a88ec7f5248767ea58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 7 Aug 2024 21:41:09 +0200 Subject: Parser: collect toplevel definitions using Writer --- src/Parser/Core.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Parser/Core.hs') diff --git a/src/Parser/Core.hs b/src/Parser/Core.hs index b932523..341d9ca 100644 --- a/src/Parser/Core.hs +++ b/src/Parser/Core.hs @@ -2,6 +2,7 @@ module Parser.Core where import Control.Monad import Control.Monad.State +import Control.Monad.Writer import Data.Text (Text) import qualified Data.Text.Lazy as TL @@ -15,10 +16,13 @@ import qualified Text.Megaparsec.Char.Lexer as L import Network () import Test -type TestParser = ParsecT Void TestStream (State TestParserState) +type TestParser = ParsecT Void TestStream (WriterT [ Toplevel ] (State TestParserState)) type TestStream = TL.Text +data Toplevel + = ToplevelTest Test + data TestParserState = TestParserState { testVars :: [(VarName, SomeExprType)] , testContext :: SomeExpr @@ -65,8 +69,8 @@ localState inner = do put s return x -toplevel :: TestParser a -> TestParser a -toplevel = L.nonIndented scn +toplevel :: (a -> Toplevel) -> TestParser a -> TestParser () +toplevel f = tell . (: []) . f <=< L.nonIndented scn block :: (a -> [b] -> TestParser c) -> TestParser a -> TestParser b -> TestParser c block merge header item = L.indentBlock scn $ do -- cgit v1.2.3