Example #1
0
def get_current_regex_position_and_length():
    current_line = editor2.lineFromPosition(editor2.getCurrentPos())
    if current_line != 0 and not editor2.getLine(current_line).startswith(COMMENT_CHAR):
        lenght_line = editor2.lineLength(current_line)
        position = editor2.positionFromLine(current_line)
        return position, lenght_line
    return None, None
Example #2
0
def get_regex_flags():
    global TIME_REGEX
    global USE_PYTHON_ENGINE
    global REPORT_MATCHES
    TIME_REGEX = False
    USE_PYTHON_ENGINE = False
    REPORT_MATCHES = False

    flags = 0
    flag_line = editor2.getLine(0)
    for char in range(flag_line.find('[')+1,flag_line.find(']')):
        if flag_line[char].upper() == 'I':
            flags |= re.IGNORECASE
        elif flag_line[char].upper() == 'L':
            flags |= re.LOCALE
        elif flag_line[char].upper() == 'M':
            flags |= re.MULTILINE
        elif flag_line[char].upper() == 'S':
            flags |= re.DOTALL
        elif flag_line[char].upper() == 'U':
            flags |= re.UNICODE
        elif flag_line[char].upper() == 'X':
            flags |= re.VERBOSE

        elif flag_line[char].upper() == 'T':
            TIME_REGEX = True
        elif flag_line[char].upper() == 'P':
            USE_PYTHON_ENGINE = True
        elif flag_line[char].upper() == 'R':
            REPORT_MATCHES = True
    return flags
Example #3
0
def get_current_regex_position_and_length():
    current_line = editor2.lineFromPosition(editor2.getCurrentPos())
    if current_line != 0 and not editor2.getLine(current_line).startswith(COMMENT_CHAR):
        lenght_line = editor2.lineLength(current_line)
        position = editor2.positionFromLine(current_line)
        return position, lenght_line
    return None, None
Example #4
0
def get_regex_flags():
    global TIME_REGEX
    global USE_PYTHON_ENGINE
    global REPORT_MATCHES
    TIME_REGEX = False
    USE_PYTHON_ENGINE = False
    REPORT_MATCHES = False

    flags = 0
    flag_line = editor2.getLine(0)
    for char in range(flag_line.find('[')+1,flag_line.find(']')):
        if flag_line[char].upper() == 'I':
            flags |= re.IGNORECASE
        elif flag_line[char].upper() == 'L':
            flags |= re.LOCALE
        elif flag_line[char].upper() == 'M':
            flags |= re.MULTILINE
        elif flag_line[char].upper() == 'S':
            flags |= re.DOTALL
        elif flag_line[char].upper() == 'U':
            flags |= re.UNICODE
        elif flag_line[char].upper() == 'X':
            flags |= re.VERBOSE

        elif flag_line[char].upper() == 'T':
            TIME_REGEX = True
        elif flag_line[char].upper() == 'P':
            USE_PYTHON_ENGINE = True
        elif flag_line[char].upper() == 'R':
            REPORT_MATCHES = True
    return flags
