Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ydah
Copy link
Member

@ydah ydah commented Jan 1, 2025

This PR, add 'only-explicit-rules' option to display explicit grammar rules.

--trace=rules:

❯ 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

--trace=only-explicit-rules:

❯ exe/lrama --trace=only-explicit-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.

ydah added 2 commits January 9, 2025 14:50
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
```
@ydah ydah force-pushed the improve-trace-rules branch from e05bcf8 to 5a4901b Compare January 9, 2025 07:13
@ydah ydah changed the title Do not include mid-rule actions when tracing rules Add 'only-explicit-rules' option to display explicit grammar rules Jan 9, 2025
@ydah
Copy link
Member Author

ydah commented Jan 9, 2025

@yui-knk Thank you for your suggestion! The only-explicit-rules option has been added to --trace.

@ydah ydah requested a review from yui-knk January 11, 2025 13:02
@ydah ydah merged commit 79387f4 into ruby:master Jan 12, 2025
22 checks passed
@ydah ydah deleted the improve-trace-rules branch January 12, 2025 03:16
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