Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Struggeling with RegExp - Experts needed.
MortenMacFly:
Dear all,
since Thomas is not available I decided to ask here hoping I can find some RegExp experts. I'm trying to fix a bug in macrosmanager.cpp concerning the new $relative() and $absolute() macros. I came that far:
The RegExp "m_re_path" seems to extract the string not correctly - from e.g.
$relative($(TARGET_OUTPUT_DIR))lib$(TARGET_OUTPUT_BASENAME).a
*should* be extracted:
$relative($(TARGET_OUTPUT_DIR))
bus *is* extracted:
$relative($(TARGET_OUTPUT_DIR)
(Notice the missing trailing bracket.)
I thought changing the RegExp from
([^$]|^)(\$(absolute|relative)\(([^)]+)\))
into:
([^$]|^)(\$(absolute|relative)\(([^)]+\))\))
might solve the problem, but it doesn't - as it seems the intended functionality (can have nested macros/string) get's lost. Any ideas???
With regards, Morten.
Ps.: For those having more insight: The guess that MakeRelativeTo() might be the cause of the bug is wrong - this works properly, also for path's with a trailing path separator.
dmoore:
shouldn't the inner substitution $(TARGET_OUTPUT_DIR) be found first and substituted? so your m_re_path regex should exclude cases where group 4's text contains nested macro variables until after they have been subsituted?
something like
--- Code: ---"([^$]|^)(\$(absolute|relative)\((?!.*\$\(.*\).*)(.*)\))"
--- End code ---
where
--- Code: ---(?!.*\$\(.*\).*)
--- End code ---
excludes patterns that have unsubsituted macros
joat:
Try ([^$]|^)(\$(absolute|relative)\(([^)]+))\)\)
Ignore that (my brain was kinda fried since I wrote it after staying up two days straight writing a research paper).
Let me make sure I've got this straight. The problem is that you want to have stuff nested in $relative() and extract $relative() with whatever is inside of it? How flexible is the accepted nesting? Would more than one item be allowed in a set of braces such as $relative(something()somethingelse()) ? If not, and only one item is allowed inside each set of braces like $relative(something(somethingelse())) then ([^$]|^)(\$(absolute|relative)\(([^)]+))\)+ should work since all of the closing braces would be together. To be on the safe side, it might also be a good idea to use some code to verify that all open braces are closed before and after applying the regex in this case.
mandrav:
Morten, you are very lucky ;).
In revision 3300 I committed a little plugin I had sitting here for some time which just might help you: a (very) simple regular expressions testbed. You give it a regex, a test input and click a button for the results :).
dmoore:
--- Quote from: mandrav on November 28, 2006, 11:57:52 pm ---Morten, you are very lucky ;).
In revision 3300 I committed a little plugin I had sitting here for some time which just might help you: a (very) simple regular expressions testbed. You give it a regex, a test input and click a button for the results :).
--- End quote ---
even more reason to make the C::B editor support "Advanced" wxRegex for find and replace (My POSIX fix is not nearly enough). The only reason Scintilla doesn't support "advanced" regexes natively is because of licensing concerns. Since C::B already uses the wxWidgets with advanced regexes embedded, licensing should be not be a concern. I may have time to put up a patch next week if noone else beats me to it. ;)
Navigation
[0] Message Index
[#] Next page
Go to full version