def unary_checks(Q, operation): Q_plus = beautifier.do(repeat.do(Q)) Q_star = beautifier.do(repeat.do(Q, min_repetition_n=0)) Q_is_Q_star = identity.do(Q, Q_star) Q_is_Q_plus = identity.do(Q, Q_plus) # \Cut{Q Q} = \Nothing y = operation(Q, Q) assert y.is_Nothing() # if Q != Q+: \CutBegin{Q+ Q} = Q* if not Q_is_Q_plus: y = operation(Q_plus, Q) assert identity.do(y, Q_star) # if Q != Q*: \CutBegin{Q* Q} = Q* if not Q_is_Q_star: y = operation(Q_star, Q) assert identity.do(y, Q_star) # \Cut{Q \Nothing} = Q y = operation(Q, DFA.Nothing()) assert identity.do(y, Q) # \Cut{\Nothing Q} = \Nothing y = operation(DFA.Nothing(), Q) assert y.is_Nothing() # \Cut{Q \Universal} = \Nothing y = operation(Q, DFA.Universal()) assert y.is_Nothing() # NOT: \Cut{\Universal Q} = \Universal if not Q_is_Q_star and not Q_is_Q_plus: y = operation(Q, DFA.Universal()) assert y.is_Nothing() return Q_star, Q_plus
def snap_nothing(stream, PatternDict): return DFA.Nothing()