def _check_states(self, states): def valid_pair(state): return (isinstance(state, (list, tuple)) and len(state) == 2 and for_all(lambda x: isinstance(x, str), state) and state[-1] in ["inclusive", "exclusive"]) if not (isinstance(states, (tuple, list)) and for_all(valid_pair, states)): raise SyntaxError(("'states' must be a tuple (list) of 2 element tuples" " where each pair is of the form (state_name, state_mode)" " (state_mode is either 'inclusive' or 'exclusive')")) state_names = map(lambda (x, _): x, states) if self._default_state_name() in state_names: raise SyntaxError("%r is an implicit default state" % self._default_state_name()) if len(state_names) != len(set(state_names)): raise SyntaxError("duplicate states defined")
def valid_pair(state): return (isinstance(state, (list, tuple)) and len(state) == 2 and for_all(lambda x: isinstance(x, str), state) and state[-1] in ["inclusive", "exclusive"])
def _check_token_names(self, names): if not (isinstance(names, (tuple, list)) and for_all(lambda x: isinstance(x, str), names)): raise SyntaxError("'tokens' must be a tuple (list) of strings") if len(names) != len(set(names)): raise SyntaxError("duplicate tokens defined")