-- |Data types and combinators for [Ribosome.Api.Syntax]("Ribosome.Api.Syntax").
module Ribosome.Syntax (
  module Ribosome.Data.Syntax,
  module Ribosome.Syntax,
) where

import qualified Data.Map.Strict as Map

import Ribosome.Data.Syntax (
  HiLink (..),
  Highlight (..),
  Syntax (..),
  SyntaxItem (..),
  SyntaxItemDetail (..),
  )

-- |Construct a default 'SyntaxItem' from a 'SyntaxItemDetail'.
syntaxItem :: SyntaxItemDetail -> SyntaxItem
syntaxItem :: SyntaxItemDetail -> SyntaxItem
syntaxItem SyntaxItemDetail
detail =
  SyntaxItemDetail -> [Text] -> Map Text Text -> SyntaxItem
SyntaxItem SyntaxItemDetail
detail [Text]
forall a. Default a => a
def Map Text Text
forall a. Default a => a
def

-- |Construct a simple keyword syntax item.
syntaxKeyword :: Text -> Text -> SyntaxItem
syntaxKeyword :: Text -> Text -> SyntaxItem
syntaxKeyword Text
group' Text
keyword =
  SyntaxItemDetail -> SyntaxItem
syntaxItem (SyntaxItemDetail -> SyntaxItem) -> SyntaxItemDetail -> SyntaxItem
forall a b. (a -> b) -> a -> b
$ Text -> Text -> [Text] -> SyntaxItemDetail
Keyword Text
group' Text
keyword [Text]
forall a. Default a => a
def

-- |Construct a simple match syntax item.
syntaxMatch :: Text -> Text -> SyntaxItem
syntaxMatch :: Text -> Text -> SyntaxItem
syntaxMatch Text
group' Text
pat =
  SyntaxItemDetail -> SyntaxItem
syntaxItem (SyntaxItemDetail -> SyntaxItem) -> SyntaxItemDetail -> SyntaxItem
forall a b. (a -> b) -> a -> b
$ Text -> Text -> SyntaxItemDetail
Match Text
group' Text
pat

-- |Construct a region syntax item with offsets.
syntaxRegionOffset :: Text -> Text -> Text -> Maybe Text -> Text -> Text -> SyntaxItem
syntaxRegionOffset :: Text -> Text -> Text -> Maybe Text -> Text -> Text -> SyntaxItem
syntaxRegionOffset Text
group' Text
start Text
end Maybe Text
skip Text
ms Text
me =
  SyntaxItemDetail -> SyntaxItem
syntaxItem (SyntaxItemDetail -> SyntaxItem) -> SyntaxItemDetail -> SyntaxItem
forall a b. (a -> b) -> a -> b
$ Text
-> Text -> Text -> Maybe Text -> Text -> Text -> SyntaxItemDetail
Region Text
group' Text
start Text
end Maybe Text
skip Text
ms Text
me

-- |Construct a simple region syntax item.
syntaxRegion :: Text -> Text -> Text -> Maybe Text -> SyntaxItem
syntaxRegion :: Text -> Text -> Text -> Maybe Text -> SyntaxItem
syntaxRegion Text
group' Text
start Text
end Maybe Text
skip =
  Text -> Text -> Text -> Maybe Text -> Text -> Text -> SyntaxItem
syntaxRegionOffset Text
group' Text
start Text
end Maybe Text
skip Text
"" Text
""

-- |Construct a simple verbatim syntax item.
syntaxVerbatim :: Text -> SyntaxItem
syntaxVerbatim :: Text -> SyntaxItem
syntaxVerbatim =
  SyntaxItemDetail -> SyntaxItem
syntaxItem (SyntaxItemDetail -> SyntaxItem)
-> (Text -> SyntaxItemDetail) -> Text -> SyntaxItem
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> SyntaxItemDetail
Verbatim

-- |Construct a syntax highlight.
syntaxHighlight :: Text -> [(Text, Text)] -> Highlight
syntaxHighlight :: Text -> [(Text, Text)] -> Highlight
syntaxHighlight Text
group' =
  Text -> Map Text Text -> Highlight
Highlight Text
group' (Map Text Text -> Highlight)
-> ([(Text, Text)] -> Map Text Text) -> [(Text, Text)] -> Highlight
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList