Skip to content

refactor: expand QuoteState usage and enhance ContextStack#322

Merged
ldayton merged 7 commits intomainfrom
quote-state-rollout
Jan 17, 2026
Merged

refactor: expand QuoteState usage and enhance ContextStack#322
ldayton merged 7 commits intomainfrom
quote-state-rollout

Conversation

@ldayton
Copy link
Copy Markdown
Owner

@ldayton ldayton commented Jan 16, 2026

Summary

  • Convert 4 functions from inline quote skip logic to QuoteState tracking
  • Add case/arithmetic depth tracking helpers to ContextStack infrastructure

Changes

QuoteState conversions:

  • Word._find_matching_paren - use QuoteState instead of inline scan
  • Word._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 scan

ContextStack enhancements:

  • Add case_depth, arith_depth, arith_paren_depth fields to ParseContext
  • Add helper methods: enter_case, exit_case, in_case, get_case_depth
  • Add helper methods: enter_arithmetic, exit_arithmetic, in_arithmetic
  • Add helper methods: inc_arith_paren, dec_arith_paren, get_arith_paren_depth

Notes

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.

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.
@ldayton ldayton enabled auto-merge (squash) January 16, 2026 23:57
@ldayton ldayton merged commit 1fff537 into main Jan 17, 2026
1 check passed
@ldayton ldayton deleted the quote-state-rollout branch January 17, 2026 00:05
ldayton added a commit that referenced this pull request Mar 25, 2026
Includes fixes for JS backend: constructor defaults (#321), startswith
pos arg (#324), operator precedence (#333), regex escaping (#322),
template literal backticks (#323), destructuring discard (#326),
isinstance primitives (#325, #327), backtick-heredoc (#352), and
UTF-8 encoding (#334).
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