tracker
All repositories: gitoria
1.9 KB
# refparams.py <app dir> [--apply] [files...]: lambda parameters that a body only READS get `&` (hybriel#48: a lambda parameter# copies its argument since 4371b7aa; before it was a reference — `&` restores exactly that for read-only params, without the copy).# Skipped: params assigned (p = …), field-assigned (p.x = / p[k] =), list-mutated (p.push …), aliased (let x = p), defaults.import re,sys,glob,osos.chdir(sys.argv[1]); apply='--apply' in sys.argvfiles=[a for a in sys.argv[2:] if a!='--apply'] or (glob.glob('*.hl')+glob.glob('lib/*.hl')+glob.glob('components/*.hl')+glob.glob('tools/*.hl'))total=0; changed_files=0for f in sorted(files):src=open(f,encoding='utf-8').read(); out=[]; last=0; n=0for m in re.finditer(r'\(([^()]*)\)(\s*=>\s*\{)',src):params=[p.strip() for p in m.group(1).split(',')]if params==[''] : continueif not all(re.match(r'^&?\w+$',p) for p in params): continuei=m.end(); depth=1while depth and i<len(src):c=src[i]; depth += (c=='{') - (c=='}'); i+=1body=src[m.end():i-1]new=[]for p in params:if p.startswith('&'): new.append(p); continuebad = re.search(r'(?<![\w.])%s\s*=(?!=)'%p,body) or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])+\s*=(?!=)'%p,body) \or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])*\.(push|pop|shift|unshift|splice|sort|reverse)\('%p,body) \or re.search(r'=\s*%s\s*$'%p,body,re.M) or re.search(r'=\s*%s\s*[;}]'%p,body) or re.search(r'(?<![\w.])%s\s*(\+\+|--)'%p,body)new.append(p if bad else '&'+p)if new!=params:n+=1out.append(src[last:m.start()]); out.append('('+', '.join(new)+')'); last=m.start()+1+len(m.group(1))+1out.append(src[last:])if n:total+=n; changed_files+=1print(f'{f}: {n} lambdas')if apply: open(f,'w',encoding='utf-8').write(''.join(out))print('total lambdas changed',total,'files',changed_files)
Branches
Latest commits
- aed12917Reference owned Style rules in genres and searchmre
- 78ee6b56Move remaining component styles into Style blocksmre
- 7f04de33log: HM49Bmre
- 00616cf3log: #49 batch merged, DP67 startedmre
- d7232e86Merge hm49-styles: tracker#49 first batch of component stylesmre
- 079f376dMove seven components' styles into Style blocksmre
- 17d66feelog: #58 mergedmre
- 69a6640bMerge hm58-map: tracker#58 project.hl only the mapmre
- a85f7900Move route logic out of the project mapmre
- 13dea5belog: #56 live, HM49 and HM58 startedmre
- a31c8f2fdocs: tracker#36 remaining listmre
- 975d06d1log: #36 live, DP66 startedmre
- d6d03fa3mission: T36Bmre
- e7512d00status: #36 rolled back, retry askedmre
- c98e2043log: T36A rollbackmre
- ae905f15Merge t36a: tracker#36 apply rechecks, reportmre
- 796bfaceT36A: report validated fixes, failed live SSH check and verified rollbackmre
- 55257852log: #53 live, #56 mergedmre
- 78b39f1bMerge hm56-rows: tracker#56 list builders insert oncemre
- 7aea52batmdb fix: protect owners without slugs and record passing gatesmre