The current implementation of the columns() function involves manual parsing logic, including custom buffering and parenthesis balancing, as well as several private helper functions (skip_to_lparen, process_token, handle_rparen, handle_comma, add_column_if_non_empty). This approach increases code complexity and maintenance overhead.
It is suggested to simplify columns() by leveraging the existing extract_parenthesized utility function (presumably in parse_utils.rs or syntax_utils.rs). This function can extract the content between the first matching pair of parentheses. Once extracted, the string can be split on commas, trimmed, and filtered for non-empty values, resulting in a much simpler and more maintainable implementation.
Proposed refactor:
use crate::parse_utils::extract_parenthesized;
pub fn columns(&self) -> Vec<String> {
// grab everything between the first '(' and matching ')'
let inside = extract_parenthesized(
&self.syntax,
SyntaxKind::T_LPAREN,
SyntaxKind::T_RPAREN,
).unwrap_or_default();
// split on commas and trim
inside
.split(',')
.map(str::trim)
.filter(|s| !s.is_empty())
.map(String::from)
.collect()
}
Action items:
- Refactor
columns() to use extract_parenthesized and simple string splitting as shown above.
- Remove the now-unnecessary private helper functions listed above.
- Ensure all existing tests pass and add new tests if needed to cover edge cases.
This change will reduce code complexity and improve maintainability without altering the function's behavior.
I created this issue for @leynos from #89 (comment).
Tips and commands
Getting Help
The current implementation of the
columns()function involves manual parsing logic, including custom buffering and parenthesis balancing, as well as several private helper functions (skip_to_lparen,process_token,handle_rparen,handle_comma,add_column_if_non_empty). This approach increases code complexity and maintenance overhead.It is suggested to simplify
columns()by leveraging the existingextract_parenthesizedutility function (presumably inparse_utils.rsorsyntax_utils.rs). This function can extract the content between the first matching pair of parentheses. Once extracted, the string can be split on commas, trimmed, and filtered for non-empty values, resulting in a much simpler and more maintainable implementation.Proposed refactor:
Action items:
columns()to useextract_parenthesizedand simple string splitting as shown above.This change will reduce code complexity and improve maintainability without altering the function's behavior.
I created this issue for @leynos from #89 (comment).
Tips and commands
Getting Help