equal
deleted
inserted
replaced
20 class parser(object): |
20 class parser(object): |
21 def __init__(self, tokenizer, elements, methods=None): |
21 def __init__(self, tokenizer, elements, methods=None): |
22 self._tokenizer = tokenizer |
22 self._tokenizer = tokenizer |
23 self._elements = elements |
23 self._elements = elements |
24 self._methods = methods |
24 self._methods = methods |
|
25 self.current = None |
25 def _advance(self): |
26 def _advance(self): |
26 'advance the tokenizer' |
27 'advance the tokenizer' |
27 t = self.current |
28 t = self.current |
28 try: |
29 try: |
29 self.current = self._iter.next() |
30 self.current = self._iter.next() |
74 self._match(infix[2], pos) |
75 self._match(infix[2], pos) |
75 return expr |
76 return expr |
76 def parse(self, message): |
77 def parse(self, message): |
77 'generate a parse tree from a message' |
78 'generate a parse tree from a message' |
78 self._iter = self._tokenizer(message) |
79 self._iter = self._tokenizer(message) |
79 self.current = self._iter.next() |
80 self._advance() |
80 return self._parse() |
81 return self._parse() |
81 def eval(self, tree): |
82 def eval(self, tree): |
82 'recursively evaluate a parse tree using node methods' |
83 'recursively evaluate a parse tree using node methods' |
83 if not isinstance(tree, tuple): |
84 if not isinstance(tree, tuple): |
84 return tree |
85 return tree |