Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. def makekeyiflinefromsourcerec(re):
  2.  
  3. # AND | NOT ^ OR ~
  4.  
  5. for xx2 in re:
  6.  
  7. if xx2.lstrip()[0:6]=="#@keys":
  8.  
  9. kl = list(xx2[7:G_max].lstrip().rstrip())
  10.  
  11. andnotorl = [];aand = 1;nnot = 0;oor = 0;st1 = ""
  12.  
  13. while kl:
  14. ch = kl.pop(0)
  15. if ch =="|":
  16. if aand:
  17. if st1: andnotorl.append((st1,"and"))
  18. if nnot:
  19. if st1: andnotorl.append((st1,"not"))
  20. if oor:
  21. if st1: andnotorl.append((st1,"or"))
  22. aand = 1 ; nnot = 0 ; oor=0;st1 = ""
  23. else:
  24. if ch == "^":
  25. if aand:
  26. if st1: andnotorl.append((st1,"and"))
  27. if nnot:
  28. if st1: andnotorl.append((st1,"not"))
  29. if oor:
  30. if st1: andnotorl.append((st1,"or"))
  31. aand = 0 ; nnot = 1 ;oor=0; st1 = ""
  32. else:
  33. if ch == "~":
  34. if aand:
  35. if st1: andnotorl.append((st1,"and"))
  36. if nnot:
  37. if st1: andnotorl.append((st1,"not"))
  38. if oor:
  39. if st1: andnotorl.append((st1,"or"))
  40. aand = 0 ; nnot = 0 ; oor=1 ; st1 = ""
  41. else:
  42. st1 = st1+ch
  43.  
  44. if aand:
  45. andnotorl.append((st1,"and"))
  46. if nnot:
  47. andnotorl.append((st1,"not"))
  48. if oor:
  49. andnotorl.append((st1,"or"))
  50.  
  51. nr = []
  52.  
  53. for i,vv in enumerate(re):
  54. if not(i):
  55. nr.append(vv)
  56. else:
  57. if i == 1:
  58.  
  59. fst = "if "
  60.  
  61. for i2,ov in enumerate(andnotorl):
  62.  
  63. if ov[1] == "or":
  64. fst += " or "
  65. fst += ov[0]
  66.  
  67. if ov[1] == "and":
  68. if i2:
  69. fst += " and "
  70. fst += ov[0]
  71. else:
  72. fst += ov[0]
  73.  
  74. if ov[1] == "not":
  75. if i2:
  76. fst += " and not "
  77. else:
  78. fst += " not "
  79. fst += ov[0]
  80.  
  81. fst += ":"
  82.  
  83. nr.append(" "+fst)
  84.  
  85. else:
  86. nr.append(" "+vv)
  87.  
  88. return nr
  89.  
  90. #~ {'y_displ': 0, 'x_displ': 0, 'rect': (419, 57, 504, 757), 'y': 10, 'x': 22, 'dir': 0}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement