Ejemplo n.º 1
0
def convertVariableName(token,line,t,v,i,understood,variables):
    if token[i+1][0] == tokenize.OP and token[i+1][1] == '=':
        type,understood = getType(token , i+2, understood,variables)
        if not (v in variables) or type != variables[v]:
            variables[v] = type
            line += 'my '
    elif token[i-1][0] == tokenize.NAME and token[i-1][1] == 'for' and token[i+2][1] == 'range':
        if not (v in variables) or "NONSTRINGSCALAR" != variables[v]:
            variables[v] = "NONSTRINGSCALAR"
    if v in variables and variables[v] == 'STRING':
        if len(token) - i > 1 and token[i+1][0] == tokenize.OP and token[i+1][1] == '%':
            line, i, understood, variables = convertSprintf(token,line,t,v,i,understood,variables)
        else:
            line += '$' + v + ' '
    elif v in variables and variables[v] == 'NONSTRINGSCALAR':
        line += '$' + v + ' '
    elif v in variables and variables[v] == 'LIST':
        if token[i+1][0] == tokenize.OP and token[i+1][1] == '[':
            line += '@' + v
        elif token[i+1][0] == tokenize.OP and token[i+1][1]   == '.' and\
             token[i+2][0] == tokenize.NAME and token[i+2][1] == 'append'and\
             token[i+3][0] == tokenize.OP and token[i+3][1] == '(':
            toAppend, i, understood, variables = convertGrouping(token,line,t,v,i+3,understood,variables)
            line += 'push(@'+v+','+ toAppend + ') '
        elif token[i+1][0] == tokenize.OP and token[i+1][1]   == '.' and\
             token[i+2][0] == tokenize.NAME and token[i+2][1] == 'pop'and\
             token[i+3][0] == tokenize.OP and token[i+3][1] == '(' and\
             token[i+4][0] == tokenize.OP and token[i+4][1] == ')':
             line += 'pop(@' + v + ') '
             i += 4
        else:
            line += '@' + v + ' '
    elif v in variables and variables[v] == 'DICT':
        if token[i+1][0] == tokenize.OP and token[i+1][1] == '[':
            line += '%' + v
        elif token[i+1][0] == tokenize.OP and token[i+1][1]   == '.' and\
             token[i+2][0] == tokenize.NAME and token[i+2][1] == 'keys'and\
             token[i+3][0] == tokenize.OP and token[i+3][1] == '(' and\
             token[i+4][0] == tokenize.OP and token[i+4][1] == ')':
            line += 'keys(' + v + ') '
            i+= 4
        else:
            line += '%' + v + ' '
    else:
        line += '$' + v + ' '
    return line, i, understood, variables
Ejemplo n.º 2
0
def convertString(token,line, t, v, i, understood, variables):
    if len(token) - i > 1 and token[i+1][0] == tokenize.OP and token[i+1][1] == '%':
        return convertSprintf.convertSprintf(token,line,t,v,i,understood,variables)
    else:
        return getString(token,line,t,v,i,understood,variables)