On 6/1/07, Rocco Caputo <[EMAIL PROTECTED]> wrote:
caller() is a good solution.  I use it, Filter::Util::Call, and some
involved #line magic to maintain sane line numbers in
Filter::Template.

I am preprocessing the code to add line number identifiers between
all lines, then when I process the code I pull them out and tag all my
lexemes with line numbers, and remove the line number IDs from
the quotelike array.  In a routine invoked by FILTER_ONLY, the
initial line appears to be caller(3)[2]

here's my line numbering code, from soon to be released Macrame.pm recursive and
lexical macro system

Like the name?  I think its better than Macro::sweet, which was the runner-up
in my fevered brain :)


sub doMacrame{
        $_ = (transform treeify($_))->Stringify;
};

sub AddLineNumbers {
        my ($line, $file) = caller(3)[2,1];
        my @lines = split /\n/, $_;
        my @linesout;
        for (@lines){
                if (  # see perldoc perlsyn
/^\#   \s* line \s+ (\d+)   \s* (?:\s("?)([^"]+)\2)? \s* $/x
                ){
                        ($line, $file) = ($1,$3);
                        $file =~ s/([^\w\/\\-\.])/sprintf("#%X#",chr($1))/ge;
                        next;
                };

#               push @linesout,  $line++, '"$file"');
#       $source =~ s/^#line (\d+) "(.+)"/__Macrame_LINE($1,$2)/mg;
                push @linesout, '__Macrame_LINE('. $line++.",$file)";
                push @linesout, $_;
        };
        $_ = join "\n", @linesout;
};

FILTER_ONLY
        all => \&AddLineNumbers,
        code => \&doMacrame,
        all => sub {
                print  "begin filter output-----\n";
                print;
                print"\n------ end filter output\n";
        };

Reply via email to