module Ermine.Parser.Style
( termIdent
, typeIdent
, kindIdent
, termIdentifier
, typeIdentifier
, kindIdentifier
, op
, operator
, termCon
, typeCon
) where
import Control.Applicative
import Control.Lens hiding (op)
import Data.HashSet as HashSet
import Data.Text (Text)
import Ermine.Parser.Keywords
import Text.Parser.Char
import Text.Parser.Token
import Text.Parser.Token.Highlight
import Text.Parser.Token.Style
variable :: TokenParsing m => IdentifierStyle m
variable = IdentifierStyle
{ _styleName = "variable"
, _styleStart = lower
, _styleLetter = alphaNum <|> oneOf "_'"
, _styleReserved = HashSet.empty
, _styleHighlight = Identifier
, _styleReservedHighlight = ReservedIdentifier
}
baseIdent, termIdent, typeIdent, kindIdent :: TokenParsing m => IdentifierStyle m
baseIdent = haskellIdents & styleReserved .~ keywords
termIdent = baseIdent & styleName .~ "term variable"
typeIdent = variable & styleName .~ "type variable"
kindIdent = baseIdent & styleName .~ "kind variable"
termIdentifier :: (Monad m, TokenParsing m) => m Text
termIdentifier = ident termIdent
typeIdentifier :: (Monad m, TokenParsing m) => m Text
typeIdentifier = ident typeIdent
kindIdentifier :: (Monad m, TokenParsing m) => m Text
kindIdentifier = ident kindIdent
op :: TokenParsing m => IdentifierStyle m
op = haskellOps
operator :: (Monad m, TokenParsing m) => m Text
operator = ident op
constructor :: TokenParsing m => IdentifierStyle m
constructor = IdentifierStyle
{ _styleName = "constructor"
, _styleStart = upper
, _styleLetter = alphaNum <|> oneOf "_'"
, _styleReserved = HashSet.empty
, _styleHighlight = Constructor
, _styleReservedHighlight = ReservedConstructor
}
termCon :: TokenParsing m => IdentifierStyle m
termCon = constructor & styleName .~ "term constructor"
typeCon :: TokenParsing m => IdentifierStyle m
typeCon = constructor & styleName .~ "type constructor"