Why Pegged action dont not work in this case ?

Bastiaan Veelo Bastiaan at Veelo.net
Thu Jun 11 11:59:56 UTC 2020


On Sunday, 19 April 2020 at 16:47:06 UTC, Basile B. wrote:
> I 've started experimenting Pegged action. Quickly i got 
> blocked by this problem. The start action works where I use the 
> rule but not directly in the rule.

I don't understand the difference between how you use "where" and 
"directly in".

Note that semantic actions are executed during the parsing 
process, even in branches that eventually fail, before the parser 
back tracks. They are not a substitute for traversing the final 
parse tree, rather, they are a method for manipulating the 
parsing process as it happens.

That's why `endResultRecord` is executed directly after `(',' 
Result)*` succeeds, and `beginResultRecord` is executed directly 
after `ResultRecord` succeeds (even if `'(gdb)'` would not match).

> Test program:
[...]
>     ResultRecord    < {beginResultRecord} Token? '^' 
> ResultClass (',' Result)* {endResultRecord}

Remove the space between "<" and "{", then it works.

> Also I'd like to report that actions dont work with partially 
> specialized templates:
>
> ---
> T handleResultRecord(bool end,  T)(T t);
> // then you use handleResultRecord!true and 
> handleResultRecord!false in the PEG.
> ---

That fails for the same reason as `handleResultRecord!true(1)` 
fails to instantiate.

-- Bastiaan.


More information about the Digitalmars-d-learn mailing list