packages feed

skylighting-core 0.14.1.2 → 0.14.2

raw patch · 3 files changed

+33/−3 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Skylighting.Loader: loadValidSyntaxesFromDir :: FilePath -> IO (LoadErrMap, SyntaxMap)

Files

changelog.md view
@@ -1,5 +1,15 @@ # Revision history for skylighting and skylighting-core +## 0.14.2++  * Add `loadValidSyntaxesFromDir` (Kevin Quick) [API change].+    The `loadSyntaxesFromDir` function is an all-or-nothing function:+    a single invalid file results in a error and *no* loaded syntaxes.+    This adds the `loadValidSyntaxesFromDir`, which is resilient+    against individual syntax file load failures.  It returns a map+    of the failure messages, and the SyntaxMap that is created from+    all the successful parsing.+ ## 0.14.1.2    * Add terraform syntax (#190).
skylighting-core.cabal view
@@ -1,5 +1,5 @@ name:                skylighting-core-version:             0.14.1.2+version:             0.14.2 synopsis:            syntax highlighting library description:         Skylighting is a syntax highlighting library.                      It derives its tokenizers from XML syntax@@ -21,7 +21,7 @@ license-file:        LICENSE author:              John MacFarlane maintainer:          jgm@berkeley.edu-copyright:           (C) 2016-2018 John MacFarlane+copyright:           (C) 2016-2024 John MacFarlane category:            Text build-type:          Simple extra-source-files:  README.md
src/Skylighting/Loader.hs view
@@ -1,8 +1,10 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE LambdaCase #-} -- | This module provides routines to load syntax definitions from disk -- files. module Skylighting.Loader ( loadSyntaxFromFile                           , loadSyntaxesFromDir+                          , loadValidSyntaxesFromDir                           )                           where @@ -37,7 +39,8 @@ -- | Loads all syntax definitions from the specified directory by -- looking for files with an ".xml" extension. This function assumes -- such files are Kate XML syntax definitions, so XML files with--- unexpected contents will cause a parsing error returned as a 'Left'.+-- unexpected contents will cause a parsing error returned as a 'Left'+-- and syntax parsing will be aborted. loadSyntaxesFromDir :: FilePath -> IO (Either String SyntaxMap) loadSyntaxesFromDir path = runExceptT $ do     files <- liftIO $ syntaxFiles path@@ -54,3 +57,20 @@     entries <- listDirectory dir     let absEntries = (dir </>) <$> filter isSyntaxFile entries     filterM doesFileExist absEntries++-- | Loads all valid syntax definitions from the specified directory by looking+-- for files with an ".xml" extension.  Any files that are not valid Kate XML+-- syntax definitions will have an entry in the resulting error map; the returned+-- SyntaxMap will be made up of only the files that could successfully be loaded+-- and parsed.+loadValidSyntaxesFromDir :: FilePath -> IO (LoadErrMap, SyntaxMap)+loadValidSyntaxesFromDir path = foldM go (mempty, mempty) =<< syntaxFiles path+  where+    go (errMap, syntaxMap) file =+      loadSyntaxFromFile file >>= \case+        Right s -> return (errMap, addSyntaxDefinition s syntaxMap)+        Left e -> return (M.insert file e errMap, syntaxMap)++-- | A map from a potential syntax file to the error encountered when trying to+-- load that syntax file.+type LoadErrMap = M.Map FilePath String