Decompose _parseBlock (447 lines) into directive/fenced/body/type-inference phases #53
No reviewers
Labels
No labels
accepted
bug
declined
docs
duplicate
enhancement
good first issue
in-progress
needs-info
privacy
security
triage
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
LibreKAT/Ocideck!53
Loading…
Reference in a new issue
No description provided.
Delete branch "refactor/decompose-parseblock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The parse counterpart to #52.
_parseBlockwas the single largest method in the tree at 447 lines, doing four jobs at once. It is decomposed into named phases (all kept in themarkdown_service_parsepart), leaving_parseBlocka thin orchestrator:_parseBlockDirectives<!-- _class -->marker + every directive comment (advance/skip/tlp/_style/two-bullets/timeline/list-style/checklist/title/bullet-marker); returns the stripped body + decoded values_tryFencedSlide_parseBodyLines_inferSlideTypeSlideTypefrom class tokens, else from contentWhy this is safe
The method bodies move verbatim (only wrapped in the new methods and threaded through plain records;
bulletsis passed by reference so it still accumulates in place). The parse result is therefore identical — proven by the round-trip (65 tests) and adversarial fuzz (53 tests) suites, which serialise a deck then re-parse it and compare every field.On the ceiling
_parseBodyLinesremains a single 229-line state machine over ~20 accumulated fields. Splitting it further needs a mutable state-holder that would relocate the same code with real transcription risk and little readability gain, so I stopped there. The worst-method ceiling for this file still drops 447 → 229: the_parseBlockbaseline entry is replaced by a_parseBodyLinesone (count unchanged at 27 baselined). A future PR can take it under 150 with a holder if desired.Verification
flutter analyze --fatal-infos— cleanflutter test— 921 passed, incl. round-trip (65) and fuzz (53)dart run tool/check_method_length.dart— green (27 baselined)dart format— clean_parseBlock was a 447-line method doing four jobs at once. It is split into named phases, all kept in the markdown_service_parse part: * _parseBlockDirectives — parse the <!-- _class --> marker and every other directive comment (advance/skip/tlp/_style/two-bullets/timeline/list- style/checklist/title/bullet-marker), returning the stripped body + the decoded values; * _tryFencedSlide — delegate code/chart/cockpit/question slides up front; * _parseBodyLines — walk the body lines into headings/bullets/images/ captions/video/audio/quote/table content; * _inferSlideType — pick the SlideType from class tokens, else content. _parseBlock is now a thin orchestrator. The bodies are moved verbatim, so the parse result is identical — proven by the round-trip and adversarial fuzz suites (which serialise then re-parse and compare every field). The body-line walker stays a single 229-line state machine over ~20 accumulated fields: splitting it further needs a mutable holder that would relocate the same code with real transcription risk and little gain. So the worst-method ceiling for this file drops from 447 to 229 — the _parseBlock baseline entry is replaced by a _parseBodyLines one (still 27 baselined).