Help Adding Pascal to Function List
-
I may have missed some obvious constructions, which must be seen in the
Fucntion List
window. Just tell me about it ?After transforming your sample into a valid source file [^1], it seems your parser has lost the ability to find nested procedures.
@dinkumoil’s (corrected) parser finds them, at the expense of also detecting the commented-out ones (i.e., the ones “nested” within block comments.)
As written, the rule is satisfied anytime the first alphabetic sequence in any line happens to be an implementation keyword. The only time the rule fails is when a comment marker is directly followed by an implementation keyword.
There needs to be an expression that can check the previous line for the start of a block comment. Unfortunately, look-behind expressions are explicitly not allowed by the function parser specification.
Even without testing, I’m confident this is reproducible in other languages with function parsers. It’s just a fundamental limitation of the specification.
[^1]:
Unit Guy; {$IFDEF FPC} // Free Pascal {$mode objfpc} {$endif} Interface {$IFDEF DCC} // Delphi uses Winapi.Windows; // DWORD {$endif} Procedure Dummy ( const bla); function Test(Tnum:Double): DWord; function Bar(const AParam: string): integer; procedure Foo(AParam: integer); procedure Boo(AParam: integer); Implementation Procedure Dummy ( const bla); begin end; { This is a small test } function Bar(const AParam: string): integer; begin Result := -1; end; procedure Foo(AParam: integer); begin end; { This is a (* small test procedure Foo(AParam: integer); function Bar(const AParam: string): integer; function Test(Tnum:Double): DWord; procedure Boo(AParam: integer); to see if *) all is OK } function Test(Tnum:Double): DWord; begin Result := 0; end; procedure Boo(AParam: integer); procedure Guy; // locally defined procedure begin end; begin end; (* This is a { small test procedure Foo(AParam: integer); function Bar(const AParam: string): integer; function Test(Tnum:Double): DWord; procedure Boo(AParam: integer); to verify if} all is OK *) end.
-
I can confirm that the new version of my parser causes commented-out procedures/functions to be part of the function list.
There needs to be an expression that can check the previous line for the start of a block comment.
The core problem seems to be how matching and processing block comments is realized in the related C++ code that fills the function list panel. There is a special section in the XML file of function list parsers to define line and block comments. I expect that code, that is recognized as commented-out by the regexes in this section, is not parsed anymore by the regex that identifies procedure/function implementations. But that’s obviously not the case and I’m wondering what’s the sense of the comment-definition section in the parser file, respectively how it is processed.
Maybe the same behaviour of the C++ code that fills the function list panel is the cause that I was not able to define everything between the
interface
andimplementation
keywords as a comment. I used a similar expression like @guy038 (i.e.(?is:^\h* Interface.*?^\h*Implementation\s*)
) but it didn’t work, it was just ignored. Trying this regex in the normal search-and-replace dialog of Notepad++ gave the expected result but in function list parser I had duplicate entries for procedure/function declarations.Maybe someone with C++ knowledge (maybe @rdipardo ?) should have a look at the function list code to check how it processes the regexes from the parser file.
-
Hi, @james-richters, @rdipardo, @peterjones, @michael-vincent, @dinkumoil and All,
Yes, of course: my test and parser examples were deliberately sketchy to only highlight that the declarations in the [Interface - Implementation] range were correctly ignored, as well as all text in comments
@dinkumoil, I also consulted your new Pascal parser and indeed, I am far from matching you on this point !
@dinkumoil, you said :
… I was not able to define everything between the interface and implementation keywords as a comment. I used a similar expression like @guy038 (i.e. (?is:^\h* Interface.?^\hImplementation\s*)) but it didn’t work, it was just ignored.
But, obviously, my simple example shows that it seems to work ?! So, @dinkumoil, @rdipardo, can you enlighten me on this apparent contradiction ?
Please, do not spend too much time on this : I’ll take your word for it !
Best Regards,
guy038
-
@guy038 said in Help Adding Pascal to Function List:
can you enlighten me on this apparent contradiction ?
When I remove the class parser part of my mixed parser (i.e. the whole
classRange
XML node) I’m able to define everything between theinterface
andimplementation
keywords as a comment.So, again it seems necessary to analyse the C++ code that processes function list parser files and fills the tree in function list panel.
But maybe you @guy038 are lucky and can find content for the class parser part that doesn’t cause the comment expression to fail. I already tried to use empty regexes in the class parser, that failed too. Seems like the simple presence of a class parser part is the root cause.
-
-
Meanwhile a fix has been applied to the source code of Notepad++ that allows your fix (to define source code between the
interface
andimplementation
keywords as a multi-line comment) to work reliably if it is used in a mixed function list parser. You can download a preview version (including that fix) of Notepad++ 32 bit >>from here<< and the 64 bit version >>from here<<.Additionally, some fixes have applied to my Pascal/Delphi function list parser (including your fix to define source code between the
interface
andimplementation
keywords as a multi-line comment). You can download it >>from here<<.So, we Delphi developers should have a working solution.
-
@James-Richters said in Help Adding Pascal to Function List:
I am trying to figure out how to add Pascal to the Function List feature.
There are two issues I’m having difficulty figuring out.
The first one is that Pascal has Functions and Procedures, Functions return something, Procedures do not… as far as the Function List is concerned, they are both the same. I can’t figure out how to get both “Function” and “Procedure” to show up in the list.
I can’t paste it as code here because it’s just a giant unreadable mess, but here is a screen shot of what I am trying to do:
I don’t know anything at all about Regex Expressions, but I tried an OR function in an on-line Regex helper and (?i:PROCEDURE\s+)|(?i:FUNCTION\s+) should get a hit on both Procedure and Function… but it doesn’t work, I only get whatever I put there first.
The second thing I’m not sure how to do is eliminate the duplicates caused by the declaration in a Unit. everything between
Interface
And
Implementation
should be ignored, as those are not the actual functions and procedures, they are just a declaration of them.Here’s the code just in case it looks better after I post it:
<association id= "pascal_function" langID="11" /> <!-- ===================================================== [ Pascal ] --> <parser displayName="Pascal" id ="pascal_function" commentExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) (?is:\x23cs.*?\x23ce) # Multi Line Comment | (?m-s:^\h*;.*?$) # Single Line Comment " > <function mainExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) (?m)^\h* # optional leading whitespace (?i:PROCEDURE|FUNCTION\s+) # start-of-function indicator \K # keep the text matched so far, out of the overall match [A-Za-z_]\w* # valid character combination for identifiers (?:\s*\([^)]*?\))? # parentheses and parameters optional " > <!-- comment out the following node to display the function with its parameters --> <functionName> <nameExpr expr="[A-Za-z_]\w*" /> </functionName> </function> </parser> <!-- ================================================================= -->
I also face this problem.
-
@menit-lop ,
You might want to read the documents a little better. If you’re going to have multiple possibilities in the mainExpr buffer, than you need to give it multiple options by separating the two options, not combining them. It probably should look more like this:?i:PROCEDURE\s+ \K | ?i:FUNCTION\s+ \K
When the first option fails, it tries the next…and on down a list if there are multiple options, like @PeterJones showed me in my dBASE UDL, which had the similar construct of Procedure, Functions, but also so we could make objects show up in the function list when there was no function, by using an additional OR statement of
with
, where the code looked like this:this.NPPINST_TL = new TEXTLABEL(this) with (this.NPPINST_TL) height = 2.0 left = 29.0 top = 0.5 width = 67.0 text = "Notepad++ dBASE Plus UDL Installer" colorNormal = "0x404000/Silver" fontSize = 19.0 fontBold = true endwith
As you can see, our UI classes would not show up unless they had a function inside them, and we wanted to be able to see the Objects whether they had a function or not, and @PeterJones figured that out for me, that adding that OR statement in the function parser would allow that to show up also emulating a function option, so our functionList code looked like this:
<function mainExpr="(?xi-s) ^ \h* (?: function \h+ \w+ | procedure \h+ \w+ | with \h+ \(.*?\) ) \h* " >
Hopefully this helps you.