Add --state option for state machine inspection - #34
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new --state option to the rustylr executable for inspecting specific parser states. This feature enables developers to debug and understand parser state machines by examining production rules, shift/goto mappings, reduce actions, and state transitions for any given state.
Key changes:
- Added
--statecommand-line argument to specify a state index for inspection - Implemented detailed state inspection logic that displays production rules, transitions, and source states
- Updated documentation to explain the new feature with examples
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| rusty_lr_executable/src/arg.rs | Added state field to Args struct for the new command-line option |
| rusty_lr_executable/src/main.rs | Implemented state inspection logic with formatted output of state details |
| rusty_lr_buildscript/src/output.rs | Added grammar field to Output struct to expose grammar data |
| rusty_lr_buildscript/src/lib.rs | Updated Output construction to include grammar field |
| rusty_lr_executable/README.md | Added documentation section explaining the --state option with example usage |
| README.md | Reordered installation methods and updated recommendation text |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let rule = out.grammar.builder.rules[rule.rule] | ||
| .rule | ||
| .clone() | ||
| .map(&term_class_map, &nonterm_map) | ||
| .into_shifted(rule.shifted); |
There was a problem hiding this comment.
The .clone() operation on line 68 creates unnecessary copies of rule data. Consider using references or borrowing instead of cloning for better performance, especially when processing large grammars with many rules.
| .map(|rule| { | ||
| out.grammar.builder.rules[*rule] | ||
| .rule | ||
| .clone() |
There was a problem hiding this comment.
Another unnecessary .clone() operation that duplicates rule data. This compounds the performance issue since it occurs within a loop over rules, potentially creating many unnecessary allocations.
| .clone() |
Add
--state %doption to the executable for direct state machine inspection