medea 1.0.0 → 1.1.0
raw patch · 6 files changed
+34/−26 lines, 6 filesdep ~parser-combinators
Dependency ranges changed: parser-combinators
Files
- CHANGELOG.md +8/−0
- medea.cabal +3/−3
- src/Data/Medea.hs +2/−0
- src/Data/Medea/Loader.hs +5/−14
- src/Data/Medea/Parser/Types.hs +15/−7
- test/TestM.hs +1/−2
CHANGELOG.md view
@@ -1,3 +1,11 @@+# Dev++# 1.1.0++- Widen bounds on ``parser-combinators``.+- Export ``ParserError``, and have the loader return it on parsing errors.+- Remove -O2 optimization flag for test-suite.+ # 1.0.0 - Initial release
medea.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: medea-version: 1.0.0+version: 1.1.0 synopsis: A schema language for JSON. description: A reference implementation of a schema language, together with a conformance@@ -35,7 +35,7 @@ -Wincomplete-uni-patterns -Wredundant-constraints common test-common- ghc-options: -O2 -threaded -with-rtsopts=-N+ ghc-options: -threaded -with-rtsopts=-N library import: lang-common@@ -69,7 +69,7 @@ , microlens-ghc ^>=0.4.12 , mtl ^>=2.2.2 , nonempty-containers ^>=0.3.3.0- , parser-combinators ^>=1.1.0+ , parser-combinators >=1.1.0 && <2.0.0 , scientific ^>=0.3.6.2 , text ^>=1.2.3.1 , unordered-containers ^>=0.2.10.0
src/Data/Medea.hs view
@@ -48,6 +48,7 @@ ( -- * Schema loading Schema, LoaderError (..),+ ParseError (..), buildSchema, loadSchemaFromFile, loadSchemaFromHandle,@@ -93,6 +94,7 @@ loadSchemaFromHandle, ) import Data.Medea.Parser.Primitive (Identifier (..), ReservedIdentifier (..), identFromReserved)+import Data.Medea.Parser.Types (ParseError(..)) import Data.Medea.Schema (Schema (..)) import Data.Medea.ValidJSON (ValidJSONF (..)) import qualified Data.Set as S
src/Data/Medea/Loader.hs view
@@ -12,32 +12,27 @@ import Control.Monad.Except (MonadError (..), runExcept) import Control.Monad.IO.Class (MonadIO (..)) import Data.ByteString (ByteString, hGetContents, readFile)-import qualified Data.List.NonEmpty as NE import Data.Medea.Analysis ( AnalysisError (..), compileSchemata, ) import Data.Medea.Parser.Primitive (toText, unwrap) import qualified Data.Medea.Parser.Spec.Schemata as Schemata+import Data.Medea.Parser.Types (ParseError) import Data.Medea.Schema (Schema (..)) import Data.Text (Text) import Data.Text.Encoding (decodeUtf8')-import Data.Void (Void) import System.IO (Handle)-import Text.Megaparsec (ParseError (..), bundleErrors, parse)+import Text.Megaparsec (ParseErrorBundle, parse) import Prelude hiding (readFile) -- | Possible errors from loading Medea schemata. data LoaderError = -- | The data provided wasn't UTF-8. NotUtf8- | -- | An identifier was longer than allowed.- IdentifierTooLong- | -- | A length specification had no minimum/maximum specification.- EmptyLengthSpec | -- | Parsing failed.- ParserError - !(ParseError Text Void) -- ^ The error we got. + ParsingFailed+ !(ParseErrorBundle Text ParseError) -- ^ The errors we got. | -- | No schema labelled @$start@ was provided. StartSchemaMissing | -- | A schema was typed in terms of itself.@@ -136,11 +131,7 @@ m Schemata.Specification fromUtf8 sourceName utf8 = case parse Schemata.parseSpecification sourceName utf8 of- Left err -> case NE.head . bundleErrors $ err of- TrivialError o u e ->- throwError . ParserError . TrivialError o u $ e- -- TODO: Handle all kinds of ParseError- FancyError {} -> throwError IdentifierTooLong+ Left err -> throwError . ParsingFailed $ err Right scm -> pure scm analyze ::
src/Data/Medea/Parser/Types.hs view
@@ -5,14 +5,22 @@ import Data.Text (Text) import Text.Megaparsec (Parsec, ShowErrorComponent, showErrorComponent) +-- | All possible errors from the Medea parser. data ParseError- = IdentifierTooLong {-# UNPACK #-} !Text- | ExpectedReservedIdentifier {-# UNPACK #-} !Text- | LeadingZero {-# UNPACK #-} !Text- | ConflictingSpecRequirements- | EmptyLengthArraySpec- | EmptyArrayElements- | EmptyStringValuesSpec+ = -- | An identifier exceeded 32 bytes.+ IdentifierTooLong {-# UNPACK #-} !Text+ | -- | We saw a non-reserved identifier where we wanted a reserved one.+ ExpectedReservedIdentifier {-# UNPACK #-} !Text+ | -- | A Medea natural number had literal zeroes.+ LeadingZero {-# UNPACK #-} !Text+ | -- | We were given incompatible requirements within a specification.+ ConflictingSpecRequirements+ | -- | We were not given a length in an array specification.+ EmptyLengthArraySpec+ | -- | We were not given an element specification in an array specification.+ EmptyArrayElements+ | -- | We were given no string values in a string specification.+ EmptyStringValuesSpec deriving stock (Eq, Ord, Show) instance ShowErrorComponent ParseError where
test/TestM.hs view
@@ -25,8 +25,7 @@ isParseError :: Either LoaderError a -> Bool isParseError (Left NotUtf8) = True-isParseError (Left IdentifierTooLong) = True-isParseError (Left (ParserError _)) = True+isParseError (Left (ParsingFailed _)) = True isParseError _ = False isSchemaError :: Either LoaderError a -> Bool