    module Happy.Frontend where

    import Happy.Frontend.AbsSyn
    import Happy.Frontend.Parser
    import Happy.Frontend.ParseMonad.Class

    parseYFileContents :: String -> ParseResult BookendedAbsSyn
    parseYFileContents :: String -> ParseResult BookendedAbsSyn
    parseYFileContents String
    contents = ReaderT (String, Int) ParseResult BookendedAbsSyn
    -> String -> Int -> ParseResult BookendedAbsSyn
    forall a.
    ReaderT (String, Int) ParseResult a
    -> String -> Int -> ParseResult a
    forall (p :: * -> *) a.
    ParseMonad p =>
    p a -> String -> Int -> ParseResult a
    runFromStartP ReaderT (String, Int) ParseResult BookendedAbsSyn
    ourParser String
    contents Int
    1

    data FileType = Y | LY

    fileNameAndType :: String -> Maybe (String, FileType)
    fileNameAndType :: String -> Maybe (String, FileType)
    fileNameAndType = String -> Maybe (String, FileType)
    nameType (String -> Maybe (String, FileType))
    -> (String -> String) -> String -> Maybe (String, FileType)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    forall a. [a] -> [a]
    reverse where
      nameType :: String -> Maybe (String, FileType)
    nameType (Char
    'y':Char
    '.':String
    f) = (String, FileType) -> Maybe (String, FileType)
    forall a. a -> Maybe a
    Just (String -> String
    forall a. [a] -> [a]
    reverse String
    f, FileType
    Y)
      nameType (Char
    'y':Char
    'l':Char
    '.':String
    f) = (String, FileType) -> Maybe (String, FileType)
    forall a. a -> Maybe a
    Just (String -> String
    forall a. [a] -> [a]
    reverse String
    f, FileType
    LY)
      nameType String
    _ = Maybe (String, FileType)
    forall a. Maybe a
    Nothing

    -- Delit, converting an ly file into a y file.
    deLitify :: String -> String
    deLitify :: String -> String
    deLitify = String -> String
    deLit where
        deLit :: String -> String
    deLit (Char
    '>':Char
    ' ':String
    r)   = String -> String
    deLit1 String
    r
        deLit (Char
    '>':Char
    '\t':String
    r)  = Char
    '\t' Char -> String -> String
    forall a. a -> [a] -> [a]
    : String -> String
    deLit1 String
    r
        deLit (Char
    '>':Char
    '\n':String
    r)  = String -> String
    deLit String
    r
        deLit (Char
    '>':String
    _)       = String -> String
    forall a. HasCallStack => String -> a
    error String
    "Error when de-litify-ing"
        deLit (Char
    '\n':String
    r)      = Char
    '\n' Char -> String -> String
    forall a. a -> [a] -> [a]
    : String -> String
    deLit String
    r
        deLit String
    r             = String -> String
    deLit2 String
    r
        deLit1 :: String -> String
    deLit1 (Char
    '\n':String
    r)     = Char
    '\n' Char -> String -> String
    forall a. a -> [a] -> [a]
    : String -> String
    deLit String
    r
        deLit1 (Char
    c:String
    r)        = Char
    c Char -> String -> String
    forall a. a -> [a] -> [a]
    : String -> String
    deLit1 String
    r
        deLit1 []           = []
        deLit2 :: String -> String
    deLit2 (Char
    '\n':String
    r)     = Char
    '\n' Char -> String -> String
    forall a. a -> [a] -> [a]
    : String -> String
    deLit String
    r
        deLit2 (Char
    _:String
    r)        = String -> String
    deLit2 String
    r
        deLit2 []           = []