예제 #1
0
def within_Ada_statements(current_file):
    line_num = GPS.Editor.cursor_get_line(current_file)
    column_num = GPS.Editor.cursor_get_column(current_file)
    up_count = 0
    result = False
    block_count = 0

    going_up = attempt_up()
    while going_up:
        up_count = up_count + 1
        prev_line = get_line()
        prev_line = string.lower(prev_line)
        if string.find(prev_line, 'begin') != -1:  # found it
            if block_count == 0:
                result = True
                break
            else:
                block_count = block_count + 1
        elif significant_end(prev_line):
            block_count = block_count - 1
        going_up = attempt_up()
    # now return cursor to original position
    GPS.Editor.cursor_set_position(current_file, line_num, column_num)
    debug("returning " + str(result))
    return result
예제 #2
0
def potential_label(current_file):
    if not within_Ada_statements(current_file):
        return ""
    label = ""
    label_line = get_line()
    label_line = string.rstrip(label_line)  # strip trailing whitespace
    if string.find(label_line, ':') == -1:  # no colon on this line
        # look on the previous line for a stand-alone label, ie "foo :" or
        # "foo:"
        # Rather than go hunting, the label, if any, must be only 1 line up.
        # This will be ok since a label is never the first line of a program
        # unit.
        line_num = GPS.Editor.cursor_get_line(current_file)
        column_num = GPS.Editor.cursor_get_column(current_file)
        going_up = attempt_up()
        if going_up:
            label_line = get_line()
            # found a colon, which might be for a label
            if string.find(label_line, ':') != -1:
                pattern = re.compile("^([ \t]*)(.*):(.*)",
                                     re.IGNORECASE | re.DOTALL)
                match = re.search(pattern, label_line)
                remainder = string.strip(match.group(3))
                if remainder == '':  # right syntax so far
                    temp_label = match.group(2)
                    if temp_label != '':  # found a label
                        label = string.strip(temp_label)

        # now return cursor to original position
        GPS.Editor.cursor_set_position(current_file, line_num, column_num)
    else:  # found ':'
        pattern = re.compile("^([ \t]*)(.*):(.*)", re.IGNORECASE)
        match = re.search(pattern, label_line)
        remainder = string.lstrip(match.group(3))
        label = match.group(2)
        # found assignment operation ":="
        if remainder and remainder[0] == '=':
            debug("returning label '" + label + "'")
            return label

        # Treat as a label, even if it won't be, such as in variable
        # declarations.
        # Since we only use it where allowed, this isn't a problem.
        label = string.strip(label)

    debug("returning label '" + label + "'")
    return label
예제 #3
0
def instantiation(prev_line, current_file):
    original_line_num = GPS.Editor.cursor_get_line(current_file)
    original_column_num = GPS.Editor.cursor_get_column(current_file)
    # check for an instantiation *on the same line* as the subprogram decl
    pattern = re.compile("([ \t]*)is([ \t]*)new(.*)",
                         re.DOTALL | re.IGNORECASE)
    match = re.search(pattern, prev_line)
    if match is not None:
        return True
    # check for instantiation on next line down
    down()
    next_line = get_line()
    if found_separated("new", next_line):
        GPS.Editor.cursor_set_position(current_file, original_line_num,
                                       original_column_num)
        return True
    else:
        GPS.Editor.cursor_set_position(current_file, original_line_num,
                                       original_column_num)
    return False
예제 #4
0
def associated_decl(current_file):
    original_line_num = GPS.Editor.cursor_get_line(current_file)
    original_column_num = GPS.Editor.cursor_get_column(current_file)

    block_count = 0
    expecting_declaration = False
    result = ""

    # we immediately attempt to go up a line to start searching because
    # we want to skip the line we are manipulating.
    # Note that if we cannot go up initially we return the null string
    # as the result, but that makes sense because this function will
    # never be called in such a case when writing legal Ada code.  For
    # example, legal Ada never has a "begin" on the very first line.
    going_up = attempt_up()
    while going_up:
        prev_line = get_line()
        search_begin_line = word_case(prev_line)
        if string.find(search_begin_line, 'begin') != -1:
            if block_count == 0:
                break
            else:
                block_count = block_count + 1

        elif significant_end(prev_line):
            block_count = block_count - 1
            expecting_declaration = True

        elif found_separated("procedure|function", prev_line):
            if not instantiation(prev_line, current_file):
                if expecting_declaration:
                    # found decl for previously encountered begin/end
                    expecting_declaration = False
                else:  # use this one
                    pattern = re.compile(
                        '^([ \t]*)(procedure|function)([ \t]*)'
                        '([a-zA-Z0-9_."=/<>+\-&*]+)(.*)',
                        re.IGNORECASE | re.DOTALL)
                    match = re.search(pattern, prev_line)
                    result = match.group(4)
                    break

        elif found_separated("task", prev_line):
            # we ignore task declarations
            if found_separated("body", prev_line):
                if expecting_declaration:
                    # found decl for previously encountered begin/end
                    expecting_declaration = False
                else:  # use this one
                    pattern = re.compile(
                        '^([ \t]*)task([ \t]*)body([ \t]*)'
                        '([a-zA-Z0-9_.]+)(.*)', re.IGNORECASE | re.DOTALL)
                    match = re.search(pattern, prev_line)
                    result = match.group(4)
                    break

        elif found_separated("entry", prev_line):
            if expecting_declaration:
                # found decl for previously encountered begin/end
                expecting_declaration = False
            else:
                # use this one
                pattern = re.compile(
                    '^([ \t]*)entry([ \t]*)([a-zA-Z0-9_.]+)(.*)',
                    re.IGNORECASE | re.DOTALL)
                match = re.search(pattern, prev_line)
                result = match.group(3)
                break

        elif found_separated("package", prev_line):
            if found_separated("body", prev_line):
                if expecting_declaration:
                    # found decl for previously encountered begin/end
                    expecting_declaration = False
                else:
                    # use this one
                    pattern = re.compile(
                        '^([ \t]*)package([ \t]*)body([ \t]*)'
                        '([a-zA-Z0-9_.]+)(.*)', re.IGNORECASE | re.DOTALL)
                    match = re.search(pattern, prev_line)
                    result = match.group(4)
                    break

        going_up = attempt_up()
    GPS.Editor.cursor_set_position(current_file, original_line_num,
                                   original_column_num)
    return identifier_case(result)