unk1911 has asked for the wisdom of the Perl Monks concerning the following question:

i am having a difficulty parsing a dollar sign ($) followed by a decimal value. here's my grammar:
$test = "$5.1"; $grammar = q { input: dollar decimal dollar : /\$/ { $item[1] } decimal : /[-+]?(\d+)?\.\d+/ { warn "decimal! $item[1]" } ...

i keep getting an error during a parse. does anyone see what i am doing wrong? if i replace $ with a % sign in the grammar and $test then everything works but the dollar is giving me a hard time. any help would be greatly appreciated. this sounds like a very trivial problem but i just don't see it.

-- http://unk1911.blogspot.com

Replies are listed 'Best First'.
Re: Parse::RecDescent and dollar sign
by Fletch (Bishop) on Jun 16, 2005 at 18:51 UTC

    It's possible to get P::RD to dump out the generated code into a file (rather than having it generated on the fly each time). You might try this and look at the code generated for your "dollar" rule.

    ## Turn the grammar in file grammar.txt into MyGrammar.pm $ perl -MParse::RecDescent - grammar.txt MyGrammar

    --
    We're looking for people in ATL

Re: Parse::RecDescent and dollar sign
by ikegami (Patriarch) on Jun 16, 2005 at 19:58 UTC
    Use
    $grammar = q { dollar : /\\$/ { $item[1] } };
    or
    $grammar = <<'__END_OF_GRAMMAR__'; dollar : /\$/ { $item[1] } __END_OF_GRAMMAR__
Re: Parse::RecDescent and dollar sign
by kwaping (Priest) on Jun 16, 2005 at 18:57 UTC
    Have you tried matching for the octal value of '$'? /\044/
      well the thing is there was nothing wrong with my grammar. my test case was wrong, i forgot about the dollar sign. i'm in good shape now , thanks