Advertisement
Guest User

Untitled

a guest
May 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import re
  2. x = r"""
  3. /* comment 1 */
  4. /***
  5. comment 2
  6. ***/
  7. /*=================
  8. comment 3
  9. */
  10. /*comment 4*/
  11. /* comment 5
  12. ***/
  13. /*****
  14. comment 6*/
  15. /* ****
  16. comment 7*/
  17. /* **** comment 8
  18. */
  19. /* **** comment 9
  20. *** */
  21. """
  22. y = re.compile(r'\/\*(?P<inner>.+?)\*\/', flags=re.UNICODE | re.MULTILINE | re.IGNORECASE | re.DOTALL)
  23. z = y.findall(x)
  24. a = [_.splitlines() for _ in z]
  25.  
  26. def trashline(line):
  27. l = line.strip()
  28. if l:
  29. l0 = l[0]
  30. if l.count(l0) == len(l):
  31. return None
  32. else:
  33. return line
  34. return None
  35.  
  36. def consumer(x):
  37. xlen = len(x)
  38. if xlen == 1:
  39. return x
  40. elif xlen > 2:
  41. return x[1:-1] # consume the first line /** ... and the last line *///
  42. elif xlen == 2:
  43. if trashline(x[0]) is None:
  44. return x[1]
  45. elif trashline(x[1]) is None:
  46. return x[0]
  47. else:
  48. raise ValueError("hmmm1")
  49. raise ValueError("hmm2")
  50. outs = [consumer(_) for _ in a]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement