<commit_before>module Language.Java.Paragon.Parac
  (
    -- * The compiler
    parac
  ) where

import Data.Maybe (fromMaybe)

import Control.Exception (tryJust)
import Control.Monad (guard)
import System.Environment (getEnv)
import System.FilePath ((</>), splitSearchPath, splitFileName)
import System.IO.Error (isDoesNotExistError)

import Language.Java.Paragon.Error
import Language.Java.Paragon.Interaction hiding (pretty)
import Language.Java.Paragon.Monad.Base
import Language.Java.Paragon.Monad.PiReader
import Language.Java.Paragon.NameResolution
import Language.Java.Paragon.Parser
import Language.Java.Paragon.SrcPos

-- | Given the flags and a file to the compiler, run the compilation. 
parac :: [Flag] -> String -> IO [Error]
parac flags filePath = do
  piPath <- buildPiPath flags filePath
  erOrU <- runBaseM flags $ do
    detailPrint $ "Starting compilation of " ++ filePath
    debugPrint $ "With .pi-directories " ++ show piPath
    let sourcepath = fromMaybe "." (getSourcePath flags)
    content <- liftIO $ readFile $ sourcepath </> filePath
    case parse content filePath of
      Left e    -> failE (parseError e defaultSpan)
      Right ast -> do
        _resolvedAST <- raiseErrors $ liftToBaseM piPath (resolveNames ast)        
        detailPrint $ "Finished compilation of " ++ filePath ++ "\n"
        return ()
  case erOrU of
    Left  e  -> return e
    Right () -> return []

-- | Collect paths to interface files from options and environment
buildPiPath :: [Flag] -> String -> IO [String]<commit_msg>Removed SrcSpan argument from Parac<commit_after>module Language.Java.Paragon.Parac
  (
    -- * The compiler
    parac
  ) where

import Data.Maybe (fromMaybe)

import Control.Exception (tryJust)
import Control.Monad (guard)
import System.Environment (getEnv)
import System.FilePath ((</>), splitSearchPath, splitFileName)
import System.IO.Error (isDoesNotExistError)

import Language.Java.Paragon.Error
import Language.Java.Paragon.Interaction hiding (pretty)
import Language.Java.Paragon.Monad.Base
import Language.Java.Paragon.Monad.PiReader
import Language.Java.Paragon.NameResolution
import Language.Java.Paragon.Parser

-- | Given the flags and a file to the compiler, run the compilation. 
parac :: [Flag] -> String -> IO [Error]
parac flags filePath = do
  piPath <- buildPiPath flags filePath
  erOrU <- runBaseM flags $ do
    detailPrint $ "Starting compilation of " ++ filePath
    debugPrint $ "With .pi-directories " ++ show piPath
    let sourcepath = fromMaybe "." (getSourcePath flags)
    content <- liftIO $ readFile $ sourcepath </> filePath
    case parse content filePath of
      Left e    -> failE (parseError e errorAnnotation)
      Right ast -> do
        _resolvedAST <- raiseErrors $ liftToBaseM piPath (resolveNames ast)        
        detailPrint $ "Finished compilation of " ++ filePath ++ "\n"
        return ()
  case erOrU of
    Left  e  -> return e
    Right () -> return []

-- | Collect paths to interface files from options and environment
buildPiPath :: [Flag] -> String -> IO [String]
{'fraction_non_alphanumeric': 0.09817351598173515, 'fraction_numerical': 0.0, 'mean_word_length': 3.4839181286549707, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '1061431', 'n_tokens_mistral': 887, 'n_tokens_neox': 872, 'n_words': 281}