def match_tokens(expected_tokens):
if isinstance(expected_tokens, Token):<EOL><INDENT>def _grammar_func(tokens):<EOL><INDENT>try:<EOL><INDENT>next_token = next(iter(tokens))<EOL><DEDENT>except StopIteration:<EOL><INDENT>return<EOL><DEDENT>if next_token == expected_tokens:<EOL><INDENT>return TokenMatch(None, next_token.value, (next_token,))<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(expected_tokens, tuple):<EOL><INDENT>match_len = len(expected_tokens)<EOL>def _grammar_func(tokens):<EOL><INDENT>upcoming = tuple(itertools.islice(tokens, match_len))<EOL>if upcoming == expected_tokens:<EOL><INDENT>return TokenMatch(None, None, upcoming)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % expected_tokens)<EOL><DEDENT>return _grammar_func<EOL>
Generate a grammar function that will match 'expected_tokens' only.