Hiya, I am trying to allow any amount of characters to go on multiple lines of a text area before the print statement, and parse a print statement whilst using Parse::Recdescent, but am having trouble. It will say there is an error if the letter p shows up anywhere else in the script before the print function is used, but if the letter p is typed in the textarea beforehand i dont want an error to show. How can i overcome this? The problem is the "text: /([^p]*)/" bit. Here is what i have. Cheers

#!/usr/bin/perl use strict; use Tk; use Parse::RecDescent; my $mw = new MainWindow; my $mw2 = $mw->Text()->pack(); my $mw3 = $mw->Button(-text=>"Check brackets", -command => [ \&parser, $mw2 ] )->pack(); MainLoop; sub parser { my $txt = shift; my $grammar = q { startrule: anything print open text close end anything:/([^p]*)/ print: "print" open: "'" text: /([^']*)/ close: "'" end: ";" }; my $parser = Parse::RecDescent->new($grammar); if ( defined( $parser->startrule( $txt->get( "1.0", "end" )))) { print "NO ERROR\n"; } else { print "Print function error\n"; } }

Also, i am wondering if i can get it so multiple print functions can appear down the text area and if there is an error with a later function, it will be spotted.
Cheers

20050331 Janitored by Corion: Put code in code tags.


In reply to Parse::Recdescent rule problem by hak0983

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.