Skip to content

Instantly share code, notes, and snippets.

@serguei-k
Last active September 25, 2018 20:14
Show Gist options
  • Save serguei-k/3e75c1026137f2215357b4c586992889 to your computer and use it in GitHub Desktop.
Save serguei-k/3e75c1026137f2215357b4c586992889 to your computer and use it in GitHub Desktop.
Lexer Example
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