Show More
@@ -30,7 +30,7 b' class parser(object):' | |||||
30 | except StopIteration: |
|
30 | except StopIteration: | |
31 | pass |
|
31 | pass | |
32 | return t |
|
32 | return t | |
33 | def _match(self, m): |
|
33 | def _match(self, m, pos): | |
34 | 'make sure the tokenizer matches an end condition' |
|
34 | 'make sure the tokenizer matches an end condition' | |
35 | if self.current[0] != m: |
|
35 | if self.current[0] != m: | |
36 | raise error.ParseError("unexpected token: %s" % self.current[0], |
|
36 | raise error.ParseError("unexpected token: %s" % self.current[0], | |
@@ -46,12 +46,12 b' class parser(object):' | |||||
46 | expr = (prefix[0], value) |
|
46 | expr = (prefix[0], value) | |
47 | else: |
|
47 | else: | |
48 | if len(prefix) > 2 and prefix[2] == self.current[0]: |
|
48 | if len(prefix) > 2 and prefix[2] == self.current[0]: | |
49 | self._match(prefix[2]) |
|
49 | self._match(prefix[2], pos) | |
50 | expr = (prefix[0], None) |
|
50 | expr = (prefix[0], None) | |
51 | else: |
|
51 | else: | |
52 | expr = (prefix[0], self._parse(prefix[1])) |
|
52 | expr = (prefix[0], self._parse(prefix[1])) | |
53 | if len(prefix) > 2: |
|
53 | if len(prefix) > 2: | |
54 | self._match(prefix[2]) |
|
54 | self._match(prefix[2], pos) | |
55 | # gather tokens until we meet a lower binding strength |
|
55 | # gather tokens until we meet a lower binding strength | |
56 | while bind < self._elements[self.current[0]][0]: |
|
56 | while bind < self._elements[self.current[0]][0]: | |
57 | token, value, pos = self._advance() |
|
57 | token, value, pos = self._advance() | |
@@ -64,14 +64,14 b' class parser(object):' | |||||
64 | # handle infix rules |
|
64 | # handle infix rules | |
65 | infix = self._elements[token][2] |
|
65 | infix = self._elements[token][2] | |
66 | if len(infix) == 3 and infix[2] == self.current[0]: |
|
66 | if len(infix) == 3 and infix[2] == self.current[0]: | |
67 | self._match(infix[2]) |
|
67 | self._match(infix[2], pos) | |
68 | expr = (infix[0], expr, (None)) |
|
68 | expr = (infix[0], expr, (None)) | |
69 | else: |
|
69 | else: | |
70 | if not infix[0]: |
|
70 | if not infix[0]: | |
71 | raise error.ParseError("not an infix: %s" % token, pos) |
|
71 | raise error.ParseError("not an infix: %s" % token, pos) | |
72 | expr = (infix[0], expr, self._parse(infix[1])) |
|
72 | expr = (infix[0], expr, self._parse(infix[1])) | |
73 | if len(infix) == 3: |
|
73 | if len(infix) == 3: | |
74 | self._match(infix[2]) |
|
74 | self._match(infix[2], pos) | |
75 | return expr |
|
75 | return expr | |
76 | def parse(self, message): |
|
76 | def parse(self, message): | |
77 | 'generate a parse tree from a message' |
|
77 | 'generate a parse tree from a message' |
General Comments 0
You need to be logged in to leave comments.
Login now