ref: Move JournalParser and ErroringJournalParser to Hledger.Data.Journal.

This is so that Hledger.Utils does not depend on Hledger.Data in any
way, and allows us more flexibility in refactoring Hledger.Data.
This commit is contained in:
Stephen Morgan 2021-09-01 11:22:16 +10:00 committed by Simon Michael
parent 993e381307
commit c1d85ba17c
2 changed files with 14 additions and 14 deletions

View File

@ -15,6 +15,8 @@ other data format (see "Hledger.Read").
module Hledger.Data.Journal (
-- * Parsing helpers
JournalParser,
ErroringJournalParser,
addPriceDirective,
addTransactionModifier,
addPeriodicTransaction,
@ -100,6 +102,7 @@ import Control.Monad.Except (ExceptT(..), runExceptT, throwError)
import "extra" Control.Monad.Extra (whenM)
import Control.Monad.Reader as R
import Control.Monad.ST (ST, runST)
import Control.Monad.State.Strict (StateT)
import Data.Array.ST (STArray, getElems, newListArray, writeArray)
import Data.Char (toUpper, isDigit)
import Data.Default (Default(..))
@ -119,6 +122,8 @@ import Data.Time.Calendar (Day, addDays, fromGregorian)
import Data.Time.Clock.POSIX (POSIXTime)
import Data.Tree (Tree, flatten)
import Text.Printf (printf)
import Text.Megaparsec (ParsecT)
import Text.Megaparsec.Custom (FinalParseError)
import Hledger.Utils
import Hledger.Data.Types
@ -131,6 +136,15 @@ import Hledger.Data.Posting
import Hledger.Query
-- | A parser of text that runs in some monad, keeping a Journal as state.
type JournalParser m a = StateT Journal (ParsecT CustomErr Text m) a
-- | A parser of text that runs in some monad, keeping a Journal as
-- state, that can throw an exception to end parsing, preventing
-- further parser backtracking.
type ErroringJournalParser m a =
StateT Journal (ParsecT CustomErr Text (ExceptT FinalParseError m)) a
-- deriving instance Show Journal
instance Show Journal where
show j

View File

@ -5,8 +5,6 @@ module Hledger.Utils.Parse (
SimpleStringParser,
SimpleTextParser,
TextParser,
JournalParser,
ErroringJournalParser,
choice',
choiceInState,
@ -34,7 +32,6 @@ module Hledger.Utils.Parse (
)
where
import Control.Monad.Except (ExceptT)
import Control.Monad.State.Strict (StateT, evalStateT)
import Data.Char
import Data.Functor (void)
@ -46,8 +43,6 @@ import Text.Megaparsec.Char
import Text.Megaparsec.Custom
import Text.Printf
import Hledger.Data.Types
-- | A parser of string to some type.
type SimpleStringParser a = Parsec CustomErr String a
@ -57,15 +52,6 @@ type SimpleTextParser = Parsec CustomErr Text -- XXX an "a" argument breaks the
-- | A parser of text that runs in some monad.
type TextParser m a = ParsecT CustomErr Text m a
-- | A parser of text that runs in some monad, keeping a Journal as state.
type JournalParser m a = StateT Journal (ParsecT CustomErr Text m) a
-- | A parser of text that runs in some monad, keeping a Journal as
-- state, that can throw an exception to end parsing, preventing
-- further parser backtracking.
type ErroringJournalParser m a =
StateT Journal (ParsecT CustomErr Text (ExceptT FinalParseError m)) a
-- | Backtracking choice, use this when alternatives share a prefix.
-- Consumes no input if all choices fail.
choice' :: [TextParser m a] -> TextParser m a