#564 Update for perl's mainExpr in functionList.xml

Next_release
closed
nobody
None
5
2014-12-19
2014-02-19
James
No

I'm sorry this is not submitted in the form of an actual patch.

In the perl section of functionList.xml, which starts with line:

<parser id="perl_function" displayName="Perl">

Change the following line:

<function mainExpr="sub[\s]+[\w]+[\s]*\([^\)\(]*\)[\n\s]*\{" displayMode="$className->$functionName">

to:

<function mainExpr="^[\s]*(?<!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*\)?[\n\s]*\{" displayMode="$className->$functionName">

Ref: http://sourceforge.net/p/notepad-plus/feature-requests/2350/#58e5

Discussion

  • James

    James - 2014-02-19

    I'm sorry. I should mention that this fixes the function list for Perl so functions without a prototype (or empty parenthesis) will appear in the function list. It also hides functions that are commented out (works with EOL comments only).

     
  • Don HO

    Don HO - 2014-02-20

    Thank you for the contribution.

    Without knowing what you try to do, may I replace the begin occurrences:
    ^[\s](?<!#)
    by
    ^[\s]
    (?<#!)

    ?

     
  • James

    James - 2014-02-21

    Thank you very much for all of your work with Notepad++.

    The short answer: no. That should remain:

    ^[\s](?<!#)
    

    The long answer:

    The "(?<!" is a special regex notation for a negative lookbehind (zero-width, meaning the parenthesis do not capture any data). The parenthesis can capture data, but can also be used to group components of a regex. The ? right after the opening parenthesis tells the regex engine not to capture the text. The < after the ? tells the engine that this is a lookbehind. The ! after the ? tells the engine it is a negative (not). Lastly, the # is the part of the expression we are looking to not exist, which is the perl end-of-line comment character. If the ! and # characters are switched, it would then only match lines that contain "#!" followed by optional whitespace and then "sub" which would not give us the results we need.

    In this specific case, I am using this part of the regex that you asked about to cause the overall regex to only match lines that do not have a # before the "sub" text, so that commented-out (using #) functions are not pulled into function list. Please note that this regex does not ignore functions that are in block comments.

    I hope that explanation helps.

    If you are interested in learning more about "lookaround" regex, this page has a pretty good explanation:
    http://www.regular-expressions.info/lookaround.html

     
    • Don HO

      Don HO - 2014-02-26

      Thank you James for the explanation.
      It'll be in tne next release.

      Thank you for your patch,
      Don

       
  • Don HO

    Don HO - 2014-02-26
    • status: open --> accepted
     
  • Don HO

    Don HO - 2014-03-07
    • Status: accepted --> closed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks