<commit_before>%%%
%%% Author:
%%%   <NAME> <<EMAIL>>
%%%
%%% Copyright:
%%%   <NAME>, 1998
%%%
%%% Last change:
%%%   $Date$ by $Author$
%%%   $Revision$
%%%
%%% This file is part of Mozart, an implementation of Oz 3:
%%%   http://mozart.ps.uni-sb.de
%%%
%%% See the file "LICENSE" or
%%%   http://mozart.ps.uni-sb.de/LICENSE.html
%%% for information on usage and redistribution
%%% of this file, and for a DISCLAIMER OF ALL
%%% WARRANTIES.
%%%

functor
import
   ErrorRegistry(put)
   Error(dispatch format formatGeneric)
export
   'class': Narrator
define
   {ErrorRegistry.put narrator
    fun {$ Exc}
       E = {Error.dispatch Exc}
       T = 'narrator error'
    in
       case E of narrator(register P) then
          {Error.format T
           'Trying to register a non-port'
           [hint(l: 'Argument' m: oz(P))]
           Exc}
       else
          {Error.formatGeneric T Exc}
       end
    end}

   fun {NormalizeCoord Coord}
      case Coord of unit then Coord
      else pos({CondSelect Coord 1 ''} Coord.2 {CondSelect Coord 2 ~1})
      end
   end

   class PrivateNarrator
      attr
         Narrator: unit
         LogPhases: false
         MaxNumberOfErrors: 17
         ErrorCount: unit
      meth init(NarratorObject)
         Narrator <- NarratorObject
      end
      meth setLogPhases(B)
         LogPhases <- B
      end
      meth setMaxNumberOfErrors(N)
         MaxNumberOfErrors <- N
      end

      meth tell(M)
         {@Narrator tell(M)}
      end
      meth startBatch()
         ErrorCount <- 0
      end
      meth startPhase(VS)
         if @LogPhases then
            {@Narrator tell(info('%%%     '#VS#'\n'))}
         end
      end
      meth startSubPhase(VS)
         if @LogPhases then
            {@Narrator tell(info('%%%         '#VS#'\n'))}
         end
      end
      meth endBatch(Kind)
         case Kind of accepted then
            {@Narrator tell(info('% -------------------- accepted\n'))}
         [] rejected then VS in
            VS = ('%** ------------------ rejected'#
                  case @ErrorCount of 0 then ""
                  elseof N then
                     ' ('#N#' error'#if N == 1 then "" else 's' end#')'
                  end#'\n')
            {@Narrator tell([attention info(VS)])}
         [] aborted then VS in
            VS = '%** ------------------ aborted\n'
            {@Narrator tell([attention info(VS)])}
         [] crashed then VS in
            VS = '%** ------------------ crashed'
            {@Narrator tell([attention info(VS)])}
         [] interrupted then
            {@Narrator tell(info('% -------------------- interrupted'))}
         end
         ErrorCount <- unit
      end

      meth error(coord: Coord <= unit
                 kind: Kind <= unit
                 msg: Msg <= unit
                 items: Items <= nil
                 abort: Abort <= true) NewCoord MaxNumberOfErrors in
         NewCoord = {NormalizeCoord Coord}
         {@Narrator
          tell(message(error(kind: Kind msg: Msg
                             items: case NewCoord of unit then Items
                                    else {Append Items [NewCoord]}
                                    end) NewCoord))}
         ErrorCount <- @ErrorCount + 1
         if @MaxNumberOfErrors >= 0 andthen @ErrorCount > @MaxNumberOfErrors
            andthen Abort
         then
            raise tooManyErrors end
         end
      end
      meth warn(coord: Coord <= unit
                kind: Kind <= unit
                msg: Msg <= unit
                items: Items <= nil) NewCoord in<commit_msg>Oops.<commit_after>%%%
%%% Author:
%%%   <NAME> <<EMAIL>>
%%%
%%% Copyright:
%%%   <NAME>, 1998
%%%
%%% Last change:
%%%   $Date$ by $Author$
%%%   $Revision$
%%%
%%% This file is part of Mozart, an implementation of Oz 3:
%%%   http://mozart.ps.uni-sb.de
%%%
%%% See the file "LICENSE" or
%%%   http://mozart.ps.uni-sb.de/LICENSE.html
%%% for information on usage and redistribution
%%% of this file, and for a DISCLAIMER OF ALL
%%% WARRANTIES.
%%%

functor
import
   ErrorRegistry(put)
   Error(dispatch format formatGeneric)
export
   'class': Narrator
define
   {ErrorRegistry.put narrator
    fun {$ Exc}
       E = {Error.dispatch Exc}
       T = 'narrator error'
    in
       case E of narrator(register P) then
          {Error.format T
           'Trying to register a non-port'
           [hint(l: 'Argument' m: oz(P))]
           Exc}
       else
          {Error.formatGeneric T Exc}
       end
    end}

   fun {NormalizeCoord Coord}
      case Coord of unit then Coord
      else pos({CondSelect Coord 1 ''} Coord.2 {CondSelect Coord 2 ~1})
      end
   end

   class PrivateNarrator
      attr
         Narrator: unit
         LogPhases: false
         MaxNumberOfErrors: 17
         ErrorCount: unit
      meth init(NarratorObject)
         Narrator <- NarratorObject
      end
      meth setLogPhases(B)
         LogPhases <- B
      end
      meth setMaxNumberOfErrors(N)
         MaxNumberOfErrors <- N
      end

      meth tell(M)
         {@Narrator tell(M)}
      end
      meth startBatch()
         ErrorCount <- 0
      end
      meth startPhase(VS)
         if @LogPhases then
            {@Narrator tell(info('%%%     '#VS#'\n'))}
         end
      end
      meth startSubPhase(VS)
         if @LogPhases then
            {@Narrator tell(info('%%%         '#VS#'\n'))}
         end
      end
      meth endBatch(Kind)
         case Kind of accepted then
            {@Narrator tell(info('% -------------------- accepted\n'))}
         [] rejected then VS in
            VS = ('%** ------------------ rejected'#
                  case @ErrorCount of 0 then ""
                  elseof N then
                     ' ('#N#' error'#if N == 1 then "" else 's' end#')'
                  end#'\n')
            {@Narrator tell([attention info(VS)])}
         [] aborted then VS in
            VS = '%** ------------------ aborted\n'
            {@Narrator tell([attention info(VS)])}
         [] crashed then VS in
            VS = '%** ------------------ crashed'
            {@Narrator tell([attention info(VS)])}
         [] interrupted then
            {@Narrator tell(info('% -------------------- interrupted'))}
         end
         ErrorCount <- unit
      end

      meth error(coord: Coord <= unit
                 kind: Kind <= unit
                 msg: Msg <= unit
                 items: Items <= nil
                 abort: Abort <= true) NewCoord in
         NewCoord = {NormalizeCoord Coord}
         {@Narrator
          tell(message(error(kind: Kind msg: Msg
                             items: case NewCoord of unit then Items
                                    else {Append Items [NewCoord]}
                                    end) NewCoord))}
         ErrorCount <- @ErrorCount + 1
         if @MaxNumberOfErrors >= 0 andthen @ErrorCount > @MaxNumberOfErrors
            andthen Abort
         then
            raise tooManyErrors end
         end
      end
      meth warn(coord: Coord <= unit
                kind: Kind <= unit
                msg: Msg <= unit
                items: Items <= nil) NewCoord in
{'fraction_non_alphanumeric': 0.1357142857142857, 'fraction_numerical': 0.004481792717086834, 'mean_word_length': 1.4497427101200686, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7530056', 'n_tokens_mistral': 2094, 'n_tokens_neox': 2003, 'n_words': 604}