refactor: expand QuoteState usage and enhance ContextStack#322
Merged
Conversation
Replace inline quote skip logic with QuoteState for consistency with the rest of the codebase.
Replace 4 manual quote tracking variables with 2 QuoteState objects:
- quote: top-level quote state
- brace_quote: quote state inside ${...}
Reduces variable count from 7 to 4 (keeping depth vars and bracket_in_double_quote).
Replace inline quote skip logic with QuoteState tracking for consistency with the rest of the codebase.
Replace inline quote skip logic with QuoteState tracking for consistency. Also tracks backtick state with a separate variable.
Add case_depth, arith_depth, arith_paren_depth fields to ParseContext and convenience methods to ContextStack: - enter_case/exit_case/in_case/get_case_depth - enter_arithmetic/exit_arithmetic/in_arithmetic - inc_arith_paren/dec_arith_paren/get_arith_paren_depth
Summary of changes in this branch: - Word._find_matching_paren: converted to QuoteState - Word._strip_locale_string_dollars: converted to QuoteState objects - _lookahead_for_esac: converted to QuoteState - _skip_heredoc: converted to QuoteState - ContextStack: added case/arithmetic tracking infrastructure Key insight: boundary detection functions (finding where $(...) ends) appropriately use local depth variables since they scan strings rather than maintain parsing context. ContextStack infrastructure is available for future parsing context needs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
QuoteState conversions:
Word._find_matching_paren- use QuoteState instead of inline scanWord._strip_locale_string_dollars- use QuoteState objects for nested contexts (7 vars → 4)_lookahead_for_esac- use QuoteState instead of inline scan_skip_heredoc- use QuoteState instead of inline scanContextStack enhancements:
case_depth,arith_depth,arith_paren_depthfields to ParseContextenter_case,exit_case,in_case,get_case_depthenter_arithmetic,exit_arithmetic,in_arithmeticinc_arith_paren,dec_arith_paren,get_arith_paren_depthNotes
Analysis revealed that boundary detection functions (finding where
$(...)ends) appropriately use local depth variables since they scan strings to find delimiters. ContextStack infrastructure is now available for future parsing context needs.