packages feed

skylighting-core 0.15.0.1 → 0.15.1

raw patch · API changes only · 5 files changed · show whitespace changes · browse skylighting-core-0.15.1

+49/−22 lines, 5 filesPVP ok

API changes (from Hackage documentation)

No changes to the public API.

version bump matches the API change (PVP)

Files

changelog.md view
@@ -1,5 +1,22 @@ # Revision history for skylighting and skylighting-core +## 0.15.1++  * Embed syntax definitions as primitive string literals (#216).+    The generated syntax modules contained `decode "..."` with+    OverloadedStrings, so the serialized syntax was an ordinary string+    literal.  Because it contains NUL and non-ASCII bytes, ghc stores it in+    modified UTF-8, and at runtime it was decoded into a String and+    repacked into a lazy ByteString before being decoded with binary.+    skylighting-extract now emits a primitive string literal ("..."#),+    which ghc stores as raw bytes, and wraps it with unsafePackLenLiteral,+    which does not copy.  This roughly halves the cost of loading a+    syntax definition, and makes the library slightly smaller.++  * skylighting now depends directly on bytestring.++  * Remove obsolete derivations of Typeable.+ ## 0.15.0.1   * Update syntax definitions for csv, isocpp, json, perl, raku,
bin/extract.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE Arrows #-}  import Data.Binary (encode)+import qualified Data.ByteString.Lazy as BL import Data.List (intercalate, isInfixOf, sortOn) import qualified Data.Text as Text import Skylighting.Loader (loadSyntaxesFromDir)@@ -77,8 +78,9 @@ writeModuleFor syn = do   let fp = toPathName syn   putStrLn $ "Writing " ++ fp+  let bytes = encode syn   writeFile fp $ unlines $-    [ "{-# LANGUAGE OverloadedStrings #-}"+    [ "{-# LANGUAGE MagicHash #-}"     , "-- | Automatically generated syntax definition for " ++         Text.unpack (sName syn) ++ "."     , "-- DO NOT EDIT THIS FILE MANUALLY."@@ -87,17 +89,26 @@         " (syntax) where"     , ""     , "import Skylighting.Types"-    , "import Data.Binary"+    , "import Data.Binary (decode)"+    , "import qualified Data.ByteString.Lazy as BL"+    , "import Data.ByteString.Internal (unsafePackLenLiteral)"     , ""     , "-- | Syntax definition for " ++ Text.unpack (sName syn) ++ "."     , "syntax :: Syntax"-    , "syntax = decode " ++ show (encode syn) ]+    , "syntax = decode $ BL.fromStrict $ unsafePackLenLiteral " +++        show (BL.length bytes)+    , "  " ++ show bytes ++ "#" ] --- NOTE:  we include string representation of the Syntax,+-- NOTE:  we include a binary serialization of the Syntax, -- which we then 'decode', rather than the code for the Syntax, -- because ghc doesn't deal well with large data structure -- literals.  For background see jgm/skylighting#7 and --  http://stackoverflow.com/questions/16348340/compiling-very-large-constants-with-ghc+--+-- The serialization is emitted as a primitive string literal+-- ("..."#), which ghc stores as raw bytes, and wrapped in a+-- ByteString without copying.  An ordinary string literal would be+-- decoded into a String and repacked every time a syntax is loaded.  toPathName :: Syntax -> String toPathName s =
skylighting-core.cabal view
@@ -1,5 +1,5 @@ name:                skylighting-core-version:             0.15.0.1+version:             0.15.1 synopsis:            syntax highlighting library description:         Skylighting is a syntax highlighting library.                      It derives its tokenizers from XML syntax@@ -190,6 +190,7 @@                        filepath,                        text,                        binary,+                       bytestring,                        containers,                        directory   if flag(executable)
src/Skylighting/Regex.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP                 #-}-{-# LANGUAGE DeriveDataTypeable  #-} {-# LANGUAGE DeriveGeneric       #-} {-# LANGUAGE OverloadedStrings   #-} {-# LANGUAGE PatternSynonyms #-}@@ -38,7 +37,7 @@   , _reCaseSensitive :: Bool   , _reMinimal       :: Bool   , _reCompiled      :: Either String (Regex, M.IntMap Regex)-} deriving Typeable+}  -- We define a smart constructor which also holds the compiled regex -- and its capturing groups, to avoid recomputing them each time we
src/Skylighting/Types.hs view
@@ -55,7 +55,6 @@ import qualified Data.Set as Set import Data.Text (Text) import qualified Data.Text as Text-import Data.Typeable (Typeable) import Data.Word import GHC.Generics (Generic) import Safe (readMay)@@ -71,14 +70,14 @@   KeywordAttr  { keywordCaseSensitive :: !Bool                , keywordDelims        :: !(Set.Set Char)                }-  deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+  deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary KeywordAttr  -- | A set of "words," possibly case insensitive. data WordSet a = CaseSensitiveWords !(Set.Set a)                | CaseInsensitiveWords !(Set.Set a)-     deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+     deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary a => Binary (WordSet a) @@ -113,14 +112,14 @@   | IncludeRules !ContextName   | DetectSpaces   | DetectIdentifier-  deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+  deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary Matcher  -- | A context switch, either pops or pushes a context. data ContextSwitch =   Pop | Push !ContextName-  deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+  deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary ContextSwitch @@ -138,14 +137,14 @@   , rFirstNonspace    :: !Bool   , rColumn           :: !(Maybe Int)   , rContextSwitch    :: ![ContextSwitch]-  } deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+  } deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary Rule  -- | A list item is either just a textual value or an included list. -- IncludeList (x,y) includes list y from syntax with full name x. data ListItem = Item !Text | IncludeList !(Text, Text)-  deriving (Show, Eq, Ord, Read, Data, Typeable, Generic)+  deriving (Show, Eq, Ord, Read, Data, Generic)  instance Binary ListItem @@ -162,7 +161,7 @@   , sLicense         :: !Text   , sExtensions      :: ![String]   , sStartingContext :: !Text-  } deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+  } deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary Syntax @@ -181,7 +180,7 @@   , cFallthrough        :: !Bool   , cFallthroughContext :: ![ContextSwitch]   , cDynamic            :: !Bool-} deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+} deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary Context @@ -221,7 +220,7 @@                | AlertTok                | ErrorTok                | NormalTok-               deriving (Read, Show, Eq, Ord, Enum, Bounded, Data, Typeable, Generic)+               deriving (Read, Show, Eq, Ord, Enum, Bounded, Data, Generic)  instance Binary TokenType @@ -259,7 +258,7 @@   , tokenBold       :: !Bool   , tokenItalic     :: !Bool   , tokenUnderline  :: !Bool-  } deriving (Show, Read, Ord, Eq, Data, Typeable, Generic)+  } deriving (Show, Read, Ord, Eq, Data, Generic)  instance Binary TokenStyle @@ -298,7 +297,7 @@  -- | A color (red, green, blue). data Color = RGB Word8 Word8 Word8-  deriving (Show, Read, Ord, Eq, Data, Typeable, Generic)+  deriving (Show, Read, Ord, Eq, Data, Generic)  instance Binary Color @@ -370,7 +369,7 @@   , backgroundColor           :: !(Maybe Color)   , lineNumberColor           :: !(Maybe Color)   , lineNumberBackgroundColor :: !(Maybe Color)-  } deriving (Read, Show, Eq, Ord, Data, Typeable, Generic)+  } deriving (Read, Show, Eq, Ord, Data, Generic)  instance Binary Style @@ -414,7 +413,7 @@ data ANSIColorLevel = ANSI16Color   -- ^ 16-color mode                     | ANSI256Color  -- ^ 256-color mode                     | ANSITrueColor -- ^ True-color mode-       deriving (Show, Read, Eq, Ord, Enum, Bounded, Data, Typeable, Generic)+       deriving (Show, Read, Eq, Ord, Enum, Bounded, Data, Generic)  instance Binary ANSIColorLevel @@ -428,7 +427,7 @@        , containerClasses :: ![Text]         -- ^ Additional classes for Html container tag        , lineIdPrefix     :: !Text           -- ^ Prefix for id attributes on lines        , ansiColorLevel   :: !ANSIColorLevel -- ^ Level of ANSI color support to use-       } deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)+       } deriving (Show, Read, Eq, Ord, Data, Generic)  instance Binary FormatOptions