ghc-syntax-highlighter-0.0.3.0: Syntax highlighter for Haskell using lexer of GHC itself

Copyright© 2018 Mark Karpov
LicenseBSD 3 clause
MaintainerMark Karpov <markkarpov92@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

GHC.SyntaxHighlighter

Description

The module allows you to decompose a Text stream containing Haskell source code into a stream of Text chunks tagged with Token.

This library uses GHC's lexer, so the result is guaranteed to be 100% correct, as if it was parsed by GHC itself.

Synopsis

Documentation

data Token #

Token types that are used as tags to mark spans of source code.

Constructors

KeywordTok

Keyword

PragmaTok

Pragmas

SymbolTok

Symbols (punctuation that is not an operator)

VariableTok

Variable name (term level)

ConstructorTok

Data/type constructor

OperatorTok

Operator

CharTok

Character

StringTok

String

IntegerTok

Integer

RationalTok

Rational number

CommentTok

Comment (including Haddocks)

SpaceTok

Space filling

OtherTok

Something else?

Instances
Bounded Token # 
Instance details

Defined in GHC.SyntaxHighlighter

Enum Token # 
Instance details

Defined in GHC.SyntaxHighlighter

Eq Token # 
Instance details

Defined in GHC.SyntaxHighlighter

Methods

(==) :: Token -> Token -> Bool #

(/=) :: Token -> Token -> Bool #

Ord Token # 
Instance details

Defined in GHC.SyntaxHighlighter

Methods

compare :: Token -> Token -> Ordering #

(<) :: Token -> Token -> Bool #

(<=) :: Token -> Token -> Bool #

(>) :: Token -> Token -> Bool #

(>=) :: Token -> Token -> Bool #

max :: Token -> Token -> Token #

min :: Token -> Token -> Token #

Show Token # 
Instance details

Defined in GHC.SyntaxHighlighter

Methods

showsPrec :: Int -> Token -> ShowS #

show :: Token -> String #

showList :: [Token] -> ShowS #

data Loc #

Start and end positions of a span. The arguments of the data constructor contain in order:

  • Line number of start position of a span
  • Column number of start position of a span
  • Line number of end position of a span
  • Column number of end position of a span

Since: 0.0.2.0

Constructors

Loc !Int !Int !Int !Int 
Instances
Eq Loc # 
Instance details

Defined in GHC.SyntaxHighlighter

Methods

(==) :: Loc -> Loc -> Bool #

(/=) :: Loc -> Loc -> Bool #

Ord Loc # 
Instance details

Defined in GHC.SyntaxHighlighter

Methods

compare :: Loc -> Loc -> Ordering #

(<) :: Loc -> Loc -> Bool #

(<=) :: Loc -> Loc -> Bool #

(>) :: Loc -> Loc -> Bool #

(>=) :: Loc -> Loc -> Bool #

max :: Loc -> Loc -> Loc #

min :: Loc -> Loc -> Loc #

Show Loc # 
Instance details

Defined in GHC.SyntaxHighlighter

Methods

showsPrec :: Int -> Loc -> ShowS #

show :: Loc -> String #

showList :: [Loc] -> ShowS #

tokenizeHaskell :: Text -> Maybe [(Token, Text)] #

Tokenize Haskell source code. If the code cannot be parsed, return Nothing. Otherwise return the original input tagged by Tokens.

The parser does not require the input source code to form a valid Haskell program, so as long as the lexer can decompose your input (most of the time), it'll return something in Just.

tokenizeHaskellLoc :: Text -> Maybe [(Token, Loc)] #

Similar to tokenizeHaskell, but instead of Text chunks provides locations of corresponding spans in the given input stream.

Since: 0.0.2.0