Á¤±Ô Ç¥Çö½Ä Callouts [AHK_L 14+]

¿ÜºÎÈ£Ãâ(Callouts)Àº Á¤±Ô Ç¥Çö½Ä ÀÏÄ¡ ÀÛ¾÷ Áß°£¿¡ Àӽ÷ΠÁ¦¾î¸¦ ½ºÅ©¸³Æ®¿¡ ³Ñ±â´Â ¼ö´ÜÀ» Á¦°øÇÕ´Ï´Ù. PCRE-Ç¥ÁØ callout Ư¡¿¡ °üÇÑ ´õ ÀÚ¼¼ÇÑ Á¤º¸´Â pcre.txt¸¦ ÂüÁ¶ÇϽʽÿÀ.

ÄݾƿôÀº ÇöÀç RegExMatch ±×¸®°í RegExReplace¸¸ Áö¿øÇÕ´Ï´Ù.

±¸¹®

¿ÀÅäÇÖÅ°¿¡¼­ callout ±¸¹®Àº (?CNumber:Function)ÀÔ´Ï´Ù. Number¿Í Function ¸ðµÎ ¼±ÅÃÀûÀÔ´Ï´Ù. ½ÖÁ¡ ':'Àº FunctionÀÌ ÁöÁ¤µÇ¾úÀ» °æ¿ì¿¡¸¸ Çã¿ëµË´Ï´Ù. Number¸¦ »ý·«ÇÏ¸é ¼±ÅÃÀûÀÔ´Ï´Ù. FunctionÀÌ ÁöÁ¤µÇ¾úÁö¸¸ »ç¿ëÀÚ-Á¤ÀÇ ÇÔ¼öÀÇ À̸§ÀÌ ¾Æ´Ï¸é, ÄÄÆÄÀÏ ¿¡·¯°¡ ÀϾ°í ÆÐÅÏ-ÀÏÄ¡°¡ ½ÃÀÛµÇÁö ¾Ê½À´Ï´Ù.

FunctionÀ» »ý·«Çϸé, ÇÔ¼ö À̸§À» ¹Ýµå½Ã pcre_calloutÀ̶ó´Â À̸§ÀÇ º¯¼ö¿¡ ÁöÁ¤ÇØ¾ß ÇÕ´Ï´Ù. ÀÌ À̸§À¸·Î Àü¿ª º¯¼ö¿Í Áö¿ª º¯¼ö°¡ ¸ðµÎ Á¸ÀçÇϸé, Áö¿ª º¯¼ö°¡ ¿ì¼± ¼øÀ§¸¦ °®½À´Ï´Ù. pcre_callout¿¡ »ç¿ëÀÚ-Á¤ÀÇ ÇÔ¼ö À̸§ÀÌ ¾øÀ¸¸é, FunctionÀÌ »ý·«µÈ ¿ÜºÎÈ£ÃâÀº ¹«½ÃµË´Ï´Ù.

Callout ÇÔ¼ö

Function(Match, CalloutNumber, FoundPos, Haystack, NeedleRegEx)
{
    ...
}

Callout ÇÔ¼ö´Â ¸Å°³º¯¼ö¸¦ ´Ù¼¸ °³±îÁö Á¤ÀÇÇÒ ¼ö ÀÖ½À´Ï´Ù:

ÀÌ À̸§µéÀº ±×³É Á¦½Ã ¿ëÀÏ »ÓÀÔ´Ï´Ù. ½ÇÁ¦ À̸§Àº ´Ù¸¦ ¼ö ÀÖ½À´Ï´Ù.

ÆÐÅÏ-ÀÏÄ¡´Â Äݾƿô ÇÔ¼öÀÇ °á°ú¿¡ µû¶ó °è¼Ó ÁøÇàµÇ°Å³ª ½ÇÆÐÇÕ´Ï´Ù:

¿¹¸¦ µé¾î:

Haystack = The quick brown fox jumps over the lazy dog.
RegExMatch(Haystack, "i)(The) (\w+)\b(?CCallout)")
Callout(m) {
    MsgBox m=%m%`nm1=%m1%`nm2=%m2%
    return 1
}

À§ÀÇ ¿¹Á¦¿¡¼­, Func´Â Äݾƿô ¾ÕÀÇ ÆÐÅÏ ÀϺο¡ ºÎÇÕÇÏ´Â ºÎ¹®ÀÚ¿­¸¶´Ù ÇÑ ¹ø¾¿ È£ÃâµË´Ï´Ù. \b´Â ºÎÇÕ¿¡¼­ ºÒ¿ÏÀüÇÑ ´Ü¾îµéÀ» ¹èÁ¦ÇÏ´Â µ¥ »ç¿ëµË´Ï´Ù. ¿¹¸¦ µé¾î The quic, The qui, The qu, µîµîÀº ´Ü¾î°¡ ¾Æ´Ï¹Ç·Î Á¦¿ÜµË´Ï´Ù.

EventInfo

A_EventInfo¸¦ ÅëÇÏ¿© pcre_callout_block ±¸Á¶Ã¼¿¡ Á¢±ÙÇϸé Ãß°¡ Á¤º¸¸¦ ¾òÀ» ¼ö ÀÖ½À´Ï´Ù .

