Hi, Guys, I am new to PRD. I knew there are many topics on skipping C comments in parser, but I failed to make it work in my perl script. Can anybody show me an example or just fix my script blow.
#! /usr/local/bin/perl -sw BEGIN { close STDERR and open STDERR, '>./STDERR' or die $!; } use Parse::RecDescent; #============================================ # GRAMMAR DEFINITION HERE #============================================ $grammar = q{ Para: List(s) /\Z/ | { use Data::Dumper 'Dumper'; print "$_->[0]\n" for @{$thisparser->{errors}}; exit; } List: #<skip: here???> Order Name Score Prize | <error: error 0!> Order: /\d+/ {print "@item\n";} | <error: error 1!> Name: /\w+/ {print "@item\n";} | <error: Expecting a name!> Score: /\d+/ {print "@item\n";} | <error: error 2!> Prize: <skip: /\/\/.*\n/> /[^\n]+/ {print "@item\n";} }; #============================================ # MAIN PROGRAM STARTS HERE #============================================ $parse = new Parse::RecDescent ($grammar); my $text = do { local $/; <DATA> }; $parse->Para($text); __DATA__ 1 Pig 100 red flower // 1 can this be removed? 2 Han 80 bread /* 2 I want this removed! */ 3 Hen 50 ass kicked /* 3 this comment should be handled too */ 3 Fdi 99 rose /* 4 failed msg if unbalanced comment here

BTW: my script works well if there is no comment in <data>.

In reply to PRD parser problem: How to skip C comments when parsing by Hanken

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.