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

Do not include mid-rule actions when tracing rules #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ydah
Copy link
Member

@ydah ydah commented Jan 1, 2025

This PR, midrule actions should not be included when tracing rules.

Before:

❯ exe/lrama --trace=rules ./spec/fixtures/common/basic.y
Grammar rules:
$accept -> program EOI
program -> class
program -> '+' strings_1
program -> '-' strings_2
class -> keyword_class tSTRING keyword_end
$@1 -> ε
$@2 -> ε
class -> keyword_class $@1 tSTRING '!' keyword_end $@2
$@3 -> ε
$@4 -> ε
class -> keyword_class $@3 tSTRING '?' keyword_end $@4
strings_1 -> string_1
strings_2 -> string_1
strings_2 -> string_2
string_1 -> string
string_2 -> string '+'
string -> tSTRING
unused -> tNUMBER

After:

❯ exe/lrama --trace=rules ./spec/fixtures/common/basic.y
Grammar rules:
$accept -> program EOI
program -> class
program -> '+' strings_1
program -> '-' strings_2
class -> keyword_class tSTRING keyword_end
class -> keyword_class tSTRING '!' keyword_end
class -> keyword_class tSTRING '?' keyword_end
strings_1 -> string_1
strings_2 -> string_1
strings_2 -> string_2
string_1 -> string
string_2 -> string '+'
string -> tSTRING
unused -> tNUMBER

This PR, midrule actions should not be included when tracing rules.

Before:
```
❯ exe/lrama --trace=rules ./spec/fixtures/common/basic.y
Grammar rules:
$accept -> program EOI
program -> class
program -> '+' strings_1
program -> '-' strings_2
class -> keyword_class tSTRING keyword_end
$@1 -> ε
$@2 -> ε
class -> keyword_class $@1 tSTRING '!' keyword_end $@2
$@3 -> ε
$@4 -> ε
class -> keyword_class $@3 tSTRING '?' keyword_end $@4
strings_1 -> string_1
strings_2 -> string_1
strings_2 -> string_2
string_1 -> string
string_2 -> string '+'
string -> tSTRING
unused -> tNUMBER
```

After:
```
❯ exe/lrama --trace=rules ./spec/fixtures/common/basic.y
Grammar rules:
$accept -> program EOI
program -> class
program -> '+' strings_1
program -> '-' strings_2
class -> keyword_class tSTRING keyword_end
class -> keyword_class tSTRING '!' keyword_end
class -> keyword_class tSTRING '?' keyword_end
strings_1 -> string_1
strings_2 -> string_1
strings_2 -> string_2
string_1 -> string
string_2 -> string '+'
string -> tSTRING
unused -> tNUMBER
```
@yui-knk
Copy link
Collaborator

yui-knk commented Jan 4, 2025

I think trace is used for debug in such case it's beneficial to render information as far as possible.
So that I want to keep to render mid-rule actions too.

@ydah
Copy link
Member Author

ydah commented Jan 4, 2025

Thank you. I certainly agree with outputting as much information as possible in trace.

I would be happy to see only the grammar rules and exclude actions, when I research structure of grammar rule. What do you think about adding an option to trace, for example, like only_rules?

@yui-knk
Copy link
Collaborator

yui-knk commented Jan 6, 2025

I agree to add new option to --trace, what do you think about only-rules (not _ but -)?

[Added]
The rules for mid-rule actions, like $@1 -> ε, are also rules which parser generator internally creates.
So that I prefer only-explicit-rules or something like that.

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