in reply to assertions help

DavidFerrington seems to be looking for a form of macro processor. Other replies give good regex solutions to the OPer's problem in terms of its narrow definition in the OP. However, these solutions seem fragile in that they may need substantial revision when faced with new or expanded requirements (which, as we know, always appear).

Then why not use a macro processor, e.g., m4 or cpp, either invoked from Perl or from the command line? The OPer may be working under Windows, but I'm sure versions could be found for this OS (cpp used to be a pretty standard C compiler utility).

Update: Changed m4 and cpp above into man page links.

Replies are listed 'Best First'.
Re^2: assertions help
by DavidFerrington (Acolyte) on Dec 23, 2009 at 00:04 UTC
    I'm processing SQL, not C and CPP states results might be unknown if the parsed file is not in C format. I couldn't find m4 in our production build (presume it's removed like a lot of dev tools on a prod build) and if I remember correctly, m4 doesn't handle
    #if defined (ABC) or defined(DEF)
    something I'm going to tackle next.

    Lastly, I wanted to try to do this in Perl and only Perl. Since I'm wighting a new tool and can set limits on it's use, plus most of what I'm dealing with is legacy, I think I'm safe here. But yes I understand about creeping featurism!

    But thanks for the thoughts, they were my first ones too.

    -- David
      ... CPP states results might be unknown if the parsed file is not in C format.

      I'm not sure what this refers to. In my understanding, cpp is at root a text macro processor. It may have a number of features adapting it to C, C++ and ObjectiveC/C++ file processing, but these may be easily turned off. Strictly to satisfy my curiosity, can you give a reference to or example of the warning you mention?

      ... if I remember correctly, m4 doesn't handle
       #if defined (ABC) or defined(DEF)

      I am not very familiar with m4, but I think you may be right, at least in that form. But if you can accept  || in place of  or as your logical operator, cpp would do the trick.

      In any event, you seem to know what you want, so let me wish you every success in your quest.