Example #5
0
def start_regex_tester():
    if REGEX_TESTER_FILE_NAME == '':
        notepad.messageBox('You need to indicate, in the REGEX_TESTER_FILE_NAME variable,\n' +
                           'the fully qualified file name of the TEXT file containing ' +
                           'the REGEX(ES) to test', 'REGEX_TESTER_FILE_NAME is not set')
        return False

    current_document = 0 if notepad.getCurrentView() == 1 else notepad.getCurrentBufferID()

    global REGEX_TESTER_INPUT_TAB
    REGEX_TESTER_INPUT_TAB = regex_tester_doc_already_exists()
    if REGEX_TESTER_INPUT_TAB == 0 :
        notepad.open(REGEX_TESTER_FILE_NAME)
        if notepad.getCurrentFilename().upper() == REGEX_TESTER_FILE_NAME.upper():
            REGEX_TESTER_INPUT_TAB = notepad.getCurrentBufferID()
        else:
            notepad.messageBox('Could not open specified file\n' +
                               '{0}'.format(REGEX_TESTER_FILE_NAME),
                               'Regex Tester Startup Failed', 0)
            return False
    else:
        notepad.activateBufferID(REGEX_TESTER_INPUT_TAB)

    if notepad.getCurrentView() != 1:
        notepad.menuCommand(MENUCOMMAND.VIEW_GOTO_ANOTHER_VIEW)

    STATUS_LINE = 'RegexTester isActive [] flags:sitpr'

    current_status_line = editor2.getLine(0)
    if 'RegexTester' in current_status_line:
        editor2.replace('RegexTester inActive', 'RegexTester isActive')
    else:
        editor2.insertText(0, STATUS_LINE)


    global REGEX_TESTER_IS_RUNNING
    REGEX_TESTER_IS_RUNNING = True

    color_regex_tester_status()

    set_current_buffer_id()

    global PREVIOUS_REGEX
    PREVIOUS_REGEX[CURRENT_BUFFER_ID] = ''

    editor.callbackSync(regex_tester_updateui_callback, [SCINTILLANOTIFICATION.UPDATEUI])

    if current_document != 0:
        notepad.activateBufferID(current_document)

    editor2.setFocus(True)
    editor2.gotoLine(0)
    notepad.save()

    notepad.callback(regex_tester_file_before_close_callback, [NOTIFICATION.FILEBEFORECLOSE])
    notepad.callback(regex_tester_buffer_activated_callback, [NOTIFICATION.BUFFERACTIVATED])

    return True
Example #6
0
def start_regex_tester():
    if REGEX_TESTER_FILE_NAME == '':
        notepad.messageBox('You need to indicate, in the REGEX_TESTER_FILE_NAME variable,\n' +
                           'the fully qualified file name of the TEXT file containing ' +
                           'the REGEX(ES) to test', 'REGEX_TESTER_FILE_NAME is not set')
        return False

    current_document = 0 if notepad.getCurrentView() == 1 else notepad.getCurrentBufferID()

    global REGEX_TESTER_INPUT_TAB
    REGEX_TESTER_INPUT_TAB = regex_tester_doc_already_exists()
    if REGEX_TESTER_INPUT_TAB == 0 :
        notepad.open(REGEX_TESTER_FILE_NAME)
        if notepad.getCurrentFilename().upper() == REGEX_TESTER_FILE_NAME.upper():
            REGEX_TESTER_INPUT_TAB = notepad.getCurrentBufferID()
        else:
            notepad.messageBox('Could not open specified file\n' +
                               '{0}'.format(REGEX_TESTER_FILE_NAME),
                               'Regex Tester Startup Failed', 0)
            return False
    else:
        notepad.activateBufferID(REGEX_TESTER_INPUT_TAB)

    if notepad.getCurrentView() != 1:
        notepad.menuCommand(MENUCOMMAND.VIEW_GOTO_ANOTHER_VIEW)

    STATUS_LINE = 'RegexTester isActive [] flags:sitpr'

    current_status_line = editor2.getLine(0)
    if 'RegexTester' in current_status_line:
        editor2.replace('RegexTester inActive', 'RegexTester isActive')
    else:
        editor2.insertText(0, STATUS_LINE)


    global REGEX_TESTER_IS_RUNNING
    REGEX_TESTER_IS_RUNNING = True

    color_regex_tester_status()

    set_current_buffer_id()

    global PREVIOUS_REGEX
    PREVIOUS_REGEX[CURRENT_BUFFER_ID] = ''

    editor.callbackSync(regex_tester_updateui_callback, [SCINTILLANOTIFICATION.UPDATEUI])

    if current_document != 0:
        notepad.activateBufferID(current_document)

    editor2.setFocus(True)
    editor2.gotoLine(0)
    notepad.save()

    notepad.callback(regex_tester_file_before_close_callback, [NOTIFICATION.FILEBEFORECLOSE])
    notepad.callback(regex_tester_buffer_activated_callback, [NOTIFICATION.BUFFERACTIVATED])

    return True
Example #7
0
def color_regex_tester_status():
    status_line = editor2.getLine(0)
    if REGEX_TESTER_IS_RUNNING:
        start = status_line.find('[')
        stop = status_line.find(']')+1
        editor2.setIndicatorCurrent(13)
        editor2.indicatorFillRange(0,20)
        editor2.setIndicatorCurrent(13)
        editor2.indicatorFillRange(start,stop-start)
    else:
        editor2.setIndicatorCurrent(13)
        editor2.indicatorClearRange(0,len(status_line))
