# -*- coding: UTF-8 -*-
#    This file is part of arena.
#
#    arena is free software: you can redistribute it and/or modify it
#    under the terms of the GNU General Public License as published by the
#    Free Software Foundation; either version 3 of the License or, at your
#    option, any later version.
#
#    arena is distributed in the hope that it will be useful, but
#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABLITY
#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
#    License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with arena.  If not, see <http://www.gnu.org/licenses/>.

## @file
#  This file defines error, warning, and hint classes that are used by a parser
#  to log diagnostic information

from Library.IO.Logging.Logs import AMessageWithTimeStamp

## The format of a parser message
pmStringRepresentation = "{source}: {line}: {message}"

# A parser message
class AParserMessage(AMessageWithTimeStamp):
    ## Constructor
    def __init__(Self, Source, errorMessage, *params):
        AMessageWithTimeStamp.__init__(Self, errorMessage, *params)
        
        Self._Source = Source
        
    ## Initializer
    def init(Self):
        result = AMessageWithTimeStamp.init(Self)
        
        if result:
            # Establish private attributes
            # The source stream for which the message was generated
            Self._Source = None
            
        return result
        
    ## IsPrintable implementation ----------------------------------------------
    ## Construct a string representation of the message
    def toString(Self):
        if Self._Source is not None:
            return pmStringRepresentation.format(
              source=Self._Source.toString(),
              line=Self._Source.line(),
              message=AMessageWithTimeStamp.toString(Self)
            )
              
        else:
          return AMessageWithTimeStamp.toString(Self)

# A fatal error
class AFatalError(AParserMessage):
    pass
    
# A syntax error
class ASyntaxError(AParserMessage):
    pass
    
# A hint
class AHint(AParserMessage):
    pass
    
# A warning
class AWarning(AParserMessage):
    pass
    
# A note
class ANote(AParserMessage):
    pass
