def _parse_snippets_file(data, filename): """Parse 'data' assuming it is a snippet file. Yields events in the file. """ python_globals = defaultdict(list) lines = LineIterator(data) current_priority = 0 actions = {} context = None for line in lines: if not line.strip(): continue head, tail = head_tail(line) if head in ("snippet", "global"): snippet = _handle_snippet_or_global( filename, line, lines, python_globals, current_priority, actions, context, ) actions = {} context = None if snippet is not None: yield snippet elif head == "extends": yield handle_extends(tail, lines.line_index) elif head == "clearsnippets": yield "clearsnippets", (current_priority, tail.split()) elif head == "context": ( head, context, ) = handle_context(tail, lines.line_index) if head == "error": yield (head, tail) elif head == "priority": try: current_priority = int(tail.split()[0]) except (ValueError, IndexError): yield "error", ("Invalid priority %r" % tail, lines.line_index) elif head in ["pre_expand", "post_expand", "post_jump"]: head, tail = handle_action(head, tail, lines.line_index) if head == "error": yield (head, tail) else: (actions[head], ) = tail elif head and not head.startswith("#"): yield "error", ("Invalid line %r" % line.rstrip(), lines.line_index)
def _parse_snippets_file(data, filename): """Parse 'data' assuming it is a .snippets file. Yields events in the file. """ lines = LineIterator(data) for line in lines: if not line.strip(): continue head, tail = head_tail(line) if head == "extends": yield handle_extends(tail, lines.line_index) elif head in "snippet": snippet = _parse_snippet(line, lines, filename) if snippet is not None: yield snippet elif head and not head.startswith("#"): yield "error", ("Invalid line %r" % line.rstrip(), lines.line_index)