Example #8
0
def color_regex_tester_status():
    status_line = editor2.getLine(0)
    if REGEX_TESTER_IS_RUNNING:
        start = status_line.find('[')
        stop = status_line.find(']')+1
        editor2.setIndicatorCurrent(13)
        editor2.indicatorFillRange(0,20)
        editor2.setIndicatorCurrent(13)
        editor2.indicatorFillRange(start,stop-start)
    else:
        editor2.setIndicatorCurrent(13)
        editor2.indicatorClearRange(0,len(status_line))
Example #9
0
def regex():
    global PREVIOUS_REGEX
    global NO_MATCH_FOUND
    global MATCH_POSITIONS
    global IS_ODD

    IS_ODD = False
    MATCH_POSITIONS[CURRENT_BUFFER_ID] = []

    clear_indicator()
    pattern = ''

    if (editor2.getSelections() == 1) and (editor2.getSelectionEmpty() == False):
        start = editor2.lineFromPosition(editor2.getSelectionNStart(0))
        end = editor2.lineFromPosition(editor2.getSelectionNEnd(0))
        for i in range(start,end+1):
            pattern += editor2.getLine(i).rstrip('\r\n')
    else:
        pattern = current_regex()

    PREVIOUS_REGEX[CURRENT_BUFFER_ID] = pattern
    NO_MATCH_FOUND = True

    if (pattern != '' and
        pattern != '.' and
        pattern != '()' and not
        pattern.startswith(COMMENT_CHAR) and not
        pattern.isspace() and
        re.match('^\(\?[mis-]*\)$',pattern) is None and
        editor2.lineFromPosition(editor2.getCurrentPos()) > 0):

        regex_flag = get_regex_flags()

        if TIME_REGEX:
            if regex_exec(pattern,regex_flag):
                track_document()
            else:
                NO_MATCH_FOUND = None
        else:
            try:
                if USE_PYTHON_ENGINE:
                    map(match_found, re.finditer(pattern, editor1.getText(), regex_flag))
                else:
                    editor1.research(pattern, match_found, regex_flag)
                track_document()
            except Exception as e:
                console.write('Exception:{}\n'.format(e))
                NO_MATCH_FOUND = None

    else:
        NO_MATCH_FOUND = None
Example #10
0
def regex():
    global PREVIOUS_REGEX
    global NO_MATCH_FOUND
    global MATCH_POSITIONS
    global IS_ODD

    IS_ODD = False
    MATCH_POSITIONS[CURRENT_BUFFER_ID] = []

    clear_indicator()
    pattern = ''

    if (editor2.getSelections() == 1) and (editor2.getSelectionEmpty() == False):
        start = editor2.lineFromPosition(editor2.getSelectionNStart(0))
        end = editor2.lineFromPosition(editor2.getSelectionNEnd(0))
        for i in range(start,end+1):
            pattern += editor2.getLine(i).rstrip('\r\n')
    else:
        pattern = current_regex()

    PREVIOUS_REGEX[CURRENT_BUFFER_ID] = pattern
    NO_MATCH_FOUND = True

    if (pattern != '' and
        pattern != '.' and
        pattern != '()' and not
        pattern.startswith(COMMENT_CHAR) and not
        pattern.isspace() and
        re.match('^\(\?[mis-]*\)$',pattern) is None and
        editor2.lineFromPosition(editor2.getCurrentPos()) > 0):

        regex_flag = get_regex_flags()

        if TIME_REGEX:
            if regex_exec(pattern,regex_flag):
                track_document()
            else:
                NO_MATCH_FOUND = None
        else:
            try:
                if USE_PYTHON_ENGINE:
                    map(match_found, re.finditer(pattern, editor1.getText(), regex_flag))
                else:
                    editor1.research(pattern, match_found, regex_flag)
                track_document()
            except Exception as e:
                console.write('Exception:{}\n'.format(e))
                NO_MATCH_FOUND = None

    else:
        NO_MATCH_FOUND = None