skylighting-0.1.1.5: syntax highlighting library

Safe Haskell | None
Language | Haskell2010

Skylighting.Types

Contents

- Syntax descriptions
- Tokens
- Styles
- Format options

Synopsis

- type ContextName = (Text, Text)
- data KeywordAttr = KeywordAttr {
  - keywordCaseSensitive :: Bool
  - keywordDelims :: Set Char
  }
- data WordSet a
  - = CaseSensitiveWords (Set a)
  - | CaseInsensitiveWords (Set (CI a))
- makeWordSet :: (FoldCase a, Ord a) => Bool -> [a] -> WordSet a
- data Matcher
  - = DetectChar Char
  - | Detect2Chars Char Char
  - | AnyChar [Char]
  - | RangeDetect Char Char
  - | StringDetect Text
  - | WordDetect Text
  - | RegExpr RE
  - | Keyword KeywordAttr (WordSet Text)
  - | Int
  - | Float
  - | HlCOct
  - | HlCHex
  - | HlCStringChar
  - | HlCChar
  - | LineContinue
  - | IncludeRules ContextName
  - | DetectSpaces
  - | DetectIdentifier
- data Rule = Rule {
  - rMatcher :: Matcher
  - rAttribute :: TokenType
  - rIncludeAttribute :: Bool
  - rDynamic :: Bool
  - rCaseSensitive :: Bool
  - rChildren :: [Rule]
  - rLookahead :: Bool
  - rFirstNonspace :: Bool
  - rColumn :: Maybe Int
  - rContextSwitch :: [ContextSwitch]
  }
- data Context = Context {
  - cName :: Text
  - cSyntax :: Text
  - cRules :: [Rule]
  - cAttribute :: TokenType
  - cLineEmptyContext :: [ContextSwitch]
  - cLineEndContext :: [ContextSwitch]
  - cLineBeginContext :: [ContextSwitch]
  - cFallthrough :: Bool
  - cFallthroughContext :: [ContextSwitch]
  - cDynamic :: Bool
  }
- data ContextSwitch
  - = Pop
  - | Push ContextName
- data Syntax = Syntax {
  - sName :: Text
  - sFilename :: String
  - sShortname :: Text
  - sContexts :: Map Text Context
  - sAuthor :: Text
  - sVersion :: Text
  - sLicense :: Text
  - sExtensions :: [String]
  - sStartingContext :: Text
  }
- type SyntaxMap = Map Text Syntax
- type Token = (TokenType, Text)
- data TokenType
  - = KeywordTok
  - | DataTypeTok
  - | DecValTok
  - | BaseNTok
  - | FloatTok
  - | ConstantTok
  - | CharTok
  - | SpecialCharTok
  - | StringTok
  - | VerbatimStringTok
  - | SpecialStringTok
  - | ImportTok
  - | CommentTok
  - | DocumentationTok
  - | AnnotationTok
  - | CommentVarTok
  - | OtherTok
  - | FunctionTok
  - | VariableTok
  - | ControlFlowTok
  - | OperatorTok
  - | BuiltInTok
  - | ExtensionTok
  - | PreprocessorTok
  - | AttributeTok
  - | RegionMarkerTok
  - | InformationTok
  - | WarningTok
  - | AlertTok
  - | ErrorTok
  - | NormalTok
- type SourceLine = [Token]
- data TokenStyle = TokenStyle {
  - tokenColor :: Maybe Color
  - tokenBackground :: Maybe Color
  - tokenBold :: Bool
  - tokenItalic :: Bool
  - tokenUnderline :: Bool
  }
- defStyle :: TokenStyle
- data Color = RGB Word8 Word8 Word8
- class ToColor a where
- class FromColor a where
- data Style = Style {
  - tokenStyles :: [(TokenType, TokenStyle)]
  - defaultColor :: Maybe Color
  - backgroundColor :: Maybe Color
  - lineNumberColor :: Maybe Color
  - lineNumberBackgroundColor :: Maybe Color
  }
- data FormatOptions = FormatOptions {
  - numberLines :: Bool
  - startNumber :: Int
  - lineAnchors :: Bool
  - titleAttributes :: Bool
  - codeClasses :: [Text]
  - containerClasses :: [Text]
  }
- defaultFormatOpts :: FormatOptions

# Syntax descriptions

type ContextName = (Text, Text) #

Full name of a context: the first member of the pair is the full syntax name, the second the context name within that syntax.

data KeywordAttr #

Constructors

KeywordAttr |
Fields keywordCaseSensitive :: Bool keywordDelims :: Set Char

Instances

