<commit_before>--------------------------------------------------------------------------------
--
-- GAC Driver program
--
-- (c) <NAME>, 2011
--
--------------------------------------------------------------------------------

module Main(main) where

import Lexer (ParseResult(..), mkPState, unP, PState, getPMessages)
import Parser (parser)
import SrcLoc (mkSrcLoc, Located)
import Outputable
import TcMonad (TcResult(..), mkTcState, unTcM, TcState, getTcMessages)
import SymbolTable (predefinedTable)
import TypeCheck (typeCheckDef)
import ErrUtils (errorsFound, unionMessages)
import UnTypedAst (UDef)
import TypedAst (ADef)

import System.Exit (exitSuccess, exitFailure)


parse :: String -> IO (PState, Located UDef)
parse buf = do
    case unP parser (mkPState buf (mkSrcLoc "Stdin" 1 1)) of
         PFailed msg       -> do
             printOutput msg
             exitFailure
         POk p_state luast -> do
             return (p_state, luast)

typeCheck :: (Located UDef) -> IO (TcState, Located ADef)
typeCheck luast = do
    case unTcM (typeCheckDef luast) (mkTcState predefinedTable) of
         TcFailed msg       -> do
             printOutput msg
             exitFailure
         TcOk tc_state ltast -> do
             return (tc_state, ltast)

main :: IO ()
main = do
    str <- getContents
    (p_state, luast) <- parse str
    let p_messages = getPMessages p_state
    if errorsFound p_messages
       then do
           printOutput p_messages
           exitFailure
       else do
           return ()
    (tc_state, _) <- typeCheck luast   
    let tc_messages = unionMessages p_messages (getTcMessages tc_state)
    if errorsFound tc_messages
       then do
           printOutput tc_messages
           exitFailure
       else do
           return ()
    printOutput tc_messages
    exitSuccess
<commit_msg>Rename printOutput to printMessages for now<commit_after>--------------------------------------------------------------------------------
--
-- GAC Driver program
--
-- (c) <NAME>, 2011
--
--------------------------------------------------------------------------------

module Main(main) where

import Lexer (ParseResult(..), mkPState, unP, PState, getPMessages)
import Parser (parser)
import SrcLoc (mkSrcLoc, Located)
import Outputable
import TcMonad (TcResult(..), mkTcState, unTcM, TcState, getTcMessages)
import SymbolTable (predefinedTable)
import TypeCheck (typeCheckDef)
import ErrUtils (errorsFound, unionMessages)
import UnTypedAst (UDef)
import TypedAst (ADef)

import System.Exit (exitSuccess, exitFailure)


parse :: String -> IO (PState, Located UDef)
parse buf = do
    case unP parser (mkPState buf (mkSrcLoc "Stdin" 1 1)) of
         PFailed msg       -> do
             printMessages msg
             exitFailure
         POk p_state luast -> do
             return (p_state, luast)

typeCheck :: (Located UDef) -> IO (TcState, Located ADef)
typeCheck luast = do
    case unTcM (typeCheckDef luast) (mkTcState predefinedTable) of
         TcFailed msg       -> do
             printMessages msg
             exitFailure
         TcOk tc_state ltast -> do
             return (tc_state, ltast)

main :: IO ()
main = do
    str <- getContents
    (p_state, luast) <- parse str
    let p_messages = getPMessages p_state
    if errorsFound p_messages
       then do
           printMessages p_messages
           exitFailure
       else do
           return ()
    (tc_state, _) <- typeCheck luast   
    let tc_messages = unionMessages p_messages (getTcMessages tc_state)
    if errorsFound tc_messages
       then do
           printMessages tc_messages
           exitFailure
       else do
           return ()
    printMessages tc_messages
    exitSuccess

{'fraction_non_alphanumeric': 0.15463362068965517, 'fraction_numerical': 0.003232758620689655, 'mean_word_length': 1.8517665130568357, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6226694', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1020, 'n_words': 331}