Skip to content

Commit b3d1732

Browse files
committed
Fix indentation in initialization/finalization sections
The sections were not being classified as statement lists by the parser, which threw the comment handling and the child line parsing code off.
1 parent 4aaf1be commit b3d1732

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
### Fixed
1111

1212
- Fixed formatting of `resourcestring` sections.
13+
- Fixed indentation inside `initialization`/`finalization` sections.
1314

1415
## [0.5.0] - 2025-03-31
1516

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Fixed parsing of `threadvar` sections in anonymous procedures.
1414
This technically isn't valid code, but we allow the `threadvar` section in a regular routine, so
1515
we should also allow it in an anonymous routine, for consistency.
16+
- Fixed indentation inside `initialization`/`finalization` sections. Cases include:
17+
- Comments preceding the `finalization` keyword or the final `end`.
18+
- Comments preceding a structured statement.
19+
- Statements following a structured statement without a begin-end block.
1620

1721
### Added
1822

core/datatests/generators/logical_line_parser.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,28 @@ mod comments {
401401
",
402402
$comment
403403
),
404+
after_initialization_finalization = format!(
405+
"
406+
_|initialization
407+
_| {0}
408+
_|finalization
409+
_| {0}
410+
",
411+
$comment
412+
),
413+
after_initialization_finalization_before_child_line = format!(
414+
"
415+
_ |initialization
416+
_ | {0}
417+
_1 | if Foo then{{1}}
418+
_^1| Bar;
419+
_ |finalization
420+
_ | {0}
421+
_2 | if Foo then{{2}}
422+
_^2| Bar;
423+
",
424+
$comment
425+
),
404426
);
405427
};
406428
}
@@ -507,6 +529,13 @@ mod child_lines {
507529
3 | end);
508530
1 |end);
509531
",
532+
inside_initialization = "
533+
_ |initialization
534+
_1 | for var I := 0 to 10 do{1}
535+
_^1| Foo;
536+
_2 | for var I := 0 to 10 do{2}
537+
_^2| Bar;
538+
",
510539
);
511540
}
512541
}

core/src/defaults/parser.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,23 +330,32 @@ impl<'a, 'b> InternalDelphiLogicalLineParser<'a, 'b> {
330330
self.finish_logical_line();
331331
self.next_token();
332332
self.finish_logical_line();
333-
let mut push_section_context = |context_type, level_delta| {
334-
self.parse_block(ParserContext {
333+
let mut push_section_context = |context_type, level_delta, stmt_kind| {
334+
let ctx = ParserContext {
335335
context_type,
336336
context_ending_predicate: CEP::Opaque(section_headings),
337337
level: ParserContextLevel::Level(level_delta),
338-
});
338+
};
339+
if let Some(stmt_kind) = stmt_kind {
340+
self.parse_statement_block_with_kind(ctx, stmt_kind);
341+
} else {
342+
self.parse_block(ctx);
343+
}
339344
};
340345
match keyword_kind {
341-
KK::Interface => push_section_context(ContextType::Interface, 0),
342-
KK::Implementation => push_section_context(ContextType::Implementation, 0),
346+
KK::Interface => push_section_context(ContextType::Interface, 0, None),
347+
KK::Implementation => {
348+
push_section_context(ContextType::Implementation, 0, None)
349+
}
343350
KK::Initialization => push_section_context(
344351
ContextType::StatementBlock(BlockKind::Initialization),
345352
1,
353+
Some(StatementKind::Normal),
346354
),
347355
KK::Finalization => push_section_context(
348356
ContextType::StatementBlock(BlockKind::Finalization),
349357
1,
358+
Some(StatementKind::Normal),
350359
),
351360
_ => {}
352361
};

0 commit comments

Comments
 (0)