in reply to PRD parser problem: How to skip C comments when parsing

Assuming you don't allow comment nesting or /*/, a C comment is

qr{ /\* .*? \*/ }sx

You said C, but your example also shows a C++ comment. A C++ comment is

qr{ // [^\n]* }x

The default definition of whitespace in PRD is

qr{ \s* }x

So if we combine them all, we get

Para: <skip:qr{ (?> \s | /\* .*? \*/ | // [^\n]* )* }sx> List(s) /\Z/

<skip> is dynamically scoped, so List and everything called by it will be affected.

Replies are listed 'Best First'.
Re^2: PRD parser problem: How to skip C comments when parsing
by Hanken (Acolyte) on Jun 10, 2008 at 07:46 UTC
    Thanks ikegami! But your change seems not fix my script. I cannot get the right result when I change my script with your kind suggestion.
    the error log: error 1! error 0!

      Did you forget to remove <skip: /\/\/.*\n/> from Prize?

      You'll still get an error, though, because your data is invalid based on your definition of Prize. You've previously indicated or implied that the Prize is the rest of the line. You have changed you definition of Prize without adjusting your grammar to compensate. You probably want something like:

      Prize: /(?:(?!\n|\/\*|\/\/).)*/
        Hi, ikegami, Thanks for you answer! I replied this post serveral times but it's not showed out along this post. I don't know why ...
        can your fix deal with mutiple lines comments, like the 3rd line of my example?