How to write micrograms in perl6?

I am interested in writing micrograms. Here the parser does not understand the full grammar of the language, only part of it; kind of "m4 acid."

The idea is that the parser reads the characters and writes them for output until it β€œwakes up” when it identifies the keywords, performs some processing according to the grammar, and then falls asleep again.

I'm having trouble building it, and in fact there are no examples.

+7
parsing perl6 grammar
source share
1 answer

The .subparse method may be what you are looking for. It captures at the beginning of the data and matches as much as it can. You can use the adverb :c to tell you where to start, and then look at the Match object to see where it stopped.

  my $position = 0; my $match = Some::Grammar.subparse( $data, :c($position) ); # update the position to the last thing your grammar consumed $position = $match.end if $match.so; 

If you keep track of where you are, you can switch grammars, try again when the buffer receives more data, etc.

In addition, you did not present the specific problem you are trying to solve.

+7
source share

All Articles