From: Wyss Clemens Date: 2001-09-21T17:51:17+09:00 Subject: [ruby-talk:21482] Regexp hangs Good morning (evening to Matz and Co ;-)), Sorry for the long appendix. We have a regexp(in line 159) which seems to "hang", at least it takes a verrrry long time to match. To me it looks like this is a bug or a special case, which might need special hadling. The regexp tries to match function declarations. If we put the function name of the first function declaration also to the end (i.e. line 19 -> end H_LINT_2_UNSIGNED_INTEGER;) the regexp matches immediately. If the name is omitted (or wrong) it takes almost 2 minutes before the script terminates. And this time seems to increase exponentially depending on str's size. Also, when we remove the \1 in the regexp the "problem" disappears. A bug, or are making wrong use of regexps (maybe the \1)? Thanks for any feedback Clemens --------- appendix -------------------- #!/usr/bin/env ruby str = " function H_LINT_2_UNSIGNED_INTEGER (VALUE : in LONG_INTEGER) return UNSIGNED_INTEGER is CASTED_VAL : array [2] of UNSIGNED_INTEGER; TEMP : LONG_INTEGER; begin if (VALUE < 0) then CASTED_VAL[1] := 0; else if (VALUE > H#FFFF#) then CASTED_VAL[1] := H#FFFF#; else // Value is valid CASTED_VAL := BI.LINT_2_UINT (VALUE); end if; end if; return (CASTED_VAL[1]); end ddd ; // ^ the function name should be here! procedure GET_ALICE_LCL_STATUS ( P_LATCH : in INTEGER; P_ALICE_IS_ON : BOOLEAN; P_DP_READ_RESULT : BOOLEAN ) is LCL_STATUS : LONG_INTEGER; begin P_ALICE_IS_ON := FALSE; if (P_LATCH = K_PAR1_LCL_A) then // Get the state of LCL A DP.READ_SPECIFIC_BITS (PPK_NPWDA11D_ACCESS_DESC, LCL_STATUS, P_DP_READ_RESULT, PPK_NPWDA11D_MASK, INTEGER(PPK_NPWDA11D_SHIFT)); if (LCL_STATUS = PPK_NPWDA11D_ON) then // ALICE LCL A is ON P_ALICE_IS_ON := TRUE; end if; else // Get the value of LCL B DP.READ_SPECIFIC_BITS (PPK_NPWDA23D_ACCESS_DESC, LCL_STATUS, P_DP_READ_RESULT, PPK_NPWDA23D_MASK, INTEGER(PPK_NPWDA23D_SHIFT)); if (LCL_STATUS = PPK_NPWDA23D_ON) then // ALICE LCL B is ON P_ALICE_IS_ON := TRUE; end if; end if; end GET_ALICE_LCL_STATUS; function IS_PRECONDITION_VALID () return BOOLEAN is RET_VALUE : BOOLEAN; EVENT_RESULT : BOOLEAN; IS_LCL_ON : BOOLEAN; DP_READ_RESULT : BOOLEAN; begin RET_VALUE := TRUE; // Check if ALICE LCL A is OFF GET_ALICE_LCL_STATUS (K_PAR1_LCL_A, IS_LCL_ON, DP_READ_RESULT); if IS_LCL_ON then // ALICE LCL A is ON EVENT_RESULT := MSG.SEND_REPORT (K_EVENT_3 [0], K_EVENT_3 [1], K_EVENT_3 [2], K_EMPTY_EVENT_PARAM_LIST); RET_VALUE := FALSE; end if; if RET_VALUE then // Check if ALICE LCL B is OFF GET_ALICE_LCL_STATUS (K_PAR1_LCL_B, IS_LCL_ON, DP_READ_RESULT); if IS_LCL_ON then // ALICE LCL B is ON EVENT_RESULT := MSG.SEND_REPORT (K_EVENT_4 [0], K_EVENT_4 [1], K_EVENT_4 [2], K_EMPTY_EVENT_PARAM_LIST); RET_VALUE := FALSE; end if; end if; if (RET_VALUE) then // The preconditions are valid EVENT_RESULT := MSG.SEND_REPORT (K_EVENT_50 [0], K_EVENT_50 [1], K_EVENT_50 [2], K_EMPTY_EVENT_PARAM_LIST); end if; return (RET_VALUE); end IS_PRECONDITION_VALID; function IS_SWITCH_LCL_OFF_SUCCESSFUL ( P_LATCH : in INTEGER ) return BOOLEAN is RET_VALUE : BOOLEAN; TC_RESULT : BOOLEAN; IS_ALICE_ON : BOOLEAN; IS_CHECK_VALID : BOOLEAN; begin RET_VALUE := TRUE; // Switch ALICE LCL OFF if (P_LATCH = K_PAR1_LCL_A) then TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMA030SWOF_BUFFER); TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMB030SWOF_BUFFER); else TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMA287SWOF_BUFFER); TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMB287SWOF_BUFFER); end if; // Wait for the LCL reaction BI.WAIT_DELAY (K_TM_UPDATE_CYCLE_TIME); // Verify if ALICE LCL is off GET_ALICE_LCL_STATUS (P_LATCH, IS_ALICE_ON, IS_CHECK_VALID); if (IS_ALICE_ON) then RET_VALUE := FALSE; end if; return (RET_VALUE); end IS_SWITCH_LCL_OFF_SUCCESSFUL; function IS_SWITCH_LCL_OFF_SUCCESSFUL ( P_LATCH : in INTEGER ) return BOOLEAN is RET_VALUE : BOOLEAN; TC_RESULT : BOOLEAN; IS_ALICE_ON : BOOLEAN; IS_CHECK_VALID : BOOLEAN; begin RET_VALUE := TRUE; // Switch ALICE LCL OFF if (P_LATCH = K_PAR1_LCL_A) then TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMA030SWOF_BUFFER); TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMB030SWOF_BUFFER); else TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMA287SWOF_BUFFER); TC_RESULT := MSG.SEND_TC_AND_CONTINUE (PPK_TC_ZPWMB287SWOF_BUFFER); end if; // Wait for the LCL reaction BI.WAIT_DELAY (K_TM_UPDATE_CYCLE_TIME); // Verify if ALICE LCL is off GET_ALICE_LCL_STATUS (P_LATCH, IS_ALICE_ON, IS_CHECK_VALID); if (IS_ALICE_ON) then RET_VALUE := FALSE; end if; return (RET_VALUE); end IS_SWITCH_LCL_OFF_SUCCESSFUL; " # The ominous regexp ;-) str =~ /^function\s*(.*?)\s*[(](.*?)[)]\s*return\s*(.*?)\s*is\s*(.*?)begin\s*(.*?)e nd\s*\1\s*[;]/m