Show KeywordAttr # |
Methods showsPrec :: Int -> KeywordAttr -> ShowS # show :: KeywordAttr -> String # showList :: [KeywordAttr] -> ShowS #

data WordSet a #

Constructors

CaseSensitiveWords (Set a) |
CaseInsensitiveWords (Set (CI a)) |

Instances

Show a => Show (WordSet a) # |
Methods showsPrec :: Int -> WordSet a -> ShowS # show :: WordSet a -> String # showList :: [WordSet a] -> ShowS #

makeWordSet :: (FoldCase a, Ord a) => Bool -> [a] -> WordSet a #

A set of words to match (either case-sensitive or case-insensitive).

data Matcher #

Constructors

DetectChar Char |
Detect2Chars Char Char |
AnyChar [Char] |
RangeDetect Char Char |
StringDetect Text |
WordDetect Text |
RegExpr RE |
Keyword KeywordAttr (WordSet Text) |
Int |
Float |
HlCOct |
HlCHex |
HlCStringChar |
HlCChar |
LineContinue |
IncludeRules ContextName |
DetectSpaces |
DetectIdentifier |

Instances

Show Matcher # |
Methods showsPrec :: Int -> Matcher -> ShowS # show :: Matcher -> String # showList :: [Matcher] -> ShowS #

data Rule #

A rule corresponds to one of the elements of a Kate syntax highlighting "context."

Constructors

Rule |
Fields rMatcher :: Matcher rAttribute :: TokenType rIncludeAttribute :: Bool rDynamic :: Bool rCaseSensitive :: Bool rChildren :: [Rule] rLookahead :: Bool rFirstNonspace :: Bool rColumn :: Maybe Int rContextSwitch :: [ContextSwitch]

Instances

Show Rule # |
Methods showsPrec :: Int -> Rule -> ShowS # show :: Rule -> String # showList :: [Rule] -> ShowS #

data Context #

A Context corresponds to a context element in a Kate syntax description.

Constructors

Context |
Fields cName :: Text cSyntax :: Text cRules :: [Rule] cAttribute :: TokenType cLineEmptyContext :: [ContextSwitch] cLineEndContext :: [ContextSwitch] cLineBeginContext :: [ContextSwitch] cFallthrough :: Bool cFallthroughContext :: [ContextSwitch] cDynamic :: Bool

Instances

Show Context # |
Methods showsPrec :: Int -> Context -> ShowS # show :: Context -> String # showList :: [Context] -> ShowS #

data ContextSwitch #

Constructors

Pop |
Push ContextName |

Instances

Show ContextSwitch # |
Methods showsPrec :: Int -> ContextSwitch -> ShowS # show :: ContextSwitch -> String # showList :: [ContextSwitch] -> ShowS #

data Syntax #

A syntax corresponds to a complete Kate syntax description. The `sShortname` field is derived from the filename.

Constructors

Syntax |
Fields sName :: Text sFilename :: String sShortname :: Text sContexts :: Map Text Context sAuthor :: Text sVersion :: Text sLicense :: Text sExtensions :: [String] sStartingContext :: Text

Instances

Show Syntax # |
Methods showsPrec :: Int -> Syntax -> ShowS # show :: Syntax -> String # showList :: [Syntax] -> ShowS #

type SyntaxMap = Map Text Syntax #

A map of syntaxes, keyed by full name.

# Tokens

type Token = (TokenType, Text) #

A pair consisting of a list of attributes and some text.

data TokenType #

`KeywordTok` corresponds to `dsKeyword` in Kate syntax descriptions, and so on.

Constructors

KeywordTok |
DataTypeTok |
DecValTok |
BaseNTok |
FloatTok |
ConstantTok |
CharTok |
SpecialCharTok |
StringTok |
VerbatimStringTok |
SpecialStringTok |
ImportTok |
CommentTok |
DocumentationTok |
AnnotationTok |
CommentVarTok |
OtherTok |
FunctionTok |
VariableTok |
ControlFlowTok |
OperatorTok |
BuiltInTok |
ExtensionTok |
PreprocessorTok |
AttributeTok |
RegionMarkerTok |
InformationTok |
WarningTok |
AlertTok |
ErrorTok |
NormalTok |

Instances

