<commit_before>{-# LANGUAGE GADTs, StandaloneDeriving, KindSignatures, DeriveFunctor #-}
module OmegaParser where

import qualified Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
import Text.Parsec
--import Text.Parsec.Token
import Text.Parsec.String
import Control.Applicative

ω = QuasiQuoter { quoteExp = parseExprExp }

data Exp :: * -> * where
  Var :: String -> Exp a
  Con :: String -> Exp a
  App :: Exp (a -> b) -> Exp a -> Exp b
  IntLit :: Int -> Exp Int

--deriving instance Functor Exp

--instance Applicative Exp where
lexeme :: Parser a -> Parser a
lexeme p = do { x <- p; spaces; return x }
integer = lexeme $ do { ds <- many1 digit; return $ IntLit (read ds) }


trans (Right (IntLit i)) = (TH.conE $ TH.mkName "Int") `TH.appE` (TH.litE $ TH.IntegerL (toInteger i))

parseExprExp :: String -> TH.Q TH.Exp
parseExprExp "" = fail "empty parse"
parseExprExp "s * h" = TH.conE $ TH.mkName "Δ"
parseExprExp s = do loc <- TH.location
                    let file = TH.loc_filename loc
                        exp = parse integer file s
                    trans exp
<commit_msg>abbreviate and comment<commit_after>{-# LANGUAGE GADTs, StandaloneDeriving, KindSignatures, DeriveFunctor #-}
module OmegaParser where

import qualified Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
import Text.Parsec
--import Text.Parsec.Token
import Text.Parsec.String
import Control.Applicative

ω = QuasiQuoter { quoteExp = parseExprExp }

-- Omega AST

data Exp :: * -> * where
  Var :: String -> Exp a
  Con :: String -> Exp a
  App :: Exp (a -> b) -> Exp a -> Exp b
  IntLit :: Int -> Exp Int

--deriving instance Functor Exp

--instance Applicative Exp where
lexeme :: Parser a -> Parser a
lexeme p = do { x <- p; spaces; return x }
integer = lexeme $ do { ds <- many1 digit; return $ IntLit (read ds) }

-- TH helpers
con = TH.conE . TH.mkName
int = TH.litE . TH.IntegerL

trans (Right (IntLit i)) = (con "Int") `TH.appE` (int (toInteger i))

parseExprExp :: String -> TH.Q TH.Exp
parseExprExp "" = fail "empty parse"
parseExprExp "s * h" = TH.conE $ TH.mkName "Δ"
parseExprExp s = do loc <- TH.location
                    let file = TH.loc_filename loc
                        exp = parse integer file s
                    trans exp

{'fraction_non_alphanumeric': 0.11863656485170429, 'fraction_numerical': 0.0008853474988933156, 'mean_word_length': 2.7417218543046356, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '2719464', 'n_tokens_mistral': 764, 'n_tokens_neox': 727, 'n_words': 258}