| 818 | |
| 819 | @staticmethod |
| 820 | def stack_fix(lst, index): |
| 821 | # type: (List[Any], List[Any]) -> str |
| 822 | r = "" |
| 823 | mul = 1 |
| 824 | for e in lst: |
| 825 | if isinstance(e, list): |
| 826 | if mul != 1: |
| 827 | mul = mul - 1 |
| 828 | r += RandRegExp.stack_fix(e[1:] * mul, index) |
| 829 | # only the last iteration should be kept for back reference |
| 830 | f = RandRegExp.stack_fix(e[1:], index) |
| 831 | for i, idx in enumerate(index): |
| 832 | if e is idx: |
| 833 | index[i] = f |
| 834 | r += f |
| 835 | mul = 1 |
| 836 | elif isinstance(e, tuple): |
| 837 | kind, val = e |
| 838 | if kind == "cite": |
| 839 | r += index[val - 1] |
| 840 | elif kind == "repeat": |
| 841 | mul = val |
| 842 | |
| 843 | elif kind == "choice": |
| 844 | if mul == 1: |
| 845 | c = random.choice(val) |
| 846 | r += RandRegExp.stack_fix(c[1:], index) |
| 847 | else: |
| 848 | r += RandRegExp.stack_fix([e] * mul, index) |
| 849 | mul = 1 |
| 850 | else: |
| 851 | if mul != 1: |
| 852 | r += RandRegExp.stack_fix([e] * mul, index) |
| 853 | mul = 1 |
| 854 | else: |
| 855 | r += str(e) |
| 856 | return r |
| 857 | |
| 858 | def _fix(self): |
| 859 | # type: () -> str |