version           := NumGet(A_EventInfo,  0, "Int")
callout_number    := NumGet(A_EventInfo,  4, "Int")
offset_vector     := NumGet(A_EventInfo,  8)
subject           := NumGet(A_EventInfo,  8 + A_PtrSize)
subject_length    := NumGet(A_EventInfo,  8 + A_PtrSize*2, "Int")
start_match       := NumGet(A_EventInfo, 12 + A_PtrSize*2, "Int")
current_position  := NumGet(A_EventInfo, 16 + A_PtrSize*2, "Int")
capture_top       := NumGet(A_EventInfo, 20 + A_PtrSize*2, "Int")
capture_last      := NumGet(A_EventInfo, 24 + A_PtrSize*2, "Int")
pad := A_PtrSize=8 ? 4 : 0  ; 64-ºñÆ® µ¥ÀÌÅÍ Á¤·ÄÀ» À§ÇÏ¿© º¸¿ÏÇÕ´Ï´Ù.
callout_data      := NumGet(A_EventInfo, 28 + pad + A_PtrSize*2)
pattern_position  := NumGet(A_EventInfo, 28 + pad + A_PtrSize*3, "Int")
next_item_length  := NumGet(A_EventInfo, 32 + pad + A_PtrSize*3, "Int")
if version >= 2
    mark   := StrGet(NumGet(A_EventInfo, 36 + pad + A_PtrSize*3, "Int"), "UTF-8")

´õ ÀÚ¼¼ÇÑ Á¤º¸´Â pcre.txt, NumGet ±×¸®°í A_PtrSize¸¦ ÂüÁ¶ÇϽʽÿÀ.

Auto-Callout

ÆÐÅÏÀÇ ¿É¼Ç¿¡ C¸¦ Æ÷ÇÔÇϸé auto-callout ¸ðµå°¡ ÄÑÁý´Ï´Ù. ÀÌ ¸ðµå¿¡¼­ (?C255)¿Í µ¿µîÇÑ ÄݾƿôÀÌ ÆÐÅÏÀÇ °¢ Ç׸ñ ¾Õ¿¡ »ðÀԵ˴ϴÙ. ¿¹¸¦ µé¾î, ´ÙÀ½ ÅÛÇø´À» »ç¿ëÇϸé Á¤±Ô Ç¥Çö½ÄÀ» µð¹ö±×ÇÒ ¼ö ÀÖ½À´Ï´Ù:

; ±âº» Äݾƿô ÇÔ¼ö¸¦ ¼³Á¤ÇÕ´Ï´Ù.
pcre_callout = DebugRegEx

; ÀÚµ¿-Äݾƿô ¿É¼Ç C¸¦ °¡Áö°í RegExMatch¸¦ È£ÃâÇÕ´Ï´Ù.
RegExMatch("xxxabc123xyz", "C)abc.*xyz")

DebugRegEx(Match, CalloutNumber, FoundPos, Haystack, NeedleRegEx)
{
    ; ´ÙÀ½ Çʵåµé¿¡ ´ëÇÑ ¼³¸íÀº pcre.txt¸¦ ÂüÁ¶ÇϽʽÿÀ.
    start_match       := NumGet(A_EventInfo, 12 + A_PtrSize*2, "Int")
    current_position  := NumGet(A_EventInfo, 16 + A_PtrSize*2, "Int")
    pad := A_PtrSize=8 ? 4 : 0
    pattern_position  := NumGet(A_EventInfo, 28 + pad + A_PtrSize*3, "Int")
    next_item_length  := NumGet(A_EventInfo, 32 + pad + A_PtrSize*3, "Int")

    ; ´ÙÀ½°ú °°ÀÌ Ç¥½Ã: >>ÇöÀç ºÎÇÕ<<.
    _HAYSTACK:=SubStr(Haystack, 1, start_match)
        . ">>" SubStr(Haystack, start_match + 1, current_position - start_match)
        . "<<" SubStr(Haystack, current_position + 1)
    
    ; ´ÙÀ½°ú °°ÀÌ Ç¥½Ã: >>Æò°¡µÉ ´ÙÀ½ Ç׸ñ<<.
    _NEEDLE:=  SubStr(NeedleRegEx, 1, pattern_position)
        . ">>" SubStr(NeedleRegEx, pattern_position + 1, next_item_length)
        . "<<" SubStr(NeedleRegEx, pattern_position + 1 + next_item_length)
    
    ListVars
    ; °è¼ÓÇÏ·Á¸é Pause¸¦ ´©¸£½Ê½Ã¿À.
    Pause
}

³íÆò

ÄݾƿôÀº ÇöÀçÀÇ ÀÇ»ç-¾²·¹µå¿¡¼­ ½ÇÇàµË´Ï´Ù. ±×·¯³ª Äݾƿô ÇÔ¼ö°¡ ¹ÝȯµÈ ÈÄ¿¡ A_EventInfoÀÇ ÀÌÀü °ªÀÌ º¹±¸µË´Ï´Ù. RegExMatch ¶Ç´Â RegExReplace°¡ µ¹¾Æ¿À±â ¹Ù·Î Àü±îÁö ErrorLevelÀº ¼³Á¤µÇÁö ¾Ê½À´Ï´Ù.

PCRE´Â ¾î¶² °æ¿ì¿¡ ºÎÇÕÀÌ ºÒ°¡´ÉÇÏ´Ù°í ÆǴܵǸé ÀÏÂï Ãë¼ÒµÇµµ·Ï ÃÖÀûÈ­µÇ¾î ÀÖ½À´Ï´Ù. ±×·± °æ¿ì¶ó¸é ¸ðµç Äݾƿô¿¡ ´ëÇÏ¿© ÀÌ·± ÃÖÀûÈ­¸¦ ²ø ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù. ÆÐÅÏÀÇ Ã³À½¿¡ (*NO_START_OPT) ¸¦ ÁöÁ¤ÇÏ¸é µË´Ï´Ù. ÀÌ ±â´ÉÀº v1.1.05 ÀÌ»óÀ» ¿ä±¸ÇÕ´Ï´Ù.