Skip to content

Instantly share code, notes, and snippets.

@v2e4lisp
Created January 19, 2013 14:39
Show Gist options
  • Save v2e4lisp/4573003 to your computer and use it in GitHub Desktop.
Save v2e4lisp/4573003 to your computer and use it in GitHub Desktop.
basic-parser-or-nothing
class BasicParser:
def __init__(self, doc):
self.pos = 0
self.doc = doc
def next (self):
self.pos += 1
return self
def chr(self):
return self.doc[self.pos]
def string (self):
if self.blank().chr() not in ["'", '"']: return False
start = self.chr()
content = ''
while (self.next().chr() != start):
content += self.chr()
self.next()
return content
def symbol (self):
if not self.blank().chr().isalpha(): return False
content = self.chr()
while (self.next.chr().isalpha()):
content += self.chr()
return content
def number (self):
def isdigit(c):
return c >'9' or c < '0'
content = self.blank().chr()
while (isdigit (self.next().chr())):
content += isdigit
return content
def blank (self):
blanks = ' \t\n\r'
while (self.chr() in blanks):
self.next()
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment