Is there a way to run an action on a grammar that's already been parsed?
Asked Answered
R

1

5

If I do:

my $parsed_grammar = PG.parse( $some_string );

Is there any way to to do something like the pseudo code below?

$parsed_grammar.run_action( $action_class.new );
Redundancy answered 4/4, 2022 at 5:9 Comment(0)
S
7

No.

Your grammar is basically a program.

Contrary to other (regex) implementations, Raku grammars are basically just another way to write a class and methods. It's all code underneath. Code that can have callbacks for each method run. That's what your action class is: a way to specify the callbacks.

So, the parsing of your grammar happens at compile time. That creates code that gets run when you call .parse with the given string as the input.

Your misconception seems to be that running .parse on a grammar parses the grammar. It doesn't. It runs the grammar, it parses your input string.

Schweitzer answered 4/4, 2022 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.