Function List able to show PHP Comments?
-
Hello,
I wondered if it would be possible to get the function list php.xml to show me
function name(){ }
AND comments like
### comment
in the functionlist.
Can I use the <classRange> for the comments, because I dont need the classes to be shown in the function list?
I tried the following, but it did not work:
<classRange mainExpr="###?[a-zA-Z0-9\xe4\xf6\xfc\xc4\xd6\xdc\xdf -]+"> <className> <nameExpr expr="[a-zA-Z0-9\xe4\xf6\xfc\xc4\xd6\xdc\xdf -]+" /> </className> </classRange>
Please help :-)
-
Please note: “class” in the FunctionList parser is only meant as a wrapper around functions. Any class that does not contain a function will not be displayed in the FunctionList panel.
You can actually define the main function expression as something akin
sub \w+|###.*
, and then have two<nameExpr>
elements inside. This isn’t tested, but the general idea is:<functionName mainExpr="sub \w+.*|^###.*"> <nameExpr expr="sub \K\w+" /> <nameExpr expr="###.*?$" /> </functionName>
This allows you to have more than one distinct function, each of which has separate rules for what gets displayed. (For example, above, I stripped the
sub
out of the FunctionList display, but left the###
, so you could tell which were comments) -
@peterjones hello Peter, thank you for your post.
I did not get it work in the stanard php.xml
The mainExpr-Term is very very big.
Have I to add the “sub” before the regex and the “|” pipe means OR ?
:-) -
No offence, but if you don’t know that
|
means OR in regular expressions, you have some studying to do before you can be effective at manipulating Function List regex. The forum has a FAQ about regular expressions, and the online User Manual (npp-user-manual.org, linked to in the ? menu in Notepad++) has a large page on regular expressions.Unfortunately, I am swamped right now, so cannot do more than point you to that documentation. Maybe another regex guru with more time will be able to hand you a working expression that takes the existing php function list and adds the ability to list ### comments as functions as well in the next couple days…
-
@peterjones said in Function List able to show PHP Comments?:
@stephan-romhart ,
No offence, but if you don’t know that | means OR in regular expressions, you have some studying to do before you can be effective at manipulating Function List regex. The forum has a FAQ about regular expressions, and the online User Manual (npp-user-manual.org, linked to in the ? menu in Notepad++) has a large page on regular expressions.
Unfortunately, I am swamped right now, so cannot do more than point you to that documentation. Maybe another regex guru with more time will be able to hand you a working expression that takes the existing php function list and adds the ability to list ### comments as functions as well in the next couple days…thanks my issue has been fixed.
-
@peterjones Thank you :-)
-
Sorry could not log in with my twitter…
Probably somebody could help me?
I still try to getfunction name(){ }
and
### comment
shown in the function list.
My current code:
<functionName mainExpr="function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|^###.*"> <nameExpr expr="[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{" /> <nameExpr expr="###.*?$" /> </functionName>
How can I tell the function list to use first nameExpr for left side of the “or” regex and last nameExpr for the right side?
-
Sorry could not log in with my twitter…
Yeah, it appears Twitter stopped providing OAuth some time ago (Feb 9)
How can I tell the function list to use first nameExpr for left side of the “or” regex and last nameExpr for the right side?
My experiments today could not get anything to work when I have two separate
<nameExpr>
tags. I thought it used to (and that’s what I have documented), but I couldn’t get that to work; maybe @MAPJe71 can chime in whether or not it’s really expected to work with multiple<nameExpr>
tags (and if not, I need to fix the documentation).For a simple example, I made one that looked for either
function
or###
and grabbed that and everything after it on the line, using a single expression rather than trying two – it is just a simple Function Parser, not a Class Parser or Mixed Parser.One thing I found while doing that: the functionList parser appears to have a problem with the
#
in the expression unless I manually turn off extended mode(?-x)
; I thought it used to be the other way around, but maybe something changed. (My advice when doing functionList definitions is to always be explicit about your desires for at least thes
(. matches newline) andx
(extended spaces and comments) options by using the(?...-...)
syntax.
text to grab functions fromthis is text ### comment #sub here sub one function xyz this is text function pdq this is text ### comment sub two #sub there function name(){ }
parser.xml
<?xml version="1.0" encoding="UTF-8"?> <NotepadPlus> <functionList> <parser id="fn_normal" displayName="Normal (plain text)" > <function mainExpr="(?-sx)^\h*\bfunction.*$|^###.*$" > <functionName> <nameExpr expr="(?-sx)^\h*\K\bfunction.*$|^###.*$" /> </functionName> </function> </parser> </functionList> </NotepadPlus>
Once you get something simple like that working, then slowly add back in the added complexities, it might work for you.
BTW: I tried your mainExpr value in just a Notepad++ FIND-dialog regex search, and it found things okay, but it claimed your first expr was not a valid regex – I don’t know whether you really had backslash-bracket in your expression someplace, which the forum messes up, or whether you have a bad regex there. But if a regex doesn’t work in Notepad++'s find dialog, it won’t work in your functionList definition, either.
I went back to your mainExpr, duplicated that as the Expr, and then tweaked it until it stripped the
function
prefix<?xml version="1.0" encoding="UTF-8"?> <NotepadPlus> <functionList> <parser id="fn_normal" displayName="Normal (plain text)" > <function mainExpr="(?-sx)function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|^###.*" > <functionName> <nameExpr expr="(?-sx)function(\s+\K[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|^###.*" /> </functionName> </function> </parser> </functionList> </NotepadPlus>
And it now restricts it to the
name(){
rather than my two dummy functions which don’t match your definitions:
Similar regex should work in the function-section of a Class or Mixed parser, too, but you’ll have to make sure to use the right element names (the elements inside a
<classRange><function>
are different than the elements inside a top-level<function>
element). -
@PeterJones Thank you very much! It works perfectly.
<function mainExpr="(?-sx)function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx)###.*"> <functionName> <nameExpr expr="(?-sx)function(\s+\K[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx).*" /> </functionName> </function>
I changed the ^ to (?-sx), so comments can be indented.
The question is, how can I strip the ### in the function list?
I did not understand how to remove some string with the expr.Is this done through groups with ()?
If so how can I adress them in the nameExpr? -
@Stephan-Romhart-0 I found it out!
With \K as Meta Escape:\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match.
<function mainExpr="(?-sx)function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx)###.*"> <functionName> <nameExpr expr="(?-sx)function(\s+\K[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx)###\K.*" /> </functionName> </function>
So my Functionlist shows now alle PHP functions and all Comments!
Thank you again, Peter! -
The result of a
<nameExpr .. />
is the input for the next<nameExpr ... />
i.e. they work in series, not parallel. -
@MAPJe71 Thank you!