Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Just hacked this together, it only knows about standard tags which are named, and doesn't know about tag attributes, but it is working.

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

In reply to Re^5: rough start of an axml compiler by Logicus
in thread rough start of an axml compiler by Logicus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2014-12-19 07:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (72 votes), past polls