SOLVED - RegEx works in Find but not in Code Folder

Discuss and announce AkelPad plugins
Post Reply
  • Author
  • Message
Offline
Posts: 32
Joined: Thu Oct 15, 2015 2:20 am

SOLVED - RegEx works in Find but not in Code Folder

Post by CBruce »

This regex:

Code: Select all

^[ \t]*(extern)\s(?!.*?\bas\b).*?$
... works in AkelPad's Find and in online regex sites like: https://regex101.com/
... but it does not work in Coder's Code Fold:

Code: Select all

1048576	0	0	0	"^[ \t]*(extern)\s(?!.*?\bas\b).*?$"	"end extern"	" 	"		0	0
Test text:

Code: Select all

'This line is *NOT* caught by the regex in Find or Code Fold -> (good):
extern import _HUGE alias "_HUGE" as double ptr

'This line *IS* caught by Find -> (good) -- but is *NOT* caught by Code Fold -> (bad):
extern "c"
declare function _cabs (byval as _complex) as double
declare function _matherr (byval as _exception ptr) as long
end extern
Anyone have an idea why Code Fold is handling the regex differently/incorrectly?

Thanks!
CBruce
Last edited by CBruce on Tue Aug 09, 2022 2:52 am, edited 1 time in total.

Offline
Posts: 13
Joined: Thu May 05, 2022 5:38 am

Post by dothen »

If I understood correctly the problem is that the rule

Code: Select all

40	0	0	0	"extern"           "end extern"      " 	"	0	0
captures a single-line 'extern'

Code: Select all

extern import _HUGE alias "_HUGE" as double ptr
and from this folding breaks down.

Solution:

Code: Select all

;1048584=8+1048576
1048584	0	0	0	"extern(?=[ \t][^\n]*[ \t]as[ \t][^\n]*$)"    "as"    " 	"	0	0
;40=8+32
40	0	0	0	"extern"           "end extern"      " 	"	0	0
Now both single-line and multi-line 'extern' will be shown in the side list,
and you can quickly move from the list to the selected line.

If the (Menu->Plugins->Programming->Settings...->CodeFold2->Mark tag) option is enabled
then the beginning and end of the block will be highlighted when the carriage is at the beginning or at the end of the block.

Notes:
The order of the rows matters, if you swap it will not work.
The forum replaces the tab character with spaces. Delimiters = space and tab.
Flags 8 and 32 mean that only space and tab characters are allowed between the beginning of the line and the beginning or end of the block.

Offline
Posts: 32
Joined: Thu Oct 15, 2015 2:20 am

Post by CBruce »

Thanks @dothen !!!!
That works perfectly for the "extern"s!
I will apply it to the other "same verb" single-line/multi-line statements and see if that fixes the rest of my problems as well.

BUT... if anyone can tell me why my original regex does not work as a Code Fold catch, I would really appreciate it!

Thanks,
CBruce

Offline
Posts: 13
Joined: Thu May 05, 2022 5:38 am

Post by dothen »

CBruce wrote: BUT... if anyone can tell me why my original regex does not work as a Code Fold catch, I would really appreciate it!
The reason is in the 's' modifier.

AkelHelp-Eng.htm->Regular expression syntax

Code: Select all

(?options)
(?s) - dot '.' matches any single character (default).
(?-s) - dot '.' matches any single character, except newline character.
It works

Code: Select all

1048576   0   0   0   "^[ \t]*(extern)\s(?-s)(?!.*?\bas\b).*?$"   "end extern"   " 	"      0   0
Note:
If you enable the option:(Menu->Edit->Find...->Regular expressions->. matches \n)
this expression

Code: Select all

^[ \t]*(extern)\s(?!.*?\bas\b).*?$
will not find anything in AkelPad's Find. :D

Offline
Posts: 32
Joined: Thu Oct 15, 2015 2:20 am

Post by CBruce »

Thanks again, @dothen !!!

This is actually a much better solution for me.
It allows for the folding of a verb's multi-line code block - and doesn't require catching any single-line versions of that verb.
With this, those single-line instances don't show up in the code fold panel at all.
This is exactly what I have been trying to accomplish!
Post Reply