Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Thanks to Ikegami, Chromatic & Corion

by ikegami (Pope)
on Nov 01, 2011 at 20:43 UTC ( #935213=note: print w/ replies, xml ) Need Help??


in reply to Thanks to Ikegami, Chromatic & Corion

Cool, where can one get their hands on it? And could you please fill in this table to match the changes in aXML?

Plugin OutputaXML Output
???&
???<
???>
???[
???]
???(
???)
???&lab;
???<db_select>
<table border="1"> <tr><th>Plugin Output<th>aXML Output <tr><td><c>???</c><td><c>&</c> <tr><td><c>???</c><td><c><</c> <tr><td><c>???</c><td><c>></c> <tr><td><c>???</c><td><c>[</c> <tr><td><c>???</c><td><c>]</c> <tr><td><c>???</c><td><c>(</c> <tr><td><c>???</c><td><c>)</c> <tr><td><c>???</c><td><c>&lab;</c> <tr><td><c>???</c><td><c><db_select></c> </table>


Comment on Re: Thanks to Ikegami, Chromatic & Corion
Select or Download Code
Re^2: Thanks to Ikegami, Chromatic & Corion
by Logicus on Nov 01, 2011 at 21:46 UTC

    The complete sourcecode to PerlNights.com, including all site assets, will be available shortly in the "Castle Blueprints" section. (gosh a self-replicating castle... whatever next?)

    In the table below, input refers to information either loaded from disc, retrieved from a db, created by a plugin, or entered through the query data by an end user.

    Output refers to the final produced output at end of processing.

    In between these two there is usually no need to consider these specials at all as they are all automatically dealt with by the system, so unless your doing something very bizarre your not likely to ever see them or need to know what they are about.

    Having said that for the sake of absolute completeness the special symbols work as follows;

    Input Output
    &lab; <
    &rab; >
    &lcb; (
    &rcb; )
    &lsb; [
    &rsb; ]
    <special>lab</special> &lab;
    <special>lcb</special> &lcb;
    <special>lsb<special> &lsb;
    <special>rab<special> &rab;
    <special>rcb</special> &rcb;
    <special>rsb</special> &rsb;
    &lab;special&rab; <special>
    &lab;/special&rab; </special>

    Note: if you want to use a tag other than "special" to instruct the parser to insert a special char, perhaps in the case where your using an XML file containing tags of the same name, provision has been made to rename the special tag by changing a value in the Conf.pm file.

    It's also possible in theory, that since the end programmer is not expected to know or care about these symbols for the vast majority of their tasks, that the system could be automated such that input is scanned for the existence of <special> tags and automatically shift to using a different delimiter, for instance <special1>. I'm not sure if that would be overkill, there is such a thing as a sledgehammer and a nut.

    In the case where you wish to output aXML code such as <db_mask> then you have the choice to either use &lab;/&rab; or &lt;/&gt;, either will work, and which you use depends on whether you want the literal output, or output is to be encoded for display in a browser. (the latter being I suspect the far more common requirement.

    The following aXML file was used to test the round trip completeness for the parser code:

    Listing of actions/test/body.aXML --------------------------------- <html> <head></head> <body> (displayqd)input(/displayqd) <hr> <buildform action="test" method="POST"> <input type="submit" value="Make it so!"><br/> <textarea name="input" rows="80" cols="80" >(textareaqd)input(/textareaqd)</textarea> </buildform> <br/><br/><br/> </body> </html>

    As you can see, no mention of any specials is required at the document level, as they are all handled automatically at the parser/plugin level. The above code run with the standard set, can take the parser as input in the text area, and correctly displays it above, and encodes it in the input area for another go around the circle if you click submit again. Sending it around the circle multiple times has no detrimental effect; the output remains identical to the input.

    Modifying the above like this :

    <html> <head></head> <body> (highlightcode)(displayqd)input(/displayqd)(/highlightcode) <hr> <buildform action="test" method="POST"> <input type="submit" value="Make it so!"><br/> <textarea name="input" rows="80" cols="80" >(textareaqd)input(/textareaqd)</textarea> </buildform> <br/><br/><br/> </body> </html>

    Causes fragments of perl wrapped in <code> tags to be highlighted in a similar fashion to the "nano" text editor, and fragments of aXML wrapped in <aXML> tags to be highlighted in a similar vein.

    The highlighting is done with <span> tags and can then be styled using CSS. PerlNights currently has two colour-schemes, midnight (light-text on darkblue bg) and daytime (dark text on white bg), and more might be added later.

    P.s, if you want a sneak peak at the PerlNights code before I'm finished writing it, you can drop me an email and I will bundle you over a ZIP or tar.gz file, I'm sure you know my address, either that or you can just wait till I'm done and PerlNights is operational, won't be too long!

      If I want to display &lab;special&rab;, do I emit &amp;lab;special&amp;rab;?


      Improve your skills with Modern Perl: the free book.

        Yes, just tested that and it works as expected. You could also do:

        <special>lab</special>special<special>rab</special>

        bit more verbose, but the output is the same, and possibly a bit more readable.

        "&" is not a meta character in aXML unless followed by "lab;" or one of the other 5, so "&amp;" outputs "&amp;", so "&amp;lab;special&amp;rab;" produces "&amp;lab;special&amp;rab;".

        To output "&lab;special&rab;" one needs "<special>lab</special>special<special>rab</special>".

        The escape function is:

        my %escapes = ( '<' => '&lab;', '>' => '&rab;', '(' => '&lcb;', ')' => '&rcb;', '[' => '&lsb;', ']' => '&rsb;', '&lab;' => '<special>lab</special>', '&lcb;' => '<special>lcb</special>', '&lsb;' => '<special>lsb</special>', '&rab;' => '<special>rab</special>', '&rcb;' => '<special>rcb</special>', '&rsb;' => '<special>rsb</special>', ); #my $escapes_pat = join '', map quotemeta, keys %escapes; #my $escapes_re = qr/$escapes_pat/; my $escapes_re = qr/[<>()\[\]]|&[lr][acs]b;/; # Manually tweaked. sub escape(_) { my ($s) = @_; $s =~ s/($escapes_re)/$escapes{$1}/g; return $s; }

        These are probably better choices:

        my %escapes = qw( & &AMP; < &LAB; > &RAB; ( &LCB; ) &RCB; [ &LSB; ] &R +SB; ); sub escape(_) { my ($s) = @_; $s =~ s(/[&<>()\[\]])/$escapes{$1}/g; return $s; }

        Or using v5.14's s///r:

        my %escapes = qw( & &AMP; < &LAB; > &RAB; ( &LCB; ) &RCB; [ &LSB; ] &R +SB; ); sub escape(_) { $_[0] =~ s(/[&<>()\[\]])/$escapes{$1}/gr }

        Why is "parenthesis" abbreviated to "c"? I think reading the "c" as curly, but "{" and "}" are the curly brackets.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935213]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2014-10-25 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (141 votes), past polls