Mercurial > lbo > hg > pcombinators
changeset 2:4270b8d16f40 draft
Fix bugs in regex and sequence parsers.
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 19 May 2019 12:17:11 +0200 |
parents | 57092e2bbe6c |
children | 466866ebc06c |
files | combinators.py |
diffstat | 1 files changed, 7 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/combinators.py Sun May 19 12:16:53 2019 +0200 +++ b/combinators.py Sun May 19 12:17:11 2019 +0200 @@ -27,8 +27,6 @@ def next(self): current = self.peek() self._index += 1 - while not self.finished() and self.peek().isspace(): - self._index += 1 return current def peek(self): @@ -88,7 +86,10 @@ return None, st st.reset(before) break - results.append(result) + if isinstance(result, list): + results.extend(result) + else: + results.append(result) st = st2 return results, st2 @@ -146,12 +147,13 @@ self._rx = rx def parse(self, st): + start = st.index() match = re.match(self._rx, st.remaining()) if match is None: return None, st begin, end = match.span() result = match.group(0) if len(match.groups()) > 0: - result = match.groups() - st.reset(end) + result = list(match.groups()) + st.reset(start+end) return result, st \ No newline at end of file