module Happy.Backend.LALR where

import Paths_happy_lib
import Data.Char

lalrBackendDataDir :: IO String
lalrBackendDataDir :: IO String
lalrBackendDataDir = IO String
getDataDir

magicFilter :: Maybe String -> String -> String
magicFilter :: Maybe String -> String -> String
magicFilter Maybe String
magicName = case Maybe String
magicName of
    Maybe String
Nothing -> String -> String
forall a. a -> a
id
    Just String
name' -> let
        small_name :: String
small_name = String
name'
        big_name :: String
big_name = Char -> Char
toUpper (String -> Char
forall a. HasCallStack => [a] -> a
head String
name') Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
forall a. HasCallStack => [a] -> [a]
tail String
name'
        filter_output :: String -> String
filter_output (Char
'h':Char
'a':Char
'p':Char
'p':Char
'y':String
rest) = String
small_name String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
filter_output String
rest
        filter_output (Char
'H':Char
'a':Char
'p':Char
'p':Char
'y':String
rest) = String
big_name String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
filter_output String
rest
        filter_output (Char
c:String
cs) = Char
c Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
filter_output String
cs
        filter_output [] = []
      in String -> String
filter_output

importsToInject :: Bool -> String
importsToInject :: Bool -> String
importsToInject Bool
debug = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"\n", String
import_prelude, String
import_array, String
import_bits, String
import_glaexts, String
debug_imports, String
applicative_imports]
    where
      debug_imports :: String
debug_imports  | Bool
debug     = String
import_debug
                     | Bool
otherwise = String
""
      applicative_imports :: String
applicative_imports        = String
import_applicative

      import_glaexts :: String
import_glaexts     = String
"import qualified GHC.Exts as Happy_GHC_Exts\n"
      _import_ghcstack :: String
_import_ghcstack   = String
"import qualified GHC.Stack as Happy_GHC_Stack\n"
      import_prelude :: String
import_prelude     = String
"import qualified Data.Bool as Happy_Prelude\nimport qualified Data.Function as Happy_Prelude\nimport qualified Data.Maybe as Happy_Prelude\nimport qualified Data.Int as Happy_Prelude\nimport qualified Data.String as Happy_Prelude\nimport qualified Data.List as Happy_Prelude\nimport qualified Control.Monad as Happy_Prelude\nimport qualified Text.Show as Happy_Prelude\nimport qualified GHC.Num as Happy_Prelude\nimport qualified GHC.Err as Happy_Prelude\n"
      import_array :: String
import_array       = String
"import qualified Data.Array as Happy_Data_Array\n"
      import_bits :: String
import_bits        = String
"import qualified Data.Bits as Bits\n"
      import_debug :: String
import_debug       = String
"import qualified System.IO as Happy_System_IO\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
                           String
"import qualified System.IO.Unsafe as Happy_System_IO_Unsafe\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
                           String
"import qualified Debug.Trace as Happy_Debug_Trace\n"
      import_applicative :: String
import_applicative = String
"import Control.Applicative(Applicative(..))\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
                           String
"import Control.Monad (ap)\n"

langExtsToInject :: [String]
langExtsToInject :: [String]
langExtsToInject = [String
"MagicHash", String
"BangPatterns", String
"TypeSynonymInstances", String
"FlexibleInstances", String
"PatternGuards", String
"NoStrictData", String
"UnboxedTuples", String
"PartialTypeSignatures"]

defines :: Bool -> Bool -> String
defines :: Bool -> Bool -> String
defines Bool
debug Bool
coerce = [String] -> String
unlines [ String
"#define " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
d String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" 1" | String
d <- [String]
vars_to_define ]
  where
  vars_to_define :: [String]
vars_to_define = [[String]] -> [String]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
    [ [ String
"HAPPY_DEBUG"  | Bool
debug ]
    , [ String
"HAPPY_COERCE" | Bool
coerce ]
    ]