PageRenderTime 73ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/utils/pretopost.py

http://github.com/samueltardieu/rforth1
Python | 29 lines | 24 code | 3 blank | 2 comment | 10 complexity | 730021fbd11971626c8ee2d14430d8ad MD5 | raw file
Possible License(s): GPL-2.0
  1. #! /usr/bin/env python
  2. #
  3. import re, sys
  4. _exr = re.compile ('(\s*)(\S+)\s(.*\S)(.*)')
  5. def main ():
  6. in_code = False
  7. for l in sys.stdin.readlines ():
  8. while l[-1:] in ['\r', '\n']: l = l[:-1]
  9. if l in ['prefix', 'postfix']: continue
  10. if not in_code and l[:5] == 'code ':
  11. in_code = True
  12. elif in_code and l[:5] == ';code':
  13. in_code = False
  14. elif in_code and l[:6:] != 'label ':
  15. s = re.split ('\s+\\\\', l, 1)
  16. code = s[0]
  17. if len (s) == 2: comment = ' \\' + s[1]
  18. else: comment = ''
  19. x = _exr.match (code)
  20. if x:
  21. l = "%s%s %s%s%s" % (x.group (1), x.group (3), x.group (2),
  22. x.group (4), comment)
  23. print(l)
  24. if __name__ == '__main__': main ()