removeTypeCtx.py 782 Bytes
Newer Older
Guillaume GENESTIER's avatar
Guillaume GENESTIER committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import sys

i=True
for fil in sys.argv:
    print(fil)
    if i:
        i=False
        continue
    toRead=open(fil,'r')
    res=[]
    for line in toRead:
        if line[:2]=="(;":
            res.append(line)
        else:
            tab=line.split(']')
            if len(tab)==2:
                res.append("")
                ctx=tab[0].split(",")
                j=True
                for decl in ctx:
                    if j:
                       j=False
                    else:
                        res[-1]+=","
                    res[-1]+=decl.split(":")[0]
                res[-1]+=']'+tab[1]
            else:
                res.append(line)
    toRead.close()
    toWrite=open(fil,'w')
    for line in res:
        toWrite.write(line)
    toWrite.close()