module Proteome.Grep.Syntax where

import qualified Data.Map.Strict as Map (fromList)
import Ribosome.Data.Syntax.Syntax (HiLink (HiLink), Syntax (Syntax))
import Ribosome.Data.SyntaxItem (SyntaxItem (options, params))
import Ribosome.Syntax (syntaxMatch, syntaxVerbatim)
import Text.RawString.QQ (r)

lineNumber :: Text
lineNumber :: Text
lineNumber =
  Text
"\57505"

asterisk :: SyntaxItem
asterisk :: SyntaxItem
asterisk =
  SyntaxItem
item {[Text]
options :: [Text]
$sel:options:SyntaxItem :: [Text]
options, Map Text Text
params :: Map Text Text
$sel:params:SyntaxItem :: Map Text Text
params}
  where
    item :: SyntaxItem
item = SyntaxGroup -> Text -> SyntaxItem
syntaxMatch SyntaxGroup
"ProGrepAsterisk" [r|^ \*|]
    options :: [Text]
options = [Item [Text]
"skipwhite"]
    params :: Map Text Text
params = [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Text
"nextgroup", Text
"ProGrepPath")]

path :: SyntaxItem
path :: SyntaxItem
path =
  SyntaxItem
item {[Text]
options :: [Text]
$sel:options:SyntaxItem :: [Text]
options, Map Text Text
params :: Map Text Text
$sel:params:SyntaxItem :: Map Text Text
params}
  where
    item :: SyntaxItem
item = SyntaxGroup -> Text -> SyntaxItem
syntaxMatch SyntaxGroup
"ProGrepPath" ([r|.*\ze|] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
lineNumber)
    options :: [Text]
options = [Item [Text]
"contained", Item [Text]
"skipwhite"]
    params :: Map Text Text
params = [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Text
"nextgroup", Text
"ProGrepLN")]

ln :: SyntaxItem
ln :: SyntaxItem
ln =
  SyntaxItem
item {[Text]
options :: [Text]
$sel:options:SyntaxItem :: [Text]
options, Map Text Text
params :: Map Text Text
$sel:params:SyntaxItem :: Map Text Text
params}
  where
    item :: SyntaxItem
item = SyntaxGroup -> Text -> SyntaxItem
syntaxMatch SyntaxGroup
"ProGrepLN" Text
lineNumber
    options :: [Text]
options = [Item [Text]
"contained", Item [Text]
"skipwhite"]
    params :: Map Text Text
params = [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Text
"nextgroup", Text
"ProGrepLine")]

line :: SyntaxItem
line :: SyntaxItem
line =
  SyntaxItem
item {[Text]
options :: [Text]
$sel:options:SyntaxItem :: [Text]
options, Map Text Text
params :: Map Text Text
$sel:params:SyntaxItem :: Map Text Text
params}
  where
    item :: SyntaxItem
item = SyntaxGroup -> Text -> SyntaxItem
syntaxMatch SyntaxGroup
"ProGrepLine" [r|\d\+\ze:|]
    options :: [Text]
options = [Item [Text]
"contained"]
    params :: Map Text Text
params = [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Text
"nextgroup", Text
"ProGrepColon")]

colon :: SyntaxItem
colon :: SyntaxItem
colon =
  SyntaxItem
item {[Text]
options :: [Text]
$sel:options:SyntaxItem :: [Text]
options, Map Text Text
params :: Map Text Text
$sel:params:SyntaxItem :: Map Text Text
params}
  where
    item :: SyntaxItem
item = SyntaxGroup -> Text -> SyntaxItem
syntaxMatch SyntaxGroup
"ProGrepColon" [r|:|]
    options :: [Text]
options = [Item [Text]
"contained"]
    params :: Map Text Text
params = [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Text
"nextgroup", Text
"ProGrepCol")]

col :: SyntaxItem
col :: SyntaxItem
col =
  SyntaxItem
item {[Text]
options :: [Text]
$sel:options:SyntaxItem :: [Text]
options, Map Text Text
params :: Map Text Text
$sel:params:SyntaxItem :: Map Text Text
params}
  where
    item :: SyntaxItem
item = SyntaxGroup -> Text -> SyntaxItem
syntaxMatch SyntaxGroup
"ProGrepCol" [r|\d\+|]
    options :: [Text]
options = [Item [Text]
"contained", Item [Text]
"skipwhite"]
    params :: Map Text Text
params = [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Text
"nextgroup", Text
"ProGrepText")]

text_ :: SyntaxItem
text_ :: SyntaxItem
text_ =
  SyntaxItem
item { [Text]
options :: [Text]
$sel:options:SyntaxItem :: [Text]
options }
  where
    item :: SyntaxItem
item = SyntaxGroup -> Text -> SyntaxItem
syntaxMatch SyntaxGroup
"ProGrepText" [r|.\+|]
    options :: [Text]
options = [Item [Text]
"contained"]

sync :: SyntaxItem
sync :: SyntaxItem
sync =
  Text -> SyntaxItem
syntaxVerbatim Text
"syntax sync minlines=1"

hlAsterisk :: HiLink
hlAsterisk :: HiLink
hlAsterisk =
  SyntaxGroup -> SyntaxGroup -> HiLink
HiLink SyntaxGroup
"ProGrepAsterisk" SyntaxGroup
"Todo"

hlPath :: HiLink
hlPath :: HiLink
hlPath =
  SyntaxGroup -> SyntaxGroup -> HiLink
HiLink SyntaxGroup
"ProGrepPath" SyntaxGroup
"Type"

hlLn :: HiLink
hlLn :: HiLink
hlLn =
  SyntaxGroup -> SyntaxGroup -> HiLink
HiLink SyntaxGroup
"ProGrepLN" SyntaxGroup
"LineNr"

hlLine :: HiLink
hlLine :: HiLink
hlLine =
  SyntaxGroup -> SyntaxGroup -> HiLink
HiLink SyntaxGroup
"ProGrepLine" SyntaxGroup
"Constant"

hlCol :: HiLink
hlCol :: HiLink
hlCol =
  SyntaxGroup -> SyntaxGroup -> HiLink
HiLink SyntaxGroup
"ProGrepCol" SyntaxGroup
"Constant"

hlText :: HiLink
hlText :: HiLink
hlText =
  SyntaxGroup -> SyntaxGroup -> HiLink
HiLink SyntaxGroup
"ProGrepText" SyntaxGroup
"Directory"

grepSyntax :: Syntax
grepSyntax :: Syntax
grepSyntax =
  [SyntaxItem] -> [Highlight] -> [HiLink] -> Syntax
Syntax [SyntaxItem]
items [] [HiLink]
links
  where
    items :: [SyntaxItem]
items =
      [Item [SyntaxItem]
SyntaxItem
asterisk, Item [SyntaxItem]
SyntaxItem
path, Item [SyntaxItem]
SyntaxItem
ln, Item [SyntaxItem]
SyntaxItem
line, Item [SyntaxItem]
SyntaxItem
col, Item [SyntaxItem]
SyntaxItem
colon, Item [SyntaxItem]
SyntaxItem
text_, Item [SyntaxItem]
SyntaxItem
sync]
    links :: [HiLink]
links =
      [Item [HiLink]
HiLink
hlAsterisk, Item [HiLink]
HiLink
hlPath, Item [HiLink]
HiLink
hlLn, Item [HiLink]
HiLink
hlLine, Item [HiLink]
HiLink
hlCol, Item [HiLink]
HiLink
hlText]