gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9fb82efc9fb82efclog: HM54 gap, fill continuesmre9fb82efc/tools/ref-params.py

1.9 KB

  1. # refparams.py <app dir> [--apply] [files...]: lambda parameters that a body only READS get `&` (hybriel#48: a lambda parameter
  2. # copies its argument since 4371b7aa; before it was a reference — `&` restores exactly that for read-only params, without the copy).
  3. # Skipped: params assigned (p = …), field-assigned (p.x = / p[k] =), list-mutated (p.push …), aliased (let x = p), defaults.
  4. import re,sys,glob,os
  5. os.chdir(sys.argv[1]); apply='--apply' in sys.argv
  6. files=[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'))
  7. total=0; changed_files=0
  8. for f in sorted(files):
  9. src=open(f,encoding='utf-8').read(); out=[]; last=0; n=0
  10. for m in re.finditer(r'\(([^()]*)\)(\s*=>\s*\{)',src):
  11. params=[p.strip() for p in m.group(1).split(',')]
  12. if params==[''] : continue
  13. if not all(re.match(r'^&?\w+$',p) for p in params): continue
  14. i=m.end(); depth=1
  15. while depth and i<len(src):
  16. c=src[i]; depth += (c=='{') - (c=='}'); i+=1
  17. body=src[m.end():i-1]
  18. new=[]
  19. for p in params:
  20. if p.startswith('&'): new.append(p); continue
  21. bad = re.search(r'(?<![\w.])%s\s*=(?!=)'%p,body) or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])+\s*=(?!=)'%p,body) \
  22. or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])*\.(push|pop|shift|unshift|splice|sort|reverse)\('%p,body) \
  23. 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)
  24. new.append(p if bad else '&'+p)
  25. if new!=params:
  26. n+=1
  27. out.append(src[last:m.start()]); out.append('('+', '.join(new)+')'); last=m.start()+1+len(m.group(1))+1
  28. out.append(src[last:])
  29. if n:
  30. total+=n; changed_files+=1
  31. print(f'{f}: {n} lambdas')
  32. if apply: open(f,'w',encoding='utf-8').write(''.join(out))
  33. print('total lambdas changed',total,'files',changed_files)

Branches

Latest commits

  • 9fb82efclog: HM54 gap, fill continuesmre
  • b632eb8dlog: HM53 done, HM54 startedmre
  • 3356fcfclog: #52 blocked, HM53 startedmre
  • 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
  • 73010cc0HM52: report replace-navigation search draft regressionmre
  • 1742e92bstatus: DP64 and HM52 runningmre
  • 29ad5b58log: #64 merged, DP64 and HM52 startedmre
  • fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
  • b2e2206dlog: #63 livemre
  • 5831e0e0log: HM64 donemre
  • 4042b923Flatten catalog membership rows into paired slotsmre
  • ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
  • 40439456Merge hm63-searchtext: tracker#63 packed search textmre
  • b7e6b48ePack normalized search text behind numeric offsetsmre
  • b35f53e1log: DP62 stale runtime decisionmre
  • f9593602log: Apollo deploy rule correctionmre
  • 3c95f7f3log: DP62 and HM63 startedmre
  • 9c4397c9mission HM63mre
  • 8dfe42c8mission DP62mre
  • e347fef4Merge rv44: tracker#61 #62 on Hybriel day44mre