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. :-) : 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. : > : And what about switching to a different or modified tokenizer ? : > : > It's not clear that the lexer is a separate entity any more. Lexers : > were originally invented as a way of abstracting out part of the : > grammar so that it could be done in a separate pass, and to simplify : > the grammar for the poor overworked parser. But you can write a : > grammar for an identifier just about as easily as for an if-then-else. : > More easily, if we're basing it on regexes. If we're viewing all : > grammar through the lens of regexes, we're really starting out closer : > to Lexerland anyway, and generalizing toward parsing, a traditionally : > weaker area for Perl. And that's an odd weakness for a text : > processing language. : : I am *so* looking forward to Apocalypse 5... Mmm. You wanna write it for me? :-) 'Course, all the hard bits will likely be deferred to Apocalypse 18 or so... Larry