diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2019-07-06 00:34:19 -0500 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2019-07-06 00:34:19 -0500 |
commit | ffee388a149836b1f8d128bc953c1b0363cee82b (patch) | |
tree | 8811ad21cdb6b09c0aecc42328ebd2b6f45341f0 /pyparsing.py | |
parent | 8b73519b483f155cfee69e36357833310ffe9dd6 (diff) | |
download | pyparsing-git-ffee388a149836b1f8d128bc953c1b0363cee82b.tar.gz |
Add support for multiple '...' skips in a single expression; `_skippped` results name will always return a list of skipped items
Diffstat (limited to 'pyparsing.py')
-rw-r--r-- | pyparsing.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/pyparsing.py b/pyparsing.py index 0f6d499..3d42289 100644 --- a/pyparsing.py +++ b/pyparsing.py @@ -2044,10 +2044,11 @@ class ParserElement(object): is equivalent to: - Literal('start') + SkipTo('end')("_skipped") + Literal('end') - - Note that the skipped text is returned with '_skipped' as a results name. + Literal('start') + SkipTo('end')("_skipped*") + Literal('end') + Note that the skipped text is returned with '_skipped' as a results name, + and to support having multiple skips in the same parser, the value returned is + a list of all skipped text. """ if other is Ellipsis: return _PendingSkip(self) @@ -2065,7 +2066,7 @@ class ParserElement(object): Implementation of + operator when left operand is not a :class:`ParserElement` """ if other is Ellipsis: - return SkipTo(self)("_skipped") + self + return SkipTo(self)("_skipped*") + self if isinstance(other, basestring): other = ParserElement._literalStringClass(other) @@ -2669,14 +2670,15 @@ class _PendingSkip(ParserElement): self.must_skip = must_skip def __add__(self, other): - skipper = SkipTo(other).setName("...")("_skipped") + skipper = SkipTo(other).setName("...")("_skipped*") if self.must_skip: def must_skip(t): - if not t._skipped: + if not t._skipped or t._skipped.asList() == ['']: del t[0] t.pop("_skipped", None) def show_skip(t): - if not t._skipped: + if t._skipped.asList()[-1:] == ['']: + skipped = t.pop('_skipped') t['_skipped'] = 'missing <' + repr(self.anchor) + '>' return (self.anchor + skipper().addParseAction(must_skip) | skipper().addParseAction(show_skip)) + other @@ -3842,7 +3844,7 @@ class And(ParseExpression): if expr is Ellipsis: if i < len(exprs)-1: skipto_arg = (Empty() + exprs[i+1]).exprs[-1] - tmp.append(SkipTo(skipto_arg)("_skipped")) + tmp.append(SkipTo(skipto_arg)("_skipped*")) else: raise Exception("cannot construct And with sequence ending in ...") else: |