Re: line numbers with Filter::Simple
On Jun 1, 2007, at 13:13, David Nicol wrote: 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 :) That's crazy, man! I think I'm going to need to see it in action... Did you like my warning format, though? I like and dislike the name. Macrame is one of those names that's clean, evocative, implies a really cool and symbolic logo... and doesn't actually say anything about the program's purpose. Does it have anything to do with OSX? :) -- Rocco Caputo - [EMAIL PROTECTED]
Re: line numbers with Filter::Simple
On May 30, 2007, at 16:38, David Nicol wrote: We can declare a line number, in source code, like so # perl foo #line 54 die smiling foo smiling at - line 54. # and counting newlines within a Filter::Simple code block is easy enough but how do I find out what line to start at, so I can insert #line comments into my filter output that will match the input? I am about to experiment with caller(N) to see how many frames back to go, then I'll use that, but I am asking here in case anyone knows a better way. caller() is a good solution. I use it, Filter::Util::Call, and some involved #line magic to maintain sane line numbers in Filter::Template. This short example defines a whatever template, then expands it inline. The resulting error message follows. (Note that #line directives seriously confuse perl -d. I half-jokingly suggested floating-point line numbers so source filters could insert lines 1.01 through 1.10 between lines 1 and 2 if necessary. But I digress...) #!/usr/bin/env perl use Filter::Template; template whatever (why) { die whatever died: , why; } {% whatever stuff %} __END__ whatever died: stuff at template whatever (defined in moo.perl at line 6) invoked from moo.perl line 9. -- Rocco Caputo - [EMAIL PROTECTED]
Re: line numbers with Filter::Simple
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; };
line numbers with Filter::Simple
We can declare a line number, in source code, like so # perl foo #line 54 die smiling foo smiling at - line 54. # and counting newlines within a Filter::Simple code block is easy enough but how do I find out what line to start at, so I can insert #line comments into my filter output that will match the input? I am about to experiment with caller(N) to see how many frames back to go, then I'll use that, but I am asking here in case anyone knows a better way.