FAQ
Hello everybody!

Parse::RecDescent is much help for my task, but what gets me into trouble is that
I can't see a way to pass any parameters to a parser except to make them global variables.
Thus I also cannot call a member function from within an action. How can I deal with that?
Any ideas appreciated.

Search Discussions

  • Ted Zlatanov at Apr 16, 2002 at 4:13 pm

    On Tue, 16 Apr 2002, vsevolod@sendmail.ru wrote:
    Parse::RecDescent is much help for my task, but what gets me into
    trouble is that I can't see a way to pass any parameters to a parser
    except to make them global variables. Thus I also cannot call a
    member function from within an action. How can I deal with that?
    Any ideas appreciated.
    Can you give an example of what you're trying to do?

    Thanks
    Ted
  • Marcel Grunauer at Apr 16, 2002 at 9:14 pm

    Am 4/16/02 3:36 PM schrieb "Vsevolod Buzinov" unter <vsevolod@sendmail.ru>:

    Parse::RecDescent is much help for my task, but what gets me into trouble is
    that I can't see a way to pass any parameters to a parser except to make them
    global variables.
    perldoc Parse::RecDescent

    Arguments can also be passed to the start rule, simply by
    appending them to the argument list with which the start
    rule is called (after the "line number" parameter). For
    example, given:

    $parser = new Parse::RecDescent ( $grammar );

    $parser->data($text, 1, "str", 2, \@arr);

    # ^^^^^ ^ ^^^^^^^^^^^^^^^
    # | | |
    # TEXT TO BE PARSED | |
    # STARTING LINE NUMBER |
    # ELEMENTS OF @arg WHICH IS PASSED TO RULE data

    then within the productions of the rule `data', the array
    `@arg' will contain `("str", 2, \@arr)'.

    .... If that's what you mean.

    Marcel
  • Vsevolod Buzinov at Apr 17, 2002 at 12:23 pm

    Marcel Grunauer wrote:

    $parser = new Parse::RecDescent ( $grammar );

    $parser->data($text, 1, "str", 2, \@arr);

    # ^^^^^ ^ ^^^^^^^^^^^^^^^
    # | | |
    # TEXT TO BE PARSED | |
    # STARTING LINE NUMBER |
    # ELEMENTS OF @arg WHICH IS PASSED TO RULE data

    then within the productions of the rule `data', the array
    `@arg' will contain `("str", 2, \@arr)'.

    .... If that's what you mean.
    Thank you -- now I'm able to call an instance method of a class:
    ....
    html: <rulevar: local $self = $arg[0]>
    start_tag: '<' tagname attr(s?) '>' {$self->start_handler ($item[2], $item[3])}
    ....

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprecdescent @
categoriesperl
postedApr 16, '02 at 1:37p
activeApr 17, '02 at 12:23p
posts4
users3
websitemetacpan.org...

People

Translate

site design / logo © 2018 Grokbase