git @ Cat's Eye Technologies Tamsin / 410779a
Make scanner switching lexically scoped, because when it's dynamically scoped... that way lies madness. Cat's Eye Technologies 10 years ago
2 changed file(s) with 5 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
715715 + dog cat
716716 = ok
717717
718 Note that we don't actually save the old scanner and restore it after the
719 `with`. If we did, well, it would be more messy than it is currently, it
720 seems. Restore it yourself if you need to!
718 Note that the scanner in force is lexically contained in the `with`. Outside
719 of the `with`, scanning returns to whatever scanner was in force before the
720 `with`.
721721
722722 | main = ("c" & "a" & "t" & " ") with raw & "dog".
723 + cat dog
724 ? expected 'dog' found 'd'
725
726 | main = ("c" & "a" & "t" & " ") with raw & "d" & "o" & "g".
727 + cat dog
728 = g
729
730 | main = ("c" & "a" & "t" & " ") with raw & "dog" with tamsin.
731723 + cat dog
732724 = dog
733725
524524 new_scanner_class = RawScanner
525525 else:
526526 raise ValueError("No such scanner '%s'" % scanner_name)
527 old_scanner_class = self.scanner.__class__
527528 self.scanner = self.scanner.switch(new_scanner_class)
528529 result = self.interpret(sub)
530 self.scanner = self.scanner.switch(old_scanner_class)
529531 return result
530532 elif ast[0] == 'WHILE':
531533 result = Term('nil')