Enum TokenType # |
Methods succ :: TokenType -> TokenType # pred :: TokenType -> TokenType # toEnum :: Int -> TokenType # fromEnum :: TokenType -> Int # enumFrom :: TokenType -> [TokenType] # enumFromThen :: TokenType -> TokenType -> [TokenType] # enumFromTo :: TokenType -> TokenType -> [TokenType] # enumFromThenTo :: TokenType -> TokenType -> TokenType -> [TokenType] #
Eq TokenType # |
Methods (==) :: TokenType -> TokenType -> Bool # (/=) :: TokenType -> TokenType -> Bool #
Data TokenType # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TokenType -> c TokenType # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TokenType # toConstr :: TokenType -> Constr # dataTypeOf :: TokenType -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c TokenType) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TokenType) # gmapT :: (forall b. Data b => b -> b) -> TokenType -> TokenType # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TokenType -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TokenType -> r # gmapQ :: (forall d. Data d => d -> u) -> TokenType -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TokenType -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TokenType -> m TokenType # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TokenType -> m TokenType # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TokenType -> m TokenType #
Ord TokenType # |
Methods compare :: TokenType -> TokenType -> Ordering # (<) :: TokenType -> TokenType -> Bool # (<=) :: TokenType -> TokenType -> Bool # (>) :: TokenType -> TokenType -> Bool # (>=) :: TokenType -> TokenType -> Bool # max :: TokenType -> TokenType -> TokenType # min :: TokenType -> TokenType -> TokenType #
Read TokenType # |
Methods readsPrec :: Int -> ReadS TokenType # readList :: ReadS [TokenType] # readPrec :: ReadPrec TokenType # readListPrec :: ReadPrec [TokenType] #
Show TokenType # |
Methods showsPrec :: Int -> TokenType -> ShowS # show :: TokenType -> String # showList :: [TokenType] -> ShowS #
FromJSON TokenType # | JSON `Keyword` corresponds to `KeywordTok`, and so on.
Methods parseJSON :: Value -> Parser TokenType # parseJSONList :: Value -> Parser [TokenType] #

type SourceLine = [Token] #

A line of source: a list of labeled tokens.

# Styles

data TokenStyle #

A `TokenStyle` determines how a token is to be rendered.

Constructors

TokenStyle |
Fields tokenColor :: Maybe Color tokenBackground :: Maybe Color tokenBold :: Bool tokenItalic :: Bool tokenUnderline :: Bool

Instances

Eq TokenStyle # |
Methods (==) :: TokenStyle -> TokenStyle -> Bool # (/=) :: TokenStyle -> TokenStyle -> Bool #
Data TokenStyle # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TokenStyle -> c TokenStyle # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TokenStyle # toConstr :: TokenStyle -> Constr # dataTypeOf :: TokenStyle -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c TokenStyle) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TokenStyle) # gmapT :: (forall b. Data b => b -> b) -> TokenStyle -> TokenStyle # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TokenStyle -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TokenStyle -> r # gmapQ :: (forall d. Data d => d -> u) -> TokenStyle -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TokenStyle -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TokenStyle -> m TokenStyle # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TokenStyle -> m TokenStyle # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TokenStyle -> m TokenStyle #
Ord TokenStyle # |
Methods compare :: TokenStyle -> TokenStyle -> Ordering # (<) :: TokenStyle -> TokenStyle -> Bool # (<=) :: TokenStyle -> TokenStyle -> Bool # (>) :: TokenStyle -> TokenStyle -> Bool # (>=) :: TokenStyle -> TokenStyle -> Bool # max :: TokenStyle -> TokenStyle -> TokenStyle # min :: TokenStyle -> TokenStyle -> TokenStyle #
Read TokenStyle # |
Methods readsPrec :: Int -> ReadS TokenStyle # readList :: ReadS [TokenStyle] # readPrec :: ReadPrec TokenStyle # readListPrec :: ReadPrec [TokenStyle] #
Show TokenStyle # |
Methods showsPrec :: Int -> TokenStyle -> ShowS # show :: TokenStyle -> String # showList :: [TokenStyle] -> ShowS #
FromJSON TokenStyle # | The keywords used in KDE syntax themes are used, e.g. `text-color` for default token color.
Methods parseJSON :: Value -> Parser TokenStyle # parseJSONList :: Value -> Parser [TokenStyle] #

defStyle :: TokenStyle #

Default style.

data Color #

Constructors

RGB Word8 Word8 Word8 |

Instances

