Example #1
0
def _parse_snippet_file(content, filename):
    """Parses 'content' assuming it is a .snippet file and yields events."""
    filename = filename[:-len(".snippet")]  # strip extension
    segments = _splitall(filename)
    segments = segments[segments.index("snippets")+1:]
    assert len(segments) in (2, 3)

    trigger = segments[1]
    description = segments[2] if 2 < len(segments) else ""

    # Chomp \n if any.
    if content and content.endswith(os.linesep):
        content = content[:-len(os.linesep)]
    yield "snippet", (SnipMateSnippetDefinition(trigger, content, description),)
Example #2
0
def _parse_snippet(line, lines):
    """Parse a snippet defintions."""
    trigger, description = head_tail(line[len("snippet"):].lstrip())
    content = ""
    while True:
        next_line = lines.peek()
        if next_line is None:
            break
        if next_line.strip() and not next_line.startswith('\t'):
            break
        line = next(lines)
        if line[0] == '\t':
            line = line[1:]
        content += line
    content = content[:-1]  # Chomp the last newline
    return "snippet", (SnipMateSnippetDefinition(trigger, content,
                                                 description), )
Example #3
0
def _parse_snippet(line, lines, filename):
    """Parse a snippet defintions."""
    start_line_index = lines.line_index
    trigger, description = head_tail(line[len('snippet'):].lstrip())
    content = ''
    while True:
        next_line = lines.peek()
        if next_line is None:
            break
        if next_line.strip() and not next_line.startswith('\t'):
            break
        line = next(lines)
        if line[0] == '\t':
            line = line[1:]
        content += line
    content = content[:-1]  # Chomp the last newline
    return 'snippet', (SnipMateSnippetDefinition(
        trigger, content, description,
        '%s:%i' % (filename, start_line_index)), )