FunctionList classrange question
-
Hi,
I am trying to include <classrange> tag for the BaanC language to the functionlist.xml
The sample BaanC code looks like below.declaration: func2(10.09, "STR") before.program: func1(10) functions: function func1(long var1) { | Do Something 1. } function string func2( double var2, string var2_1 ) { | Do Something 2. }
The expected result in the function list for the above code is as shown
+FileName +--declaration: | +--before.program: | +--functions: | +--func1 | +--func2
The original <function> tag was given by @MAPJe71
The <classrange> tag what I am trying is attached below.
Is the above format acheievable?<!-- ======================================================= [ BaanC ] --> <parser displayName="BaanC" id ="baanc_function" commentExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?m-s:\x7C.*$) # Single Line Comment " > <function mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks ^\h* # optional leading whitespace at start-of-line (?i:function)\s+ (?:extern\s+)? (?:(?:boolean|double|long|string|void|domain\s+[A-Za-z_]\w*)\s+)? \K \w+(?:\s*\.\s*\w+)* \s*\( " > <functionName> <nameExpr expr="\w+(?:\s*\.\s*\w+)*" /> </functionName> </function> <classRange mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks ^\h* # optional leading whitespace at start-of-line \K \b(?i: # keywords (case-insensitive) before\.program | declaration | functions \b) : " > <className> <nameExpr expr="(?i:\w+\.)?\w+" /> </className> </classRange> </parser> <!-- ================================================================= -->
-
Questions:
- Are the “before.program”, “declaration” and “functions” sections always in the same order in a file?
- Are all sections always present?
It would be very helpfull if you could provide a grammar (e.g. BNF) for BaanC.
-
@MAPJe71
There is not a definite sequence, for the before.program: / declaration: / functions:.
Infact, these are called sections in BaanC and there are a lot of other sections involved (at least 60+ sections).
I have just kept three to keep it simple as the regex might look weird after adding the 60+ sections.
Only convention is (not a pre-requiste) , the functions section come at the last.Also, not all the sections need to be present all the time. Only the sections which are required for the flow are developed. Which are of not interest can be left without coding.
As far the BNF, i have searched and none exists for BaanC. I will check if it exists or if I can describe on my own as BNF.
Regards,
-
@oirfeodent Try this one:
<parser displayName="BaanC Sections" id ="baanc_section" > <classRange mainExpr ="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks (?'SECTION' ^\h* # optional leading whitespace at start-of-line (?: # section keywords before\s*\.\s*program | declaration | functions ) \s*: # end-of-section-header ) (?s: .*? # whatever, (?=(?&SECTION)|\Z) # ...up till next section or end-of-text ) " > <className> <nameExpr expr="\w+(?:\s*\.\s*\w+)*(?=\s*:)" /> </className> <function mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks ^\h* # optional leading whitespace at start-of-line (?: # prefix for function definitions function\s+ (?:extern\s+)? (?:(?:boolean|double|long|string|void|domain\s+[A-Za-z_]\w*)\s+)? )? \K # discard text matched so far \w+(?:\s*\.\s*\w+)* \s*\( " > <functionName> <funcNameExpr expr="\w+(?:\s*\.\s*\w+)*" /> </functionName> </function> </classRange> </parser>
-
@MAPJe71
Thx for your time, checking this.
However the format, what I am trying to develop is different.
In the fix provided, the function list shows the SECTIONS and inside that the function names are shown.The PR #3702 which is currently open, is already listing the functions independently on the function List window.
The <classrange> tag should list all the SECTIONS including the “functions:” SECTION.
And the <function> tag inside the <classrange> should list the SUB-SECTIONS (if present).
The existing <function> tag from PR #3702 would co-exists togther with this.So, this will be a mixed parser.
I did not provide the details about the SUB-SECTIONS earlier… as, I intend to go step-by-step.
First <function> tag of PR #3702 and now, <classrange> tag for the SECTIONS.
And once it is done, work on the <function> tag inside <classrange> tag which would list the SUB-SECTIONS (if any).
This way, I would also learn <REGEX>. But, I have shown the example code below and the expected output.In short, the <classrange> tag does not need to worry about functions.
In the sample below, ‘+’ symbol means it gets expanded and ‘-’ symbol cant be expanded.
Hope this explanation is better.Sample code (SUB-SECTIONS included) shown below
-
Sample code
declaration: |This main section, does not have a sub section. func2(10.09, "STR") before.program: |This main section, does not have a sub section. func1(10) choice.test.123: |Has multiple subsections. 2 shown below. Regex to check this would be "choice\s*\.\s*[\w\s*\.\s*]+" before.choice: |This sub-section should be listed under choice.test.123: func1(20) after.choice: |This sub-section should be listed under choice.test.123: func2(20.09, "STR") field.field.123: |Has multiple subections. 1 shown below. Regex to check this would be "field\s*\.\s*[\w\s*\.\s*]+" on.input: |This sub-section should be listed under field.field.123: func1(30) functions: |Does not have a sub section (per se)... but, encloses a list of functions |which are called from other main/sub sections. function func1(long var1) |These are functions, which the existing PR #3702 would work. { | Do Something 1. } function string func2( double var2, string var2_1 ) { | Do Something 2. }
Expected output
+<filename.bc> -declaration: -before.program: +choice.test.123: -before.choice: -after.choice: +field.field.123: -on.input: -functions: -func1 -func2
If there is a possibility to fold, the “functions:” SECTION with all the functions from PR #3702.
If not the above option is also fine.+<filename.bc> -declaration: -before.program: +choice.test.123: -before.choice: -after.choice: +field.field.123: -on.input: +functions: -func1 -func2
-
@oirfeodent Please try the following parser.
<parser displayName="BaanC Sections v2" id ="baanc_section" > <classRange mainExpr ="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks (?'SECTION' ^\h* # optional leading whitespace at start-of-line (?: # known section names before\s*\.\s*program | (?:choice|field)(?:\s*\.\s*\w+)+ | declaration | functions ) \s*: # end-of-section-header indicator ) (?s:.*?) # whatever, up till (?=(?&SECTION)|\Z) # ...next section or end-of-text " > <className> <nameExpr expr="^\h*\K\w+(?:\s*\.\s*\w+)*(?=\s*:)" /> </className> <function mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks ^\h* # optional leading whitespace at start-of-line (?: \K # discard text matched so far \b(?!(?: # discard known section names before\s*\.\s*program | (?:choice|field)(?:\s*\.\s*\w+)+ | declaration | functions )\b) \w+(?:\s*\.\s*\w+)+ # sub-section name \s*: # end-of-sub-section-header indicator | function\s+ (?:extern\s+)? (?:(?:boolean|double|long|string|void|domain\s+[A-Za-z_]\w*)\s+)? \K # discard text matched so far \w+(?:\s*\.\s*\w+)* # function name \s*\( # end-of-function-header indicator ) " > <functionName> <funcNameExpr expr="\w+(?:\s*\.\s*\w+)*" /> </functionName> </function> </classRange> </parser>
REMARKS:
- Function List does NOT support sub-classes i.e. branches of branches;
- Function List does NOT show empty classes i.e.
<classRange>
with no match for its<function>
;
Result:
+--- filename.bc +--- choice.test.123 | +--- before.choice | \--- after.choice | +--- field.field.123 | \--- on.input | \--- functions +--- func1 \--- func2
-
Some additional info.
Function List parse steps:
- The
<parser>
“commentExpr”-attribute is used to find all the comment code blocks; - The
<classRange>
“mainExpr”-attribute is used to find all the class code blocks in the none-comment code blocks; - For each class code block found:
- The
<classRange><className><nameExpr>
“expr”-attribute is used to find the classes name; - The
<classRange><function>
“mainExpr”-attribute is used to find the method definitions; - For each method definition found within the class code block:
- The
<classRange><function><functionName><funcNameExpr>
“expr”-attribute is used to find the method’s name; - The method is added to the trunk of the tree as branch-leaf using class name and method name respectively;
- The
- The
- For each remaining code block i.e. neither being a comment nor a class code block:
- The
<function>
“mainExpr”-attribute is used to find the function and method definitions; - For each function/method definition:
- The
<function><functionName><nameExpr>
“expr”-attribute is used to find the function/method’s name; - The
<function><className>
“expr”-attribute is used to find the function/method’s class name; - The function/method is added to the trunk of the tree as:
- a branch-leaf using class name and method name respectively when a class name was found;
- a leaf using the function name when no a class name was found;
- The
- The
ExampleClass.hpp
class ExampleClass { void Method1(); void Method2() { return; } void Method3(); } void ExampleClass::Method1() { return; }
Collapsed:
class ExampleClass {\r\n void Method1();\r\n void Method2() {\r\n return;\r\n }\r\n void Method3();\r\n}\r\nvoid ExampleClass::Method1() {\r\n return;\r\n}\r\n |<-1------------------------------------------------------------------------------->| |<-2------------------------>| |<-3------>| |<-4---------->| |<-5------>| |<-6->| |<-7->|
Description for numbered code blocks:
- class definition to be matched by
<classRange>
“mainExpr”-attribute optionally combined with “openSymbol” and “closeSymbol”-attributes; - function definition to be matched by
<function>
“mainExpr”-attribute; - class name to be matched by
<classRange><className><nameExpr>
“expr”-attribute; - function definition to be matched by
<classRange><function>
“mainExpr”-attribute; - class name to be matched by
<function><className>
“expr”-attribute; - function name to be matched by
<function><functionName><nameExpr>
“expr”-attribute; - function name to be matched by
<classRange><function><functionName><funcNameExpr>
“expr”-attribute;
Result:
ExampleClass.hpp \--- ExampleClass +--- Method2 \--- Method1
Note:
When the list is unsorted Method2 is listed before Method1 as class code blocks are parsed before any remaining code blocksExampleClass.cpp
#include "ClassExample.h" void HelperFunction() { return; } void ExampleClass::Method3() { return; }
Collapsed:
#include "ClassExample.h"\r\nvoid HelperFunction() {\r\n return;\r\n}\r\nvoid ExampleClass::Method3() {\r\n return;\r\n}\r\n |<-1----------------->| |<-2------------------------>| |<-3-------->| |<-4------>| |<-5->|
Description for numbered code blocks:
- function definition to be matched by
<function>
“mainExpr”-attribute; - function definition to be matched by
<function>
“mainExpr”-attribute; - function name to be matched by
<function><functionName><nameExpr>
“expr”-attribute; - class name to be matched by
<function><className>
“expr”-attribute; - function name to be matched by
<function><functionName><nameExpr>
“expr”-attribute;
Result:
ExampleClass.hpp +--- ExampleClass | \--- Method3 | \--- HelperFunction
- The
-
That last result should have read
ExampleClass.cpp
as root label. -
@MAPJe71
The parser did not show me the “functions” section and the related functions for me.
Only showed the following.+--- filename.bc +--- choice.test.123 | +--- before.choice | \--- after.choice | +--- field.field.123 \--- on.input
Not sure which part I am missing.
Reattaching the full <parser> tag what I picked from the above post.<parser displayName="BaanC" id ="baanc_function" commentExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?m-s:\x7C.*$) # Single Line Comment " > <classRange mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks (?'SECTION' ^\h* # optional leading whitespace at start-of-line (?: # known section names before\s*\.\s*program | (?:choice|field)(?:\s*\.\s*\w+)+ | declaration | functions ) \s*: # end-of-section-header indicator ) (?s:.*?) # whatever, up till (?=(?&SECTION)|\Z) # ...next section or end-of-text " > <className> <nameExpr expr="^\h*\K\w+(?:\s*\.\s*\w+)*(?=\s*:)" /> </className> <function mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks ^\h* # optional leading whitespace at start-of-line (?: \K # discard text matched so far \b(?!(?: # discard known section names before\s*\.\s*program | (?:choice|field)(?:\s*\.\s*\w+)+ | declaration | functions )\b) \w+(?:\s*\.\s*\w+)+ # sub-section name \s*: # end-of-sub-section-header indicator | function\s+ (?:extern\s+)? (?:(?:boolean|double|long|string|void|domain\s+[A-Za-z_]\w*)\s+)? \K # discard text matched so far \w+(?:\s*\.\s*\w+)* # function name \s*\( # end-of-function-header indicator ) " > <functionName> <funcNameExpr expr="\w+(?:\s*\.\s*\w+)*" /> </functionName> </function> </classRange> </parser>
am I missing something?
-
@oirfeodent Make sure there’s an empty line at the end of the
.bc
file. -
@MAPJe71
Still no luck, after adding the last empty line. -
-
ok, let me check if I have missed something.
Probably do a fresh install of NPP.Regards,
-
@MAPJe71
Removing the “commentExpr” attribute from the <parser> worked. Thx.I have started building the regex to add the other sections and have an additional question.
For instance, in the <classrange> known section names, if I want to check “before.<anyname>:” main section but should not check “before.choice:|before.checks:” sub section… can it be acheived?I tried with
| (?:before\.[^checks|choice|delete|display|field|form|group|input|layout|print|read|rewrite|write|zoom|display\.object|new\.object|program])(?:(?:\.)*\w+)+
This doesn’t seem to work. I also tried to create negative look ahead but failed.
Let me know if you have some suggestions.Regards,
-
@oirfeodent
Do you mean something like| before(?:\s*\.\s*(?!checks|choice|delete|display|field|form|group|input|layout|print|read|rewrite|write|zoom|display\.object|new\.object|program)\w+)+
-
@MAPJe71
The above is close to expected output.
In the sample file below, the “before.program:” main section gets listed as the sub section of “choice.test.123:” main section.
Sample file:choice.test.123: before.choice: funct1(10) on.choice: funct1(10) before.program: set.synchronized.dialog("fxinh0123s000") functions: function func1(long var1) { | Do Something 1. }
The expected output is
+--- filename.bc +--- choice.test.123: | +--- before.choice | \--- on.choice | \--- functions: \--- func1
But the “before.program:” also gets listed under “choice.test.123:” for the below <classrange> tag.
<classRange mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks (?'SECTION' ^\h* # optional leading whitespace at start-of-line (?: # known section names after\.(?:(?!choice:|delete:|display:|field:|form\.read:|form:|group:|input:|layout:|program:|read:|receive\.data:|rewrite:|skip\.delete:|skip\.rewrite:|skip\.write:|update\.db\.commit:|write:|zoom:)(?:\.)*\w+)+ | before\.(?:(?!checks:|choice:|delete:|display:|field:|form:|group:|input:|layout:|print:|read:|rewrite:|write:|zoom:|display\.object:|new\.object:|program:)(?:\.)*\w+)+ | (?:choice\.|field\.|zoom\.from\.)(?:(?:\.)*\w+)+ | (?:detail\.|footer\.|form\.|group\.|header\.)(?:\d+)+ | functions | main\.table\.io ) : # end-of-section-header indicator ) (?s:.*?) # whatever, up till (?=(?&SECTION)|\Z) # ...next section or end-of-text " > <className> <nameExpr expr="^\h*\K\w+(?:\.\w+)*:" /> </className> <function mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?im) # case-insensitive, ^ and $ match at line breaks ^\h* # optional leading whitespace at start-of-line (?: \K # discard text matched so far \b(?!(?: # discard known section names after\.(?:(?!choice:|delete:|display:|field:|form\.read:|form:|group:|input:|layout:|program:|read:|receive\.data:|rewrite:|skip\.delete:|skip\.rewrite:|skip\.write:|update\.db\.commit:|write:|zoom:)(?:\.)*\w+)+ | before\.(?:(?!checks:|choice:|delete:|display:|field:|form:|group:|input:|layout:|print:|read:|rewrite:|write:|zoom:|display\.object:|new\.object:|program)(?:\.)*\w+)+ | (?:choice\.|field\.|zoom\.from\.)(?:(?:\.)*\w+)+ | (?:detail\.|footer\.|form\.|group\.|header\.)(?:\d+)+ | functions | main\.table\.io )\b) \w+(?:\s*\.\s*\w+)+ # sub-section name : # end-of-sub-section-header indicator | function\s+ \K # discard text matched so far (?:extern\s+)? (?:(?:boolean|double|long|string|void|domain\s+[A-Za-z_]\w*)\s+)? \w+(?:\s*\.\s*\w+)* # function name \s*\( # end-of-function-header indicator ) " > <functionName> <funcNameExpr expr="(?:extern\s+)?(?:(?:boolean|double|long|string|void|domain\s+[A-Za-z_]\w*)\s+)?\w+(?:\s*\.\s*\w+)*" /> </functionName> </function> </classRange>
Adding/removing the ‘:’ to the negative look ahead provides the same results.
Any possibilities?Regards,
-
@oirfeodent Could you provide a complete list of:
- valid section names i.e. invalid sub-sections names;
- valid sub-section names i.e. invalid section names.
-
Main Sections Sub Sections after.<charsDigitsPeriods>.<digitsOnly>: after.choice: after.form.read: after.delete: after.program: after.display: after.receive.data: after.field: after.report.<digitsOnly>: after.form: after.update.db.commit: after.group: before.<charsDigitsPeriods>.<digitsOnly>: after.input: before.display.object: after.layout: before.new.object: after.read: before.program: after.rewrite: before.report.<digitsOnly>: after.skip.delete: choice.<charsDigitsPeriods>: after.skip.rewrite: declaration: after.skip.write: detail.<digitsOnly>: after.write: field.<charsDigitsPeriods>: after.zoom: field.all: before.checks: field.other: before.choice: footer.<digitsOnly>: before.delete: form.<digitsOnly>: before.display: form.all: before.field: form.other: before.form: functions: before.group: group.<digitsOnly>: before.input: header.<digitsOnly>: before.layout: main.table.io: before.print: on.display.total.line: before.read: on.error: before.rewrite: zoom.from.<charsDigitsPeriods>: before.write: zoom.from.all: before.zoom: zoom.from.other: check.input: domain.error: init.field: init.form: init.group: on.choice: on.entry: on.exit: on.input: read.view: ref.display: ref.input: selection.filter: when.field.changes: -
List of Main Sections:
Main Sections Has SubSections? after.<charsDigitsPeriods>.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections after.form.read: No Subsection after.program: No Subsection after.receive.data: No Subsection after.report.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections after.update.db.commit: No Subsection before.<charsDigitsPeriods>.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections before.display.object: No Subsection before.new.object: No Subsection before.program: No Subsection before.report.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections choice.<charsDigitsPeriods>: Atlease one Sub-Section, can have multiple SubSections declaration: No Subsection detail.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections field.<charsDigitsPeriods>: Atlease one Sub-Section, can have multiple SubSections field.all: Atlease one Sub-Section, can have multiple SubSections field.other: Atlease one Sub-Section, can have multiple SubSections footer.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections form.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections form.all: Atlease one Sub-Section, can have multiple SubSections form.other: Atlease one Sub-Section, can have multiple SubSections functions: No Subsection, but functions are present group.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections header.<digitsOnly>: Atlease one Sub-Section, can have multiple SubSections main.table.io: Atlease one Sub-Section, can have multiple SubSections on.display.total.line: No Subsection on.error: No Subsection zoom.from.<charsDigitsPeriods>: Atlease one Sub-Section, can have multiple SubSections zoom.from.all: Atlease one Sub-Section, can have multiple SubSections zoom.from.other: Atlease one Sub-Section, can have multiple SubSections List of Sub Sections
Sub Sections after.choice: after.delete: after.display: after.field: after.form: after.group: after.input: after.layout: after.read: after.rewrite: after.skip.delete: after.skip.rewrite: after.skip.write: after.write: after.zoom: before.checks: before.choice: before.delete: before.display: before.field: before.form: before.group: before.input: before.layout: before.print: before.read: before.rewrite: before.write: before.zoom: check.input: domain.error: init.field: init.form: init.group: on.choice: on.entry: on.exit: on.input: read.view: ref.display: ref.input: selection.filter: when.field.changes: