| @@ -46,7 +46,8 @@ class Parser: | |||||
| def parse(self, stream, start_symbol=None): | def parse(self, stream, start_symbol=None): | ||||
| # Define parser functions | # Define parser functions | ||||
| start_symbol = start_symbol or self.start_symbol | start_symbol = start_symbol or self.start_symbol | ||||
| delayed_matches = defaultdict(list) | |||||
| delayed_matches = defaultdict(set) | |||||
| match_after_ignore = set() | |||||
| text_line = 1 | text_line = 1 | ||||
| text_column = 0 | text_column = 0 | ||||
| @@ -82,20 +83,28 @@ class Parser: | |||||
| for x in self.ignore: | for x in self.ignore: | ||||
| m = x.match(stream, i) | m = x.match(stream, i) | ||||
| if m: | if m: | ||||
| delayed_matches[m.end()] |= set(to_scan) | |||||
| if m.end() == len(stream): | |||||
| match_after_ignore.update(set(column.to_reduce)) | |||||
| # TODO add partial matches for ignore too? | # TODO add partial matches for ignore too? | ||||
| delayed_matches[m.end()] += to_scan | |||||
| # s = m.group(0) | |||||
| # for j in range(1, len(s)): | |||||
| # m = x.match(s[:-j]) | |||||
| # if m: | |||||
| # delayed_matches[m.end()] += to_scan | |||||
| for item in to_scan: | for item in to_scan: | ||||
| m = item.expect.match(stream, i) | m = item.expect.match(stream, i) | ||||
| if m: | if m: | ||||
| t = Token(item.expect.name, m.group(0), i, text_line, text_column) | t = Token(item.expect.name, m.group(0), i, text_line, text_column) | ||||
| delayed_matches[m.end()].append(item.advance(t)) | |||||
| delayed_matches[m.end()].add(item.advance(t)) | |||||
| s = m.group(0) | s = m.group(0) | ||||
| for j in range(1, len(s)): | for j in range(1, len(s)): | ||||
| m = item.expect.match(s[:-j]) | m = item.expect.match(s[:-j]) | ||||
| if m: | if m: | ||||
| delayed_matches[m.end()].append(item.advance(m.group(0))) | |||||
| delayed_matches[m.end()].add(item.advance(m.group(0))) | |||||
| next_set = Column(i+1) | next_set = Column(i+1) | ||||
| next_set.add(delayed_matches[i+1]) | next_set.add(delayed_matches[i+1]) | ||||
| @@ -125,6 +134,10 @@ class Parser: | |||||
| solutions = [n.tree for n in column.to_reduce | solutions = [n.tree for n in column.to_reduce | ||||
| if n.rule.origin==start_symbol and n.start is column0] | if n.rule.origin==start_symbol and n.start is column0] | ||||
| if not solutions: | |||||
| solutions = [n.tree for n in match_after_ignore | |||||
| if n.rule.origin==start_symbol and n.start is column0] | |||||
| if not solutions: | if not solutions: | ||||
| raise ParseError('Incomplete parse: Could not find a solution to input') | raise ParseError('Incomplete parse: Could not find a solution to input') | ||||
| elif len(solutions) == 1: | elif len(solutions) == 1: | ||||