while1elsestmt.py 764 B

1234567891011121314151617181920212223
  1. # Copyright (c) 2020 Rocky Bernstein
  2. def while1elsestmt(self, lhs, n, rule, ast, tokens, first, last):
  3. if last == n:
  4. # Adjust for fuzziness in parsing
  5. last -= 1
  6. if tokens[last] == "COME_FROM_LOOP":
  7. last -= 1
  8. elif tokens[last - 1] == "COME_FROM_LOOP":
  9. last -= 2
  10. if tokens[last] in ("JUMP_BACK", "CONTINUE"):
  11. # These indicate inside a loop, but token[last]
  12. # should not be in a loop.
  13. # FIXME: Not quite right: refine by using target
  14. return True
  15. # if SETUP_LOOP target spans the else part, then this is
  16. # not while1else. Also do for whileTrue?
  17. last += 1
  18. # 3.8+ Doesn't have SETUP_LOOP
  19. return self.version < (3, 8) and tokens[first].attr > tokens[last].off2int()