Eq Color # |
Methods (==) :: Color -> Color -> Bool # (/=) :: Color -> Color -> Bool #
Data Color # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Color -> c Color # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Color # toConstr :: Color -> Constr # dataTypeOf :: Color -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Color) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Color) # gmapT :: (forall b. Data b => b -> b) -> Color -> Color # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Color -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Color -> r # gmapQ :: (forall d. Data d => d -> u) -> Color -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Color -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Color -> m Color # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Color -> m Color # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Color -> m Color #
Ord Color # |
Methods compare :: Color -> Color -> Ordering # (<) :: Color -> Color -> Bool # (<=) :: Color -> Color -> Bool # (>) :: Color -> Color -> Bool # (>=) :: Color -> Color -> Bool # max :: Color -> Color -> Color # min :: Color -> Color -> Color #
Read Color # |
Methods readsPrec :: Int -> ReadS Color # readList :: ReadS [Color] # readPrec :: ReadPrec Color # readListPrec :: ReadPrec [Color] #
Show Color # |
Methods showsPrec :: Int -> Color -> ShowS # show :: Color -> String # showList :: [Color] -> ShowS #
FromJSON Color # | JSON `"#1aff2b" corresponds to the color` RGB 0x1a 0xff 0x2b@.
Methods parseJSON :: Value -> Parser Color # parseJSONList :: Value -> Parser [Color] #

class ToColor a where #

Minimal complete definition

toColor

Methods

toColor :: a -> Maybe Color #

Instances

ToColor Int # |
Methods toColor :: Int -> Maybe Color #
ToColor String # |
Methods toColor :: String -> Maybe Color #
ToColor (Double, Double, Double) # |
Methods toColor :: (Double, Double, Double) -> Maybe Color #
ToColor (Word8, Word8, Word8) # |
Methods toColor :: (Word8, Word8, Word8) -> Maybe Color #

class FromColor a where #

Minimal complete definition

fromColor

Methods

fromColor :: Color -> a #

Instances

FromColor String # |
Methods fromColor :: Color -> String #
FromColor (Double, Double, Double) # |
Methods fromColor :: Color -> (Double, Double, Double) #
FromColor (Word8, Word8, Word8) # |
Methods fromColor :: Color -> (Word8, Word8, Word8) #

data Style #

A rendering style. This determines how each kind of token is to be rendered, and sets a default color and background color for normal tokens. Line numbers can have a different color and background color.

Constructors

Style |
Fields tokenStyles :: [(TokenType, TokenStyle)] defaultColor :: Maybe Color backgroundColor :: Maybe Color lineNumberColor :: Maybe Color lineNumberBackgroundColor :: Maybe Color

Instances

Eq Style # |
Methods (==) :: Style -> Style -> Bool # (/=) :: Style -> Style -> Bool #
Data Style # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Style -> c Style # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Style # toConstr :: Style -> Constr # dataTypeOf :: Style -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Style) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Style) # gmapT :: (forall b. Data b => b -> b) -> Style -> Style # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Style -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Style -> r # gmapQ :: (forall d. Data d => d -> u) -> Style -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Style -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Style -> m Style # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Style -> m Style # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Style -> m Style #
Ord Style # |
Methods compare :: Style -> Style -> Ordering # (<) :: Style -> Style -> Bool # (<=) :: Style -> Style -> Bool # (>) :: Style -> Style -> Bool # (>=) :: Style -> Style -> Bool # max :: Style -> Style -> Style # min :: Style -> Style -> Style #
Read Style # |
Methods readsPrec :: Int -> ReadS Style # readList :: ReadS [Style] # readPrec :: ReadPrec Style # readListPrec :: ReadPrec [Style] #
Show Style # |
Methods showsPrec :: Int -> Style -> ShowS # show :: Style -> String # showList :: [Style] -> ShowS #
FromJSON Style # | The FromJSON instance for `Style` is designed so that a KDE syntax theme (JSON) can be decoded directly as a `Style`.
Methods parseJSON :: Value -> Parser Style # parseJSONList :: Value -> Parser [Style] #

# Format options

data FormatOptions #

Options for formatting source code.

Constructors

FormatOptions |
Fields numberLines :: Bool Number lines startNumber :: Int Number of first line lineAnchors :: Bool Anchors on each line number titleAttributes :: Bool Html titles with token types codeClasses :: [Text] Additional classes for Html code tag containerClasses :: [Text] Additional classes for Html container tag (pre or table depending on numberLines)

Instances

Eq FormatOptions # |
Methods (==) :: FormatOptions -> FormatOptions -> Bool # (/=) :: FormatOptions -> FormatOptions -> Bool #
Read FormatOptions # |
Methods readsPrec :: Int -> ReadS FormatOptions # readList :: ReadS [FormatOptions] # readPrec :: ReadPrec FormatOptions # readListPrec :: ReadPrec [FormatOptions] #
Show FormatOptions # |
Methods showsPrec :: Int -> FormatOptions -> ShowS # show :: FormatOptions -> String # showList :: [FormatOptions] -> ShowS #

defaultFormatOpts :: FormatOptions #