Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Parsing errors on `implementation` keywords nested in conditional branches.

## [1.10.0] - 2024-10-01

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import au.com.integradev.delphi.antlr.ast.node.*;

package au.com.integradev.delphi.antlr;

import org.apache.commons.lang3.StringUtils;
}

@lexer::members {
Expand Down Expand Up @@ -1503,9 +1504,9 @@ COMMENT : '//' ~('\n'|'\r')* {$channel

if ($text.startsWith(start + "\$")) {
$type = TkCompilerDirective;
if ($text.startsWith(start + "\$endif") || $text.startsWith(start + "\$ifend")) {
if (StringUtils.startsWithIgnoreCase($text, start + "\$endif") || StringUtils.startsWithIgnoreCase($text, start + "\$ifend")) {
--directiveNesting;
} else if ($text.startsWith(start + "\$if")) {
} else if (StringUtils.startsWithIgnoreCase($text, start + "\$if")) {
++directiveNesting;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
package au.com.integradev.delphi.file;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.*;

import au.com.integradev.delphi.compiler.Platform;
import au.com.integradev.delphi.core.Delphi;
Expand All @@ -36,6 +35,8 @@
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;

Expand Down Expand Up @@ -106,4 +107,21 @@ void testByteOrderMarkShouldBeStripped() {
String firstLine = delphiFile.getSourceCodeFileLines().get(0);
assertThat(firstLine).doesNotStartWith("\ufeff");
}

@ParameterizedTest
@ValueSource(strings = {"SkipImplementation.pas", "SkipImplementationWithDirectiveNesting.pas"})
void testShouldSkipImplementation(String filename) {
File file = DelphiUtils.getResource("/au/com/integradev/delphi/file/" + filename);

DelphiFileConfig config =
DelphiFile.createConfig(
StandardCharsets.UTF_8.name(),
new DelphiPreprocessorFactory(Platform.WINDOWS),
TypeFactoryUtils.defaultFactory(),
SearchPath.create(Collections.emptyList()),
Collections.emptySet(),
true);

assertThatNoException().isThrownBy(() -> DelphiFile.from(file, config));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
unit SkipImplementation;

interface

implementation

ERROR

end.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
unit SkipImplementationWithDirectiveNesting;

interface

{$If False}
type
TFoo = ERROR class
emd;
implementation
{$eLsE}
implementation
{$endif}

end.
Loading