Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a variable substitution feature to the grammar parser, allowing the use of variables prefixed with $ inside RustCode blocks to reduce boilerplate. It also implements compile-time checks for circular dependencies, maximum recursion depth, and missing filter definitions. The review feedback highlights several performance optimization opportunities in the substitution resolution logic within rusty_lr_parser/src/grammar.rs, specifically focusing on reducing redundant heap allocations, caching formatted keys, and avoiding duplicate span manager lookups.
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.
| }); | ||
| } | ||
|
|
||
| if stack.contains(&name.to_string()) { |
There was a problem hiding this comment.
Using stack.contains(&name.to_string()) performs a redundant heap allocation of a String on every lookup. Since stack is a Vec<String> and name is a &str, you can perform the lookup without any allocation by using stack.iter().any(|s| s == name).
| if stack.contains(&name.to_string()) { | |
| if stack.iter().any(|s| s == name) { |
| } else if providers.contains_key(&format!("term:{}", ident_name)) { | ||
| iter.next(); | ||
| let resolved = resolve_provider( | ||
| &format!("term:{}", ident_name), | ||
| providers, | ||
| span_manager, | ||
| stack, | ||
| depth, | ||
| max_depth, | ||
| ref_loc, | ||
| )?; | ||
| result.extend(resolved); | ||
| continue; | ||
| } else if providers.contains_key(&format!("nonterm:{}", ident_name)) { | ||
| iter.next(); | ||
| let resolved = resolve_provider( | ||
| &format!("nonterm:{}", ident_name), | ||
| providers, | ||
| span_manager, | ||
| stack, | ||
| depth, | ||
| max_depth, | ||
| ref_loc, | ||
| )?; | ||
| result.extend(resolved); | ||
| continue; | ||
| } else { | ||
| // TODO: 이거 워닝으로 내면 좋을듯 | ||
| } |
There was a problem hiding this comment.
The keys format!("term:{}", ident_name) and format!("nonterm:{}", ident_name) are formatted twice: once for the contains_key check and once when calling resolve_provider. We can avoid these redundant string allocations by formatting the keys once into local variables and reusing them.
} else {
let term_key = format!("term:{}", ident_name);
if providers.contains_key(&term_key) {
iter.next();
let resolved = resolve_provider(
&term_key,
providers,
span_manager,
stack,
depth,
max_depth,
ref_loc,
)?;
result.extend(resolved);
continue;
}
let nonterm_key = format!("nonterm:{}", ident_name);
if providers.contains_key(&nonterm_key) {
iter.next();
let resolved = resolve_provider(
&nonterm_key,
providers,
span_manager,
stack,
depth,
max_depth,
ref_loc,
)?;
result.extend(resolved);
continue;
}
// TODO: 이거 워닝으로 내면 좋을듯
}
Description
This Pull Request introduces
$filtervariable substitution withinRustCodeblocks, simplifies the non-terminal substitution syntax to$NonTerminalName(replacing the bracketed$<NonTerminal>syntax), implements fallback preservation for unknown variables, and enhances compile-time diagnostics insiderusty_lr_buildscript.Changes
1. Simplified Variable Substitution & Fallback Behavior
$NonTerminalNameinstead of$<NonTerminal>. Updatedsubstitute_streamingrammar.rsto support lookup directly.$is followed by an unknown identifier, it is preserved in the token stream unchanged (along with a// TODO: 이거 워닝으로 내면 좋을듯comment) instead of producing an error.$filterSubstitution: Resolved$filterto evaluate to the user-defined filter function if%filteris specified.2. Diagnostics inside
rusty_lr_buildscriptArgError::MultipleLocationDefinition(locs)ArgError::MultipleFilterDefinition(locs)ParseError::CircularDependency { location, path }ParseError::MaxSubstitutionDepthExceeded { location, max_depth }ParseError::FilterNotDefined(loc)CircularDependency,MaxSubstitutionDepthExceeded, andFilterNotDefined), added warning notes containing links pointing directly to the#substitution-errorssection inSYNTAX.mdon GitHub.3. Error Definition Cleanup & Documentation
LocationTypeNotDefinedandTokenTypeNotDefinedparse errors since their validations occur earlier inside argument checks.SYNTAX.mdto document the new$filtervariable, the simplified$NonTerminalNamesyntax, and the three variable substitution error types (CircularDependency,MaxSubstitutionDepthExceeded, andFilterNotDefined).