Example #1
0
def scanScopeAST(scope,keyword,matchfinder):
    lines = scope.generateLinesNotIncludingThoseBelongingToChildScopes()
    match = None
    for line,linenum in generateLogicalLinesAndLineNumbers(lines):
        if isWordInLine(keyword, line):
            doctoredline = makeLineParseable(line)
            ast = compiler.parse(doctoredline)
            matchfinder.reset(line)
            match = visitor.walk(ast,matchfinder).getMatch()
            if match is not None:
                column,yoffset = indexToCoordinates(line,match)
                m = createMatch(scope,linenum + yoffset,column)
                return m
    return None
Example #2
0
def getLogicalLine(module, lineno):
    # we know that the scope is the start of a logical line, so
    # we search from there
    scope = getScopeForLine(module.getSourceNode(), lineno)
    linegenerator = \
            module.generateLinesWithLineNumbers(scope.getStartLine())
    for lline,llinenum in \
            generateLogicalLinesAndLineNumbers(linegenerator):
        if llinenum > lineno:
            break
        prevline = lline
        prevlinenum = llinenum

    backtrackchars = 0
    for i in range(prevlinenum, lineno):
        backtrackchars += len(module.getSourceNode().getLines()[i - 1])
    return prevline, backtrackchars
Example #3
0
def getLogicalLine(module, lineno):
    # we know that the scope is the start of a logical line, so
    # we search from there
    scope = getScopeForLine(module.getSourceNode(), lineno)
    linegenerator = \
            module.generateLinesWithLineNumbers(scope.getStartLine())
    for lline,llinenum in \
            generateLogicalLinesAndLineNumbers(linegenerator):
        if llinenum > lineno:
            break
        prevline = lline
        prevlinenum = llinenum

    backtrackchars = 0
    for i in range(prevlinenum,lineno):
        backtrackchars += len(module.getSourceNode().getLines()[i-1])
    return prevline, backtrackchars