#!/usr/bin/perl use Modern::Perl; my $knownCmds = '(use|conf|qd)'; $_ = qq@ <conf>site_title</conf> some orphan text actions/action/somefile.aXML orphan a @; #tokenise negatable marker s@`@@gs; #any text before first knownCmd s@(.*?)<$knownCmds>@'$1',\n\n<$2>@s; #put negatable marker next to knownCmds s@<$knownCmds>@<$1>`@gs; s@@`@gs; #any text between any two opens s@<$knownCmds>`([^`]*?)<$knownCmds>`@<$1>`\n'$2',\n\n<$3>`@gs; #any text between any two closes s@`([^`]*?)`@`\n'$2',\n\n`@gs; #any text between a close and an open s@([^`]*?)<$knownCmds>@\n\n'$2',\n\n<$3>@gs; #any text after last known close s@(.*)(.*)@$1\n'$3'@s; #remove remaining negatable markers s@`@@gs; #de-tokenise negatable marker s@@`@gs; #convert non-nested tags to node calls s@<$knownCmds>([^<>]*?)@Node->new ( $1 => '$2' ),@gs; #convert everything else s@<$knownCmds>(.*?)@Node->new ( \[ $2 \] ),@gs; #get rid of comma before end of array s@,(\s+?)\]@]@gs; say 'my @nodes = ('; say; say ');'; #### my @nodes = ( ' ', Node->new ( conf => 'site_title' ), ' some orphan text ', Node->new ( [ 'actions/', Node->new ( qd => 'action' ), '/somefile.aXML', ] ), ' orphan ', Node->new ( conf => 'a' ), ' ' );