<commit_before>{-# LANGUAGE ViewPatterns #-}

-- | Common tools for code generation.
module Language.K3.Codegen.Common (
    annotationComboId,
    annotationComboIdT,
    annotationComboIdE,
    annotationComboIdL,

    recordName,
    signature
) where

import Control.Arrow ((&&&))

import Language.K3.Core.Common

import Language.K3.Core.Annotation (K3, tag, children)
import Language.K3.Core.Expression (Expression, namedEAnnotations)
import Language.K3.Core.Literal (Literal, namedLAnnotations)
import Language.K3.Core.Type

import Data.List

{- Annotation identifiers. -}

annotationComboId :: [Identifier] -> Identifier
annotationComboId = intercalate "_"

annotationComboIdT :: [Annotation Type] -> Maybe Identifier
annotationComboIdT (namedTAnnotations -> [])  = Nothing
annotationComboIdT (namedTAnnotations -> ids) = Just $ annotationComboId ids

annotationComboIdE :: [Annotation Expression] -> Maybe Identifier
annotationComboIdE (namedEAnnotations -> [])  = Nothing
annotationComboIdE (namedEAnnotations -> ids) = Just $ annotationComboId ids

annotationComboIdL :: [Annotation Literal] -> Maybe Identifier
annotationComboIdL (namedLAnnotations -> [])  = Nothing
annotationComboIdL (namedLAnnotations -> ids) = Just $ annotationComboId ids

-- Record Identifiers

recordName :: [(Identifier, K3 Type)] -> Identifier
recordName its = concat $ fst $ unzip its

signature :: Monad m => K3 Type -> m Identifier<commit_msg>Make single-annotation combinations name-unique.<commit_after>{-# LANGUAGE ViewPatterns #-}

-- | Common tools for code generation.
module Language.K3.Codegen.Common (
    annotationComboId,
    annotationComboIdT,
    annotationComboIdE,
    annotationComboIdL,

    recordName,
    signature
) where

import Control.Arrow ((&&&))

import Language.K3.Core.Common

import Language.K3.Core.Annotation (K3, tag, children)
import Language.K3.Core.Expression (Expression, namedEAnnotations)
import Language.K3.Core.Literal (Literal, namedLAnnotations)
import Language.K3.Core.Type

import Data.List

{- Annotation identifiers. -}

annotationComboId :: [Identifier] -> Identifier
annotationComboId = ('_':) . intercalate "_"

annotationComboIdT :: [Annotation Type] -> Maybe Identifier
annotationComboIdT (namedTAnnotations -> [])  = Nothing
annotationComboIdT (namedTAnnotations -> ids) = Just $ annotationComboId ids

annotationComboIdE :: [Annotation Expression] -> Maybe Identifier
annotationComboIdE (namedEAnnotations -> [])  = Nothing
annotationComboIdE (namedEAnnotations -> ids) = Just $ annotationComboId ids

annotationComboIdL :: [Annotation Literal] -> Maybe Identifier
annotationComboIdL (namedLAnnotations -> [])  = Nothing
annotationComboIdL (namedLAnnotations -> ids) = Just $ annotationComboId ids

-- Record Identifiers

recordName :: [(Identifier, K3 Type)] -> Identifier
recordName its = concat $ fst $ unzip its

signature :: Monad m => K3 Type -> m Identifier
{'fraction_non_alphanumeric': 0.10481099656357389, 'fraction_numerical': 0.006185567010309278, 'mean_word_length': 5.089958158995816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '5505155', 'n_tokens_mistral': 847, 'n_tokens_neox': 864, 'n_words': 216}