Helper function to simplify comparisons Instance, Match and TokenType :param token: :param i: Class or Tuple/List of Classes :param m: Tuple of TokenType & Value. Can be list of Tuple for multiple :param t: TokenType or Tuple/List of TokenTypes :return: bool
(token, i=None, m=None, t=None)
| 79 | |
| 80 | |
| 81 | def imt(token, i=None, m=None, t=None): |
| 82 | """Helper function to simplify comparisons Instance, Match and TokenType |
| 83 | :param token: |
| 84 | :param i: Class or Tuple/List of Classes |
| 85 | :param m: Tuple of TokenType & Value. Can be list of Tuple for multiple |
| 86 | :param t: TokenType or Tuple/List of TokenTypes |
| 87 | :return: bool |
| 88 | """ |
| 89 | if token is None: |
| 90 | return False |
| 91 | if i and isinstance(token, i): |
| 92 | return True |
| 93 | if m: |
| 94 | if isinstance(m, list): |
| 95 | if any(token.match(*pattern) for pattern in m): |
| 96 | return True |
| 97 | elif token.match(*m): |
| 98 | return True |
| 99 | if t: |
| 100 | if isinstance(t, list): |
| 101 | if any(token.ttype in ttype for ttype in t): |
| 102 | return True |
| 103 | elif token.ttype in t: |
| 104 | return True |
| 105 | return False |
| 106 | |
| 107 | |
| 108 | def consume(iterator, n): |
no test coverage detected