Process a match to determine if it is correct, and to find the correct substitution that will convert the term into the pattern. Parameters ---------- rule : RewriteRule syms : iterable Iterable of subterms that match a corresponding variable. Returns -------
(rule, syms)
| 410 | |
| 411 | |
| 412 | def _process_match(rule, syms): |
| 413 | """Process a match to determine if it is correct, and to find the correct |
| 414 | substitution that will convert the term into the pattern. |
| 415 | |
| 416 | Parameters |
| 417 | ---------- |
| 418 | rule : RewriteRule |
| 419 | syms : iterable |
| 420 | Iterable of subterms that match a corresponding variable. |
| 421 | |
| 422 | Returns |
| 423 | ------- |
| 424 | A dictionary of {vars : subterms} describing the substitution to make the |
| 425 | pattern equivalent with the term. Returns `None` if the match is |
| 426 | invalid.""" |
| 427 | |
| 428 | subs = {} |
| 429 | varlist = rule._varlist |
| 430 | if not len(varlist) == len(syms): |
| 431 | raise RuntimeError("length of varlist doesn't match length of syms.") |
| 432 | for v, s in zip(varlist, syms): |
| 433 | if v in subs and subs[v] != s: |
| 434 | return None |
| 435 | else: |
| 436 | subs[v] = s |
| 437 | return subs |