Make scanner switching lexically scoped, because when it's dynamically scoped... that way lies madness.
Cat's Eye Technologies
10 years ago
715 | 715 |
+ dog cat
|
716 | 716 |
= ok
|
717 | 717 |
|
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`.
|
721 | 721 |
|
722 | 722 |
| 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.
|
731 | 723 |
+ cat dog
|
732 | 724 |
= dog
|
733 | 725 |
|
524 | 524 |
new_scanner_class = RawScanner
|
525 | 525 |
else:
|
526 | 526 |
raise ValueError("No such scanner '%s'" % scanner_name)
|
|
527 |
old_scanner_class = self.scanner.__class__
|
527 | 528 |
self.scanner = self.scanner.switch(new_scanner_class)
|
528 | 529 |
result = self.interpret(sub)
|
|
530 |
self.scanner = self.scanner.switch(old_scanner_class)
|
529 | 531 |
return result
|
530 | 532 |
elif ast[0] == 'WHILE':
|
531 | 533 |
result = Term('nil')
|