Parse::Recdescent match word exactly with regular expressions

Discussion in 'Perl' started by ccm news, Jan 15, 2009.

  1. ccm news

    ccm news Guest

    Hi,

    ( using parse::recdescent 1.94 )
    I want to parse a string and search for a word (and exactly this word). I
    use the following grammar:

    my $grammar = <<'_EOGRAMMAR_';

    any : /[a-zA-Z0-9\d\., +-]+/

    cmd_unknown : any(s)
    { main::cmd_unknown(); $return = 1;}

    cmd_doit : /doit/
    { main::cmd_doit(); $return = 1; }

    cmd : cmd_doit
    | cmd_unknown

    startrule: <skip: qr/[ \t]*/> cmd

    _EOGRAMMAR_


    The input "doit\r\n" works and executes the cmd_doit. But using the string
    "doitnow\r\n" as input it also executes the cmd_doit function.

    I want something like:

    cmd_doit : /^doit$/ # saying the sentence must begin and end with doit. but
    this syntax doesnt work?!

    Any suggestions?

    Thanx for your time.
     
    ccm news, Jan 15, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jean-gert nesselbosch

    XPath1.0-grammar compatible to Parse::RecDescent

    jean-gert nesselbosch, May 12, 2006, in forum: XML
    Replies:
    0
    Views:
    416
    jean-gert nesselbosch
    May 12, 2006
  2. Lex Williams

    Alternative to Parse::RecDescent

    Lex Williams, Aug 26, 2008, in forum: Ruby
    Replies:
    4
    Views:
    206
    James Gray
    Aug 27, 2008
  3. Jon Ericson

    Huffman coding and Parse::RecDescent

    Jon Ericson, Apr 22, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    184
    Jon Ericson
    Apr 23, 2004
  4. Chris Chandler

    Non match word list with Regular Expressions

    Chris Chandler, Aug 18, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    186
    John Bokma
    Aug 18, 2004
  5. Noman Shapiro
    Replies:
    0
    Views:
    245
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page