Last active
September 25, 2018 20:14
-
-
Save serguei-k/3e75c1026137f2215357b4c586992889 to your computer and use it in GitHub Desktop.
Lexer Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_while(self, predicate): | |
str = '' | |
while not self._data.end() and predicate(self._data.peek()): | |
str += self._data.next() | |
return str | |
@staticmethod | |
def is_string(char, strict=True): | |
if strict: | |
return char.isalpha() | |
return char.isalnum() or char in ['.', '_', ':'] | |
def read_string(self): | |
return Token(StringToken, self.read_while(functools.partial(self.is_string, strict=False))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment