Larry Wall <[EMAIL PROTECTED]> writes: > Piers Cawley writes: > : In a use.perl post not far away I sketched out something like the following: > : > : module foo is Mixin { > : > : sub category($category, &block) { > : &block.abstract_syntax_tree.walk_with -> $node { > : when AST::Method { > : .attrib(category => $category) if .parent =~ █ > : } > : } > : } > > I don't entirely understand what you're trying to do. Pretty code, > though. :-)
Heh. I didn't think it was that tricky. ..abstract_syntax_tree gets the blocks Syntax Tree. ..walk_with iterates over the tree passing each node into the block it gets called with. -> $node { when AST::Method { ... } } a single argument callback function. Yeah, I could have used { given $^node { when AST::Method {...} } } But I liked the C<-> $node {...}> notation better in this case. And then the callback decorates every method defined at the top level of the block with a category attribute. So, I know I'm stretching on the AST thing, but we're not far off being able to do this sort of thing right now with B::Optimize and B::Utils. > : Actually, my naming choices were rather worse, I originally suggested > : 'optree', but the optree is really too low level for a lot of things. > : > : # Which leads to thoughts of: > : macro Java(&block is rw) { > : &block = &block.source.parse_with( Parser::Java ) > : } > : } > : > : (The idea here is that 'macro' would get the block 'earlier' while the > : raw source is still lying around, and before perl has started to throw > : syntax errors.) > > Hmm, I think most macros with arguments would want to assume the > arguments to be Perl code, and not delay parsing till the macro > call. The abstraction of having an argument to the macro that's not > really there when you call it seems a bit odd. Why return a value > through the argument? I'd rather look at it as an argumentless > macro that just happens to harvest additional text from the input > stream. Then return the block as part of what the macro ordinarily > returns. Seems cleaner to me. Good point. However, I'd like to see a mechanism that allows one to use an entirely different parser a la Inline. macro Java is raw { ... } # Gets untokenized, unparsed source macro PerlDialect { ... } # Gets some sort of syntax tree? > : I am *so* looking forward to Apocalypse 5... > > Mmm. You wanna write it for me? :-) Hell no. I'd volunteer to do tech review, but I'm sure that with Damian, Dan, Hugo, Jon, Gnat and Co. on your case already you don't really need another pair of eyes; I'd just slow you down. > 'Course, all the hard bits will likely be deferred to Apocalypse 18 > or so... By which time it'll all seem obvious and/or inevitable. One hopes. -- Piers "It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite." -- Jane Austen?