    module Happy.Backend.LALR where

    import Happy.Paths
    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_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"
          import_prelude :: String
    import_prelude     = [String] -> String
    unlines ([String] -> String) -> [String] -> String
    forall a b. (a -> b) -> a -> b
    $ (String -> String) -> [String] -> [String]
    forall a b. (a -> b) -> [a] -> [b]
    map (\ String
    x -> [String] -> String
    unwords [String
    "import qualified", String
    x, String
    "as Happy_Prelude"]) ([String] -> [String]) -> [String] -> [String]
    forall a b. (a -> b) -> a -> b
    $
            -- Keep this list alphabetically ordered!
            -- The style of list notation here has been chosen so that these lines can be sorted mechanically,
            -- e.g. in Emacs with M-x sort-lines.
            String
    "Control.Monad" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Data.Bool" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Data.Function" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Data.Int" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Data.List" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Data.Maybe" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Data.String" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Data.Tuple" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "GHC.Err" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "GHC.Num" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            String
    "Text.Show" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :
            []

    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 ]
        ]