Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try this.<br> Some questions. Are you accumulating and processing more than 1 line at a time? </p> <p>If not, I don't see any provisions for block comments that extend over multiple lines.<br> Also, block comments consume line comments, and I don't see any provisions for line comment continuation.</p> <p><strong>Edit - 5</strong> @Adrian - I punched up a version that works for me. The Perl code and output are below.<br> Let me know if this does the trick.<br> Note that a added line continuation code for <code>#</code>Preprocessor as well as <code>//</code>Line comments<br> and it tests out very nice. </p> <pre><code> my $doubleQuotedString = q{"(?&gt;[^"\\\\]++|\\\\{2}|\\\\(?s).)*+"}; my $singleQuotedString = q{'(?&gt;[^'\\\\]++|\\\\{2}|\\\\(?s).)*+'}; my ($rest, $code, $stuffToIgnore) = (""); my $counter = 0; while (&lt;DATA&gt;) { $_ = "$rest$_"; do { ($code, $stuffToIgnore, $rest) = m~ ( # (1), Code (?: (?! ^ [^\S\n]* \# ) # Not a preprocessor statement (?: $ doubleQuotedString # found a string | $ singleQuotedString # found a string | (?: [^/\n]++ | / [^*/\n] ) # found something not a string or comment or newline | \n # newline ) )*+ ) ( # (2), Ignore (?: \s*+ ^ [^\S\n]* \# # '#' Preprocessor statement with Continuation logic (?: [^\\] # any Non-Continuation character ^\ | \\ \n? # Or, any Continuation character followed by optional newline )*? (?&lt;! \\ ) \n | \s*+ /\* # '/**_**/' Block comment (?: [^*]++ | \* (?! / ) )*+ \*/ | \s*+ // # '//' Line comment, with Continuation logic (?: [^\\] | \\ \n? )*? (?&lt;! \\ ) \n )*+ ) ( # (3), Rest (?s) .* ) ~xm; ++$counter; goto BLOCK_READ if $stuffToIgnore ne "" or eof(DATA); } while ($_ .= &lt;DATA&gt;); BLOCK_READ: defined $code or die "Unterminated block."; # do transformation on $code print "CODE: &gt;&gt;$code&lt;&lt;\nIGNORE: &gt;&gt;$stuffToIgnore&lt;&lt;\n---------------------------------------\n"; } __DATA__ # hello \ there # how # are #you #pragma once #include "EditState.h" #include "MyDoc.h" // InputEdit class CInputEdit : public CEdit { DECLARE_DYNAMIC(CInputEdit) public: CInputEdit(); virtual ~CInputEdit(); // Attributes protected: DECLARE_MESSAGE_MAP() BOOL m_bTrackingMenu; }; </code></pre> <p>Output </p> <pre><code> CODE: &gt;&gt; &lt;&lt; IGNORE: &gt;&gt;# hello \ there &lt;&lt; --------------------------------------- CODE: &gt;&gt;&lt;&lt; IGNORE: &gt;&gt;# how &lt;&lt; --------------------------------------- CODE: &gt;&gt;&lt;&lt; IGNORE: &gt;&gt;# are &lt;&lt; --------------------------------------- CODE: &gt;&gt;&lt;&lt; IGNORE: &gt;&gt;#you &lt;&lt; --------------------------------------- CODE: &gt;&gt; &lt;&lt; IGNORE: &gt;&gt;#pragma once &lt;&lt; --------------------------------------- CODE: &gt;&gt; &lt;&lt; IGNORE: &gt;&gt;#include "EditState.h" &lt;&lt; --------------------------------------- CODE: &gt;&gt;&lt;&lt; IGNORE: &gt;&gt;#include "MyDoc.h" &lt;&lt; --------------------------------------- CODE: &gt;&gt; &lt;&lt; IGNORE: &gt;&gt;// InputEdit &lt;&lt; --------------------------------------- CODE: &gt;&gt; class CInputEdit : public CEdit { DECLARE_DYNAMIC(CInputEdit) public: CInputEdit(); virtual ~CInputEdit(); &lt;&lt; IGNORE: &gt;&gt;// Attributes &lt;&lt; --------------------------------------- CODE: &gt;&gt;protected: DECLARE_MESSAGE_MAP() BOOL m_bTrackingMenu; }; &lt;&lt; IGNORE: &gt;&gt;&lt;&lt; --------------------------------------- </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload