diff options
author | ptmcg <ptmcg@austin.rr.com> | 2020-12-24 00:30:59 -0600 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2020-12-24 00:30:59 -0600 |
commit | d7fc7e5499276427a4ce2758b3d0a23747d50ce9 (patch) | |
tree | caba495699fc0b5b07026639e897e1d619ca80c4 | |
parent | 3abd462a9188e820e69ff8478c999bbf16db05e1 (diff) | |
download | pyparsing-git-d7fc7e5499276427a4ce2758b3d0a23747d50ce9.tar.gz |
Move OnlyOnce out of core.py and into actions.py
-rw-r--r-- | pyparsing/actions.py | 23 | ||||
-rw-r--r-- | pyparsing/core.py | 22 |
2 files changed, 23 insertions, 22 deletions
diff --git a/pyparsing/actions.py b/pyparsing/actions.py index 0c185ab..827c74f 100644 --- a/pyparsing/actions.py +++ b/pyparsing/actions.py @@ -4,6 +4,29 @@ from .exceptions import ParseException from .util import col +class OnlyOnce: + """Wrapper for parse actions, to ensure they are only called once. + """ + + def __init__(self, methodCall): + from .core import _trim_arity + self.callable = _trim_arity(methodCall) + self.called = False + + def __call__(self, s, l, t): + if not self.called: + results = self.callable(s, l, t) + self.called = True + return results + raise ParseException(s, l, "OnlyOnce obj called multiple times w/out reset") + + def reset(self): + """Allow the associated parse action to be called once more. + """ + + self.called = False + + def matchOnlyAtCol(n): """Helper method for defining parse actions that require matching at a specific column in the input text. diff --git a/pyparsing/core.py b/pyparsing/core.py index fed71a9..0649a3c 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -4626,28 +4626,6 @@ class Suppress(TokenConverter): return self -class OnlyOnce: - """Wrapper for parse actions, to ensure they are only called once. - """ - - def __init__(self, methodCall): - self.callable = _trim_arity(methodCall) - self.called = False - - def __call__(self, s, l, t): - if not self.called: - results = self.callable(s, l, t) - self.called = True - return results - raise ParseException(s, l, "OnlyOnce obj called multiple times w/out reset") - - def reset(self): - """Allow the associated parse action to be called once more. - """ - - self.called = False - - def traceParseAction(f): """Decorator for debugging parse actions. |