Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the --trace=actions option #396

Merged
merged 1 commit into from
Apr 17, 2024
Merged

Conversation

ydah
Copy link
Collaborator

@ydah ydah commented Apr 17, 2024

The concept of merging actions was born in Inline. I think it would be useful to have an option to print the resolved action. However, we don't know what it is when I just display the action, so I've decided to print the rule and its corresponding action like this:. What do you think?

❯ exe/lrama --trace=actions sample/calc.y
Grammar rules with actions:
$accept -> list, YYEOF {}
list -> ε {}
list -> list, LF {}
list -> list, expr, LF { printf("=> %d\n", $2); }
expr -> NUM {}
expr -> expr, '+', expr { $$ = $1  +  $3; }
expr -> expr, '-', expr { $$ = $1  -  $3; }
expr -> expr, '*', expr { $$ = $1  *  $3; }
expr -> expr, '/', expr { $$ = $1  /  $3; }
expr -> '(', expr, ')' { $$ = $2; }

The concept of merging actions was born in Inline. I think it would be useful to have an option to print the resolved action.
However, we don't know what it is when I just display the action, so I've decided to print the rule and its corresponding action like this:. What do you think?

```
❯ exe/lrama --trace=actions sample/calc.y
Grammar rules with actions:
$accept -> list, YYEOF {}
list -> ε {}
list -> list, LF {}
list -> list, expr, LF { printf("=> %d\n", $2); }
expr -> NUM {}
expr -> expr, '+', expr { $$ = $1  +  $3; }
expr -> expr, '-', expr { $$ = $1  -  $3; }
expr -> expr, '*', expr { $$ = $1  *  $3; }
expr -> expr, '/', expr { $$ = $1  /  $3; }
expr -> '(', expr, ')' { $$ = $2; }
```
@yui-knk yui-knk merged commit 3ee5723 into ruby:master Apr 17, 2024
16 checks passed
@yui-knk
Copy link
Collaborator

yui-knk commented Apr 17, 2024

LGTM, thank you!

@ydah ydah deleted the new-option branch April 17, 2024 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants