Skip to content

refactor: modularize replace_rarrows and segment-splitting logic - #186

Open
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-cognitive-complexity-sugar
Open

refactor: modularize replace_rarrows and segment-splitting logic#186
bhagathkrishnacdac wants to merge 1 commit into
omec-project:mainfrom
bhagathkrishnacdac:bess-cognitive-complexity-sugar

Conversation

@bhagathkrishnacdac

Copy link
Copy Markdown

Description
This PR refactors replace_rarrows inside sugar.py to resolve cognitive complexity. The original monolithic function, which managed lexical analysis, string slicing, token boundaries, and nested gate checks, has been broken down into single-responsibility helpers.

Key Changes

  • Separated Tokenizer Scans (find_arrow_positions): Moved the Python 2/3 lexical analysis scan for right-arrow operators (->) into an isolated helper.
  • Streamlined Segment Splitting (split_string_by_arrows): Extracted the complex string index/offset tracking loops used to partition configuration strings. Replaced assert False with an explicit RuntimeError to prevent optimizations from bypassing errors.
  • Decoupled Gate Transformation:
    • Extracted process_output_gate and process_input_gate to independently handle colon searches and gate expressions formatting.
    • Extracted parenthesize into a standalone, safe utility function.

Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
@bhagathkrishnacdac
bhagathkrishnacdac requested a review from a team August 2, 2026 18:52
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