currycarbon 0.4.0.1 → 0.5.0.0
raw patch · 7 files changed
+59/−27 lines, 7 filesdep ~optparse-applicativePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: optparse-applicative
API changes (from Hackage documentation)
+ Currycarbon.CalCurves: readCalCurveUnsafe :: String -> CalCurveBP
+ Currycarbon.ParserHelpers: cleanParsecErr :: ParseError -> String
+ Currycarbon.ParserHelpers: showParsecErrOneLine :: ParseError -> String
- Currycarbon.CalCurves: readCalCurve :: String -> CalCurveBP
+ Currycarbon.CalCurves: readCalCurve :: String -> Either String CalCurveBP
Files
- CHANGELOG.md +4/−0
- README.md +2/−2
- currycarbon.cabal +3/−3
- src-executables/Main-currycarbon.hs +1/−2
- src/Currycarbon/CalCurves.hs +24/−11
- src/Currycarbon/ParserHelpers.hs +16/−0
- src/Currycarbon/Parsers.hs +9/−9
CHANGELOG.md view
@@ -1,3 +1,7 @@+- V 0.5.0.0: Cleaned up parser error behaviour:+ - Parsing errors are now more helpful with better positional information, using a modified `showParsecErr` and a new `showParsecErrOneLine`.+ - Breaking change: The type of `readCalCurve` changed. It is now safe, returning `Either String CalCurveBP`. The old version is preserved in `readCalCurveUnsafe`.+- V 0.4.0.2: Support for `optparse-applicative-0.19.0.0`. - V 0.4.0.1: Support for `random-1.3`. Now possible, because MonadRandom supports it as well (https://github.com/byorgey/MonadRandom/blob/master/CHANGES.markdown#062-5-march-2025). - V 0.4.0.0: Another major update: - Added more calibration curves next to `intcal20`: `shcal20` and `marine20`. Renamed the `Currycarbon.CalCurves.IntCal20` module to just `Currycarbon.CalCurves`. In the CLI, `--calCurveFile` is now just `--calCurve`, and it allows to either select the different packaged curves or read arbitrary .14c files.
README.md view
@@ -32,7 +32,7 @@ ``` ```-currycarbon v0.4.0.0 (UTF-8)+currycarbon v0.4.0.2 (UTF-8) Method: Bchron {distribution = StudentTDist {ndf = 100.0}} Curve: IntCal20 Calibrating...@@ -74,7 +74,7 @@ [[--seed INT] (-n|--nrSamples INT) --samplesFile FILE] [--calCurveSegFile FILE] [--calCurveMatFile FILE] - Intercept calibration of radiocarbon dates+ currycarbon calibrates radiocarbon dates Available options: -h,--help Show this help text
currycarbon.cabal view
@@ -1,7 +1,7 @@ name: currycarbon-version: 0.4.0.1+version: 0.5.0.0 synopsis: A package for simple, fast radiocarbon calibration-description: Radiocarbon calibration with the intercept method optimised for fast calibration of many dates.+description: Radiocarbon calibration library and command line tool. homepage: https://github.com/nevrome/currycarbon category: Archaeoinformatics author: Clemens Schmid@@ -54,7 +54,7 @@ build-depends: currycarbon , base >= 4.14 && < 5- , optparse-applicative >= 0.16 && < 0.19+ , optparse-applicative >= 0.16 && < 0.21 , filepath >= 1.4 && < 1.6 other-modules: Paths_currycarbon
src-executables/Main-currycarbon.hs view
@@ -47,8 +47,7 @@ optParserInfo :: OP.ParserInfo Options optParserInfo = OP.info (OP.helper <*> versionOption <*> optParser) (- OP.briefDesc <>- OP.progDesc "Intercept calibration of radiocarbon dates"+ OP.progDesc "currycarbon calibrates radiocarbon dates" ) versionOption :: OP.Parser (a -> a)
src/Currycarbon/CalCurves.hs view
@@ -4,7 +4,9 @@ import Currycarbon.ParserHelpers import Currycarbon.Types+import Currycarbon.Utils +import Control.Exception (throwIO) import qualified Data.FileEmbed as FE import qualified Data.Vector.Unboxed as VU import qualified Text.Parsec as P@@ -22,8 +24,8 @@ readCalCurveSelection :: String -> Either String CalCurveSelection readCalCurveSelection s =- case P.runParser parseCalCurveSelection () "" s of- Left err -> Left $ showParsecErr err+ case P.runParser parseCalCurveSelection () s s of+ Left err -> Left $ showParsecErrOneLine err Right x -> Right x parseCalCurveSelection :: P.Parser CalCurveSelection@@ -44,18 +46,29 @@ -- | Read a calibration curve file. The file must adhere to the .14c file format. readCalCurveFromFile :: FilePath -> IO CalCurveBP readCalCurveFromFile calCurveFile = do- calCurve <- readFile calCurveFile- return $ readCalCurve calCurve+ calCurveString <- readFile calCurveFile+ case readCalCurve calCurveString of+ Left err -> throwIO $ CurrycarbonCLIParsingException err+ Right x -> return x -readCalCurve :: String -> CalCurveBP+readCalCurve :: String -> Either String CalCurveBP readCalCurve calCurveString = do- case P.runParser parseCalCurve () "" calCurveString of- Left p -> error $ "This should never happen." ++ show p- Right x -> CalCurveBP+ case P.runParser parseCalCurve () "calCurve" calCurveString of+ Left err -> Left $ showParsecErr err+ Right x -> Right $ CalCurveBP (VU.fromList $ map (\(a,_,_) -> a) x) (VU.fromList $ map (\(_,b,_) -> b) x) (VU.fromList $ map (\(_,_,c) -> c) x) +readCalCurveUnsafe :: String -> CalCurveBP+readCalCurveUnsafe calCurveString = do+ case P.runParser parseCalCurve () "calCurve" calCurveString of+ Left err -> error $ "Error when reading calCurve " ++ show err+ Right x -> CalCurveBP+ (VU.fromList $ map (\(a,_,_) -> a) x)+ (VU.fromList $ map (\(_,b,_) -> b) x)+ (VU.fromList $ map (\(_,_,c) -> c) x)+ parseCalCurve :: P.Parser [(YearBP, YearBP, YearRange)] parseCalCurve = do P.skipMany comments@@ -79,20 +92,20 @@ -- | The intcal20 calibration curve -- (Reimer et al. 2020, doi: [10.1017/RDC.2020.41](https://doi.org/10.1017/RDC.2020.41)) intcal20 :: CalCurveBP-intcal20 = readCalCurve intcal20String+intcal20 = readCalCurveUnsafe intcal20String intcal20String :: String intcal20String = $(FE.makeRelativeToProject "data/intcal20.14c" >>= FE.embedStringFile) -- | The shcal20 calibration curve -- (Hogg et al. 2020, doi: [10.1017/RDC.2020.59](https://doi.org/10.1017/RDC.2020.59)) shcal20 :: CalCurveBP-shcal20 = readCalCurve shcal20String+shcal20 = readCalCurveUnsafe shcal20String shcal20String :: String shcal20String = $(FE.makeRelativeToProject "data/shcal20.14c" >>= FE.embedStringFile) -- | The shcal20 calibration curve -- (Heaton et al. 2020, doi: [10.1017/RDC.2020.68](https://doi.org/10.1017/RDC.2020.68)) marine20 :: CalCurveBP-marine20 = readCalCurve marine20String+marine20 = readCalCurveUnsafe marine20String marine20String :: String marine20String = $(FE.makeRelativeToProject "data/marine20.14c" >>= FE.embedStringFile)
src/Currycarbon/ParserHelpers.hs view
@@ -158,6 +158,22 @@ showParsecErr :: P.ParseError -> String showParsecErr err =+ let pos = P.errorPos err+ posStr = P.sourceName pos +++ " (issue in line " ++ show (P.sourceLine pos) +++ ", column " ++ show (P.sourceColumn pos) +++ ")"+ in posStr ++ ": " ++ cleanParsecErr err++showParsecErrOneLine :: P.ParseError -> String+showParsecErrOneLine err =+ let pos = P.errorPos err+ posStr = P.sourceName pos +++ " (issue in column " ++ show (P.sourceColumn pos) ++ ")"+ in posStr ++ ": " ++ cleanParsecErr err++cleanParsecErr :: P.ParseError -> String+cleanParsecErr err = P.showErrorMessages "or" "unknown parse error" "expecting" "unexpected" "end of input"
src/Currycarbon/Parsers.hs view
@@ -26,8 +26,8 @@ readCalibrationMethod :: String -> Either String CalibrationMethod readCalibrationMethod s =- case P.runParser parseCalibrationMethod () "" s of- Left err -> Left $ showParsecErr err+ case P.runParser parseCalibrationMethod () s s of+ Left err -> Left $ showParsecErrOneLine err Right x -> Right x parseCalibrationMethod :: P.Parser CalibrationMethod@@ -201,8 +201,8 @@ readNamedCalExprs :: String -> Either String [NamedCalExpr] readNamedCalExprs s =- case P.runParser parseCalExprSepBySemicolon () "" s of- Left err -> Left $ showParsecErr err+ case P.runParser parseCalExprSepBySemicolon () s s of+ Left err -> Left $ showParsecErrOneLine err Right x -> Right x where parseCalExprSepBySemicolon :: P.Parser [NamedCalExpr]@@ -210,8 +210,8 @@ readOneNamedCalExpr :: String -> Either String NamedCalExpr readOneNamedCalExpr s =- case P.runParser namedExpr () "" s of- Left err -> Left $ showParsecErr err+ case P.runParser namedExpr () s s of+ Left err -> Left $ showParsecErrOneLine err Right x -> Right x readNamedCalExprsFromFile :: FilePath -> IO [NamedCalExpr]@@ -244,7 +244,7 @@ readUncalC14FromFile :: FilePath -> IO [UncalC14] readUncalC14FromFile uncalFile = do s <- readFile uncalFile- case P.runParser uncalC14SepByNewline () "" s of+ case P.runParser uncalC14SepByNewline () uncalFile s of Left err -> throwIO $ CurrycarbonCLIParsingException $ showParsecErr err Right x -> return x where@@ -253,8 +253,8 @@ readUncalC14 :: String -> Either String [UncalC14] readUncalC14 s =- case P.runParser uncalC14SepBySemicolon () "" s of- Left err -> Left $ showParsecErr err+ case P.runParser uncalC14SepBySemicolon () s s of+ Left err -> Left $ showParsecErrOneLine err Right x -> Right x where uncalC14SepBySemicolon :: P.Parser [UncalC14]