# -*- 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 custom symbol types for arena

from Library.Parse.Symbols import SymbolCategory, AConstant
    
## A link identifier
class ALinkIdentifier(AConstant):
    ## Construct a new constant instance with the specified name and value.
    def __init__(Self, thisName):
        AConstant.__init__(Self, thisName, None)
    
    ## Initializer    
    def init(Self):
        result = AConstant.init(Self)
        
        if result:
            # Establish public attributes
            # The destination of the link (its URL)
            Self.url = ""
            # The title of the link
            Self.title = ""
            # The attributes of the link
            Self.attributes = {}

        return result
        
    # IsPrintable implementation -----------------------------------------------
    ## Construct a string representation of the constant.
    #    
    # This representation is merely a quoted form of the URL.
    def toString(Self):
        return String.quote(str(Self.url))
        
    # Properties ---------------------------------------------------------------
    ## Retrieve the specified attribute from the tag
    def __getitem__(Self, key):
        if key in Self.attributes:
            return Self.attributes[key]
            
        return None
        
    ## Set the specified attribute in the tag
    def __setitem__(Self, key, value):
        Self.attributes[key] = value
        
    ## Delete the specified attribute from the tag
    def __delitem__(Self, key):
        if key in Self.attributes:
            del Self.attributes[key]    
