An input port. Retains a line of chars.
| 37 | eof_object = Symbol('#<eof-object>') # Note: uninterned; can't be read |
| 38 | |
| 39 | class InPort: |
| 40 | "An input port. Retains a line of chars." |
| 41 | tokenizer = r"""\s*(,@|[('`,)]|"(?:[\\].|[^\\"])*"|;.*|[^\s('"`,;)]*)(.*)""" |
| 42 | def __init__(self, file): |
| 43 | self.file = file; self.line = '' |
| 44 | def next_token(self): |
| 45 | "Return the next token, reading new text into line buffer if needed." |
| 46 | while True: |
| 47 | if self.line == '': self.line = self.file.readline() |
| 48 | if self.line == '': return eof_object |
| 49 | token, self.line = re.match(InPort.tokenizer, self.line).groups() |
| 50 | if token != '' and not token.startswith(';'): |
| 51 | return token |
| 52 | |
| 53 | def readchar(inport): |
| 54 | "Read the next character from an input port." |