<commit_before>{
-- We use these options because Happy generates code with a lot of warnings.
{-# LANGUAGE Trustworthy #-}
module Text.Show.Parser (parseValue) where

import Text.Show.Value
import Language.Haskell.Lexer
}

%token

        '='             { (Reservedop, (_,"=")) }
        '('             { (Special, (_,"(")) }
        ')'             { (Special, (_,")")) }
        '{'             { (Special, (_,"{")) }
        '}'             { (Special, (_,"}")) }
        '['             { (Special, (_,"[")) }
        ']'             { (Special, (_,"]")) }
        ','             { (Special, (_,",")) }
        '-'             { (Varsym,  (_,"-")) }
        '%'             { (Varsym,  (_,"%")) }
        '`'             { (Special, (_,"`")) }

        INT             { (IntLit,   (_,$$)) }
        FLOAT           { (FloatLit, (_,$$)) }
        STRING          { (StringLit, (_,$$)) }
        CHAR            { (CharLit,  (_,$$)) }

        VARID           { (Varid,    (_,$$)) }
        QVARID          { (Qvarid,   (_,$$)) }
        VARSYM          { (Varsym,   (_,$$)) }
        QVARSYM         { (Qvarsym,  (_,$$)) }
        CONID           { (Conid,    (_,$$)) }
        QCONID          { (Qconid,   (_,$$)) }
        CONSYM          { (Consym,   (_,$$)) }
        QCONSYM         { (Qconsym,  (_,$$)) }


%monad { Maybe } { (>>=) } { return }
%name parseValue value
%tokentype { PosToken }


%%

value                        :: { Value }
  : value '%' app_value         { Ratio $1 $3 }
  | '-' avalue                  { Neg $2 }
  | app_value                   { $1 }
  | app_value list1(infixelem)  { InfixCons $1 $2 }

infixelem                    :: { (String,Value) }
  : infixcon app_value          { ($1,$2) }

app_value                    :: { Value }
  : list1(avalue)               { mkValue $1 }


avalue                       :: { Value }
  : '(' value ')'               { $2 }
  | '[' sep(value,',') ']'      { List $2 }
  | '(' tuple ')'               { Tuple $2 }
  | con '{' sep(field,',') '}'  { Rec $1 $3 }
  | con                         { Con $1 [] }
  | INT                         { Integer $1 }
  | FLOAT                       { Float $1 }
  | STRING                      { String $1 }
  | CHAR                        { Char $1 }
<commit_msg>Make unary minus have high precedence.<commit_after>{
-- We use these options because Happy generates code with a lot of warnings.
{-# LANGUAGE Trustworthy #-}
module Text.Show.Parser (parseValue) where

import Text.Show.Value
import Language.Haskell.Lexer
}

%token

        '='             { (Reservedop, (_,"=")) }
        '('             { (Special, (_,"(")) }
        ')'             { (Special, (_,")")) }
        '{'             { (Special, (_,"{")) }
        '}'             { (Special, (_,"}")) }
        '['             { (Special, (_,"[")) }
        ']'             { (Special, (_,"]")) }
        ','             { (Special, (_,",")) }
        '-'             { (Varsym,  (_,"-")) }
        '%'             { (Varsym,  (_,"%")) }
        '`'             { (Special, (_,"`")) }

        INT             { (IntLit,   (_,$$)) }
        FLOAT           { (FloatLit, (_,$$)) }
        STRING          { (StringLit, (_,$$)) }
        CHAR            { (CharLit,  (_,$$)) }

        VARID           { (Varid,    (_,$$)) }
        QVARID          { (Qvarid,   (_,$$)) }
        VARSYM          { (Varsym,   (_,$$)) }
        QVARSYM         { (Qvarsym,  (_,$$)) }
        CONID           { (Conid,    (_,$$)) }
        QCONID          { (Qconid,   (_,$$)) }
        CONSYM          { (Consym,   (_,$$)) }
        QCONSYM         { (Qconsym,  (_,$$)) }


%monad { Maybe } { (>>=) } { return }
%name parseValue value
%tokentype { PosToken }


%%

value                        :: { Value }
  : value '%' app_value         { Ratio $1 $3 }
  | app_value                   { $1 }
  | app_value list1(infixelem)  { InfixCons $1 $2 }

infixelem                    :: { (String,Value) }
  : infixcon app_value          { ($1,$2) }

app_value                    :: { Value }
  : list1(avalue)               { mkValue $1 }


avalue                       :: { Value }
  : '(' value ')'               { $2 }
  | '[' sep(value,',') ']'      { List $2 }
  | '(' tuple ')'               { Tuple $2 }
  | con '{' sep(field,',') '}'  { Rec $1 $3 }
  | con                         { Con $1 [] }
  | INT                         { Integer $1 }
  | FLOAT                       { Float $1 }
  | STRING                      { String $1 }
  | CHAR                        { Char $1 }
  | '-' avalue                  { Neg $2 }

{'fraction_non_alphanumeric': 0.1961597207069605, 'fraction_numerical': 0.0091643028583897, 'mean_word_length': 1.088382687927107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6228938', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1466, 'n_words': 255}