Regex help needed editing the function list xml file
-
I am trying to edit the Notepad++ xml file to display a Javascript “class” (prototype functions) hierarchy as nodes and have (preferably) the public methods nested underneath and the private methods also displayed in the tree
The objective is to have it recognize a coding convention that looks like:
function TypeMyClass () { Private properties var a; var b; //Public properties this.c; this.d; //Private methods var Init = function () { //... Do something ... } //Public methods this.GetVarA = function () { return a; } //Initialization Init (); }
This is what I have so far, but I am getting nothing:
<parser id="js_function" displayName="Javascript" commentExpr="((/\*.*?\*)/|(//.*?$))" > <!--parser: sniff comment lines; either /*blah*/ or // blah --> <classRange mainExpr="^[\s]*function([\s]+[_A-Za-z]?[\w_]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{" openSymbole = "\{" closeSymbole = "\}" displayMode = "node" > <className> <nameExpr expr="[_A-Za-z]?[\w_]*[\s]*\("/> <!--Narrow down from mainExpr towards the class names--> <nameExpr expr="[_A-Za-z]?[\w_]"/> <!--Narrow down to the name itself --> </className> <function mainExpr="(var/let|(this+[.]))+[\s]*[_A-Za-z][\w_]*[\s]*[=]+[\s]*[_A-Za-z][\w_]*[\s]*\(" displayMode="$functionName"> <!--function: is used to find the method definitions --> <functionName> <nameExpr expr="[_A-Za-z][\w_]*[\s]*[=]+[\s]*[_A-Za-z]?[\w_]*[\s]*\("/> <!--Narrow down the mainExpr--> <nameExpr expr="[_A-Za-z][\w_]*[\s]*[=]"/> <!--Narrow further down to the name itself --> </functionName> </function> </classRange> </parser>
-
try this one
<!-- ========================================================= [ JS FPS ] --> <parser displayName="Javascript" id="js_function" commentExpr="(?s:/\*.*?\*/)|(?m-s://.*?$)" > <function mainExpr="((^|\s+|[;\}\.])([A-Za-z_]\w*\.)*[A-Za-z_]\w*\s*[=:]|^|[\s;\}]+)\s*function(\s+[A-Za-z_]?\w*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{" > <functionName> <nameExpr expr="[A-Za-z_]\w*\s*[=:]|[A-Za-z_]?\w*\s*\(" /> <nameExpr expr="[A-Za-z_]?\w*" /> </functionName> <className> <nameExpr expr="([A-Za-z_]\w*\.)*[A-Za-z_]\w*\." /> <nameExpr expr="([A-Za-z_]\w*\.)*[A-Za-z_]\w*" /> </className> </function> </parser>
-
@Florent-Pagès as available in Notepad++ v7.3.2.0 which was enhanced in v7.5.1.0 i.e. allowing
$
in identifiers and whitespace before the left/open parenthesis.