Example #1
0
 def new_replace(s, l, tokens):
     tokenlist = tokens.asList()
     if assert_len is not None:
         assert len(tokenlist) == assert_len, \
             "len(" + repr(tokenlist) + ") != " + repr(assert_len)
     if assert_len_in is not None:
         assert len(tokenlist) in assert_len_in, "len(" + repr(tokenlist) + ") not in " + repr(assert_len_in)
     return _trim_arity(old_replace)(s, l, tokenlist)
Example #2
0
 def new_replace(s, l, tokens):
     tokendict = tokens.asDict()
     if assert_keys is not None:
         assert set(tokendict.keys()) >= set(assert_keys), \
             repr(set(tokendict.keys())) + " != " + repr(set(assert_keys))
     if assert_keys_in is not None:
         assert set(tokendict.keys()) <= set(assert_keys_in), \
             repr(set(tokendict.keys())) + " > " + repr(set(assert_keys_in))
     return _trim_arity(old_replace)(s, l, tokendict)
Example #3
0
 def wrapped_handler(s, l, t):
     self.log_trace(handler.__name__, s, l, t)
     try:
         return _trim_arity(handler)(s, l, t)
     except CoconutException:
         raise
     except Exception:
         raise CoconutInternalException(
             "error calling handler " + handler.__name__ +
             " with tokens", t)
Example #4
0
def create_find_and_replace(grammar, replace):
    """Creates a find-and-replace grammar."""
    return attach(grammar, lambda s, l, t: [_trim_arity(replace)(s, l, t)])