{-# LANGUAGE OverloadedStrings #-}

-- | Haskell's reserved words.

module BNFC.Backend.Haskell.Utilities.ReservedWords where

import BNFC.Prelude

hsReservedWords :: [String]
hsReservedWords :: [String]
hsReservedWords =
  [ String
"as"
  , String
"case"
  , String
"class"
  , String
"data"
  , String
"default"
  , String
"deriving"
  , String
"do"
  , String
"else"
  , String
"family"
  , String
"forall"
  , String
"foreign"
  , String
"hiding"
  , String
"if"
  , String
"import"
  , String
"in"
  , String
"infix"
  , String
"infixl"
  , String
"infixr"
  , String
"instance"
  , String
"let"
  , String
"mdo"
  , String
"module"
  , String
"newtype"
  , String
"of"
  , String
"pattern"
  , String
"proc"
  , String
"qualified"
  , String
"rec"
  , String
"then"
  , String
"type"
  , String
"where"
  ]

-- | Modifier to avoid clashes in definition.

avoidReservedWords :: String -> String
avoidReservedWords :: String -> String
avoidReservedWords  String
x
  | String
x String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
hsReservedWords = String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'"
  | Bool
otherwise                = String
x

avoidReservedWordsArgs :: String -> String
avoidReservedWordsArgs :: String -> String
avoidReservedWordsArgs String
x
  | String
x String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
hsReservedWords = String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"_"
  | Bool
otherwise                = String
x

avoidReservedWords' :: String1 -> String
avoidReservedWords' :: String1 -> String
avoidReservedWords' = String -> String
avoidReservedWords (String -> String) -> (String1 -> String) -> String1 -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String1 -> String
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList

avoidReservedWordsArgs' :: String1 -> String
avoidReservedWordsArgs' :: String1 -> String
avoidReservedWordsArgs' = String -> String
avoidReservedWordsArgs (String -> String) -> (String1 -> String) -> String1 -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String1 -> String
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList

avoidReservedWords1 :: String1 -> String1
avoidReservedWords1 :: String1 -> String1
avoidReservedWords1 String1
x =
  if String1 -> String
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList String1
x String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
hsReservedWords
  then String1
x String1 -> String1 -> String1
forall a. Semigroup a => a -> a -> a
<> (Char
'\''Char -> String -> String1
forall a. a -> [a] -> NonEmpty a
:|[])
  else String1
x