packages feed

ghc-syntax-highlighter 0.0.3.1 → 0.0.4.0

raw patch · 5 files changed

+57/−3 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+## GHC syntax highlighter 0.0.4.0++* Implemented highlighting of file header pragmas such as `OPTIONS_GHC` and+  `LANGUAGE`. They are not handled by the GHC lexer, so custom code were+  added for this purpose.+ ## GHC syntax highlighter 0.0.3.1  * Fixed the bug when certain extensions such as `-XLambdaCase` were not
GHC/SyntaxHighlighter.hs view
@@ -29,6 +29,7 @@ import Control.Monad import Data.Bits import Data.List (unfoldr, foldl')+import Data.Maybe (isJust) import Data.Text (Text) import Data.Word (Word64) import FastString (mkFastString)@@ -98,7 +99,12 @@       case tryFetchSpace txt l of         Nothing ->           let (txt', chunk) = fetchSpan txt l-          in Just ((t, chunk), (txt', ts))+              t' = case t of+                CommentTok -> if isHeaderPragma chunk+                  then PragmaTok+                  else CommentTok+                tok -> tok+          in Just ((t', chunk), (txt', ts))         Just (txt', chunk) ->           Just ((SpaceTok, chunk), (txt', tss)) @@ -408,6 +414,16 @@               _    -> (l', c' + 1)         return (ch, Text' l'' c'' s')   in (Text' l c (T.drop (T.length chunk) original), chunk)++----------------------------------------------------------------------------+-- Pragmas detection++-- | Detect file header pragma.++isHeaderPragma :: Text -> Bool+isHeaderPragma txt0 = isJust $ do+  txt1 <- T.stripStart <$> T.stripPrefix "{-#" txt0+  guard (T.isPrefixOf "LANGUAGE" txt1 || T.isPrefixOf "OPTIONS_GHC" txt1)  ---------------------------------------------------------------------------- -- Exts bitmap hack
+ data/Pragmas.hs view
@@ -0,0 +1,5 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -fno-warn-unused-matches #-}++main :: IO ()+main = return ()
ghc-syntax-highlighter.cabal view
@@ -1,7 +1,7 @@ name:                 ghc-syntax-highlighter-version:              0.0.3.1+version:              0.0.4.0 cabal-version:        1.18-tested-with:          GHC==8.4.4, GHC==8.6.4+tested-with:          GHC==8.4.4, GHC==8.6.5 license:              BSD3 license-file:         LICENSE.md author:               Mark Karpov <markkarpov92@gmail.com>
tests/GHC/SyntaxHighlighterSpec.hs view
@@ -15,6 +15,7 @@   it "parses a type family" (withFile "data/TypeFamily.hs" typeFamily)   it "parses an explicit forall" (withFile "data/Forall.hs" explicitForall)   it "parses lambda case correctly" (withFile "data/LambdaCase.hs" lambdaCase)+  it "parses file header pragmas correctly" (withFile "data/Pragmas.hs" pragmas)  withFile :: FilePath -> [(Token, Text)] -> Expectation withFile path toks = do@@ -196,5 +197,31 @@   , (SymbolTok,"->")   , (SpaceTok," ")   , (ConstructorTok,"Nothing")+  , (SpaceTok,"\n")+  ]++pragmas :: [(Token, Text)]+pragmas =+  [ (PragmaTok,"{-# LANGUAGE OverloadedStrings #-}")+  , (SpaceTok,"\n")+  , (PragmaTok,"{-# OPTIONS_GHC -fno-warn-unused-matches #-}")+  , (SpaceTok,"\n\n")+  , (VariableTok,"main")+  , (SpaceTok," ")+  , (SymbolTok,"::")+  , (SpaceTok," ")+  , (ConstructorTok,"IO")+  , (SpaceTok," ")+  , (SymbolTok,"(")+  , (SymbolTok,")")+  , (SpaceTok,"\n")+  , (VariableTok,"main")+  , (SpaceTok," ")+  , (SymbolTok,"=")+  , (SpaceTok," ")+  , (VariableTok,"return")+  , (SpaceTok," ")+  , (SymbolTok,"(")+  , (SymbolTok,")")   , (SpaceTok,"\n")   ]