Skip to content

Removed inner Context wrapping & add generic based start extractor#86

Merged
ehwan merged 6 commits into
mainfrom
remove_data_stack
Jun 26, 2026
Merged

Removed inner Context wrapping & add generic based start extractor#86
ehwan merged 6 commits into
mainfrom
remove_data_stack

Conversation

@ehwan

@ehwan ehwan commented Jun 26, 2026

Copy link
Copy Markdown
Owner

1. Transition of DataStack -> SemanticValue

  • Removed the DataStack trait and replaced it with the SemanticValue trait.
  • While the previous DataStack was a trait representing Vec<Enum Value>, the new SemanticValue represents a single Enum Value.
  • It will include new_empty(), new_terminal( term ), and reduce_action() functions.
  • The Context will now hold Vec<SemanticValue> instead of DataStack.
  • Previously, a Context wrapper was created only when there were two or more start_rule_names. However, since SemanticValue alone cannot determine the StartType or extract the inner value, a Context wrapper will now be created even if there is only one start_rule_name.
  • Implemented accept and accept_all within the wrapper.
  • In accept, it calls feed_eof(), pops one EOF, pops one value, and then extracts and returns the value corresponding to Start using a match expression on the spot.
  • Since the Context wrapper is implemented regardless of the number of start_rule_names, the conditional if branching based on the count of start_rule_names in emit.rs was removed.

2. Removed inner Context wrapping & add generic based start extractor

  • Removed the wrapping with an inner Context. Instead, decided to simply apply an alias to the original rusty_lr_core's Context.
  • Hidden all branch-related elements in Context so they are not visible to the user.
  • Moved branch-related and StartType-related elements into Generics.
  • For extracting Start data from SemanticValue inside accept, created a separate trait or struct in emit (e.g., <Start1>Extracter, <Start2>Extracter) and had Context hold it.
  • With this setup, implementations like Clone or Display for Context can be automatically handled by moving them to trait bounds.

@ehwan ehwan self-assigned this Jun 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the parser stack representation in rusty_lr by replacing the custom DataStack trait with a new SemanticValue trait and a StartExtractor trait. This allows the deterministic and non-deterministic Context implementations to store semantic values directly in a standard Vec, simplifying the generated code structure and removing the need to generate individual DataStack wrapper structs. Additionally, the documentation, examples, and tests have been updated to reflect these changes. Feedback on this PR suggests improving error handling in the deterministic Context::accept method by replacing a generic .unwrap() with a descriptive panic message via .unwrap_or_else(), ensuring consistency with the non-deterministic implementation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Ok((self.data_stack.pop_start().unwrap(), self.userdata))
// pop eof
self.data_stack.pop();
let start = self.data_stack.pop().unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using .unwrap() here can lead to a generic panic without context if the stack is unexpectedly empty. It is safer and more consistent with the non-deterministic context implementation (and the very next line) to use .unwrap_or_else() with a descriptive panic message.

        let start = self.data_stack.pop().unwrap_or_else(|| {\n            panic!(\n                \"Accepted path for virtual start branch {} has no start value\",\n                Start::BRANCH_INDEX\n            )\n        });

@ehwan
ehwan merged commit 79a5a04 into main Jun 26, 2026
1 check passed
@ehwan
ehwan deleted the remove_data_stack branch June 26, 2026 22:30
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.

1 participant