Building a Smart IDE: Identifying comments

  • + 0 comments

    perl

    use warnings;
    use strict;
    
    my $mComment = 0;
    while(<>){
        if(m|//|){
            print "$&$'";
        } elsif ( (/\/\*\*?/ && ($mComment = 1)) || $mComment == 1){ 
    #set $mComment to 1 if match
            s/^\s+//g; #remove beginning spaces
            print;
            $mComment = 0 if(m%\*\*?/%);
        }
    }