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 Inlining #369

Merged
merged 11 commits into from
Apr 2, 2024
Merged

Introduce Inlining #369

merged 11 commits into from
Apr 2, 2024

Conversation

ydah
Copy link
Collaborator

@ydah ydah commented Feb 9, 2024

This PR implements the Inlining feature in Menhir in Lrama.

@ydah ydah force-pushed the inline branch 3 times, most recently from 0301414 to 15d7e3f Compare February 14, 2024 16:18
@ydah ydah changed the title [WIP] Introduce Inlining [PoC] Introduce Inlining Mar 6, 2024
@ydah ydah force-pushed the inline branch 5 times, most recently from fd4f102 to e84d38b Compare March 21, 2024 17:53
@ydah ydah changed the title [PoC] Introduce Inlining Introduce Inlining Mar 21, 2024
parser.y Outdated Show resolved Hide resolved
@ydah ydah requested a review from yui-knk March 30, 2024 18:34
parser.y Show resolved Hide resolved
@ydah ydah requested a review from yui-knk April 1, 2024 04:42
def find(token)
select_rules(token).last
def find_rule(token)
if token.is_a?(Lexer::Token::InstantiateRule)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for this check?
As far as I read the code, caller of this method (

when Lrama::Lexer::Token::InstantiateRule
) ensures token is a InstantiateRule. If there is not reason to return nil for other than InstantiateRule, it's better to raise an error whose message includes BUG.

Copy link
Collaborator Author

@ydah ydah Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it is! Thank you. The conditional expression is removed here because it is impossible to get an error. I updated this PR: bba8995

@@ -25,7 +31,7 @@ def created_lhs(lhs_s_value)

def select_rules(token)
rules = select_rules_by_name(token.rule_name)
rules = rules.select { |rule| rule.required_parameters_count == token.args_count }
rules = rules.select { |rule| rule.required_parameters_count == token.args_count && !rule.is_inline }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits] It might be better to extract rules.select {|rule| !rule.is_inline} into another method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good. I updated this PR: 6928bc8

@@ -52,12 +57,16 @@ def complete_input

def setup_rules(parameterizing_rule_resolver)
preprocess_references unless @skip_preprocess_references
process_rhs(parameterizing_rule_resolver)
if rhs.any? { |token| parameterizing_rule_resolver.find_inline(token) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] In the future, we need to change this condition otherwise lrama can not handle production rules whose RHS include both parameterizing rules and inline rules.

@yui-knk
Copy link
Collaborator

yui-knk commented Apr 1, 2024

@ydah Reviewed. The direction is ok for me.

@yui-knk
Copy link
Collaborator

yui-knk commented Apr 1, 2024

This PR is the first step to support inline rule in Lrama. Then only support primitive functionality, for example nested inline rules and combination of inline rules and non inline rules are not supported now.

@ydah
Copy link
Collaborator Author

ydah commented Apr 1, 2024

@yui-knk Thank you for your review! I updated this PR.

@ydah ydah requested a review from yui-knk April 1, 2024 17:21
def created_lhs(lhs_s_value)
@created_lhs_list.reverse.find { |created_lhs| created_lhs.s_value == lhs_s_value }
end

private

def select_rules(token)
rules = select_not_inline_rules
rules = select_rules_by_name(token.rule_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the result o line 31 is not used by line 32 and overwrote by line 32. Is something wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😨 My apologies... I updated it.

@ydah ydah requested a review from yui-knk April 2, 2024 02:30
@yui-knk yui-knk merged commit 80fd926 into ruby:master Apr 2, 2024
16 checks passed
@yui-knk
Copy link
Collaborator

yui-knk commented Apr 2, 2024

Thank you!

@ydah ydah deleted the inline branch April 2, 2024 03:09
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