import logging

def pushParseThing(rpnList,nextElement):
    parseThing = eval(nextElement)
    index = int(parseThing['argNo'])
    if len(rpnList)>index:
        rpnList.pop(index)
    rpnList.insert(index,parseThing)

def addParenthesis(rpnList,wsText):
    lastElement = rpnList.pop()
    lastElement['isParenthesised']=1.0
    trimmedText = wsText.lstrip()
    wsCount = len(wsText) - len(trimmedText)
    lastElement['leadingWS']=wsCount
    trimmedText = wsText.rstrip()
    wsCount = len(wsText) - len(trimmedText)
    lastElement['trailingWS']=wsCount
    rpnList.append(lastElement)

def addWS(rpnList,wsText):
    lastElement = rpnList.pop()
    trimmedText = wsText.lstrip()
    wsCount = len(wsText) - len(trimmedText)
    lastElement['leadingWS']=wsCount
    trimmedText = wsText.rstrip()
    wsCount = len(wsText) - len(trimmedText)
    lastElement['trailingWS']=wsCount
    rpnList.append(lastElement)

def getBooleanConstantValue(textValue):
    if textValue=='TRUE':
        return '1.0'
    return '0.0'

def resolveSugar3dCell(sugar3dCell):
    i = sugar3dCell.find('[')
    j = sugar3dCell.find(']')
    return sugar3dCell[:i]+'.'+sugar3dCell[i+1:j], sugar3dCell[:i]+sugar3dCell[j+1:]

def getIncrementVal(rpnList):
    if len(rpnList)>2:
        if rpnList[-1].get('IsSyntacticSugar') and rpnList[-1]['nodeType']=='3dCellReference' and rpnList[-2].get('IsSyntacticSugar') and rpnList[-2]['nodeType']=='3dCellReference':
            return 2
    return 1