Skip to content

Commit 97244a5

Browse files
committed
Fix parsing errors on implementation keywords in conditional branches
1 parent 627908f commit 97244a5

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,9 +1503,9 @@ COMMENT : '//' ~('\n'|'\r')* {$channel
15031503

15041504
if ($text.startsWith(start + "\$")) {
15051505
$type = TkCompilerDirective;
1506-
if ($text.startsWith(start + "\$endif") || $text.startsWith(start + "\$ifend")) {
1506+
if ($text.startsWithIgnoreCase(start + "\$endif") || $text.startsWithIgnoreCase(start + "\$ifend")) {
15071507
--directiveNesting;
1508-
} else if ($text.startsWith(start + "\$if")) {
1508+
} else if ($text.startsWithIgnoreCase(start + "\$if")) {
15091509
++directiveNesting;
15101510
}
15111511
}

delphi-frontend/src/test/java/au/com/integradev/delphi/file/DelphiFileTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
*/
1919
package au.com.integradev.delphi.file;
2020

21-
import static org.assertj.core.api.Assertions.assertThat;
22-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
21+
import static org.assertj.core.api.Assertions.*;
2322

2423
import au.com.integradev.delphi.compiler.Platform;
2524
import au.com.integradev.delphi.core.Delphi;
@@ -36,6 +35,8 @@
3635
import java.nio.charset.StandardCharsets;
3736
import java.util.Collections;
3837
import org.junit.jupiter.api.Test;
38+
import org.junit.jupiter.params.ParameterizedTest;
39+
import org.junit.jupiter.params.provider.ValueSource;
3940
import org.sonar.api.batch.fs.InputFile;
4041
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
4142

@@ -106,4 +107,21 @@ void testByteOrderMarkShouldBeStripped() {
106107
String firstLine = delphiFile.getSourceCodeFileLines().get(0);
107108
assertThat(firstLine).doesNotStartWith("\ufeff");
108109
}
110+
111+
@ParameterizedTest
112+
@ValueSource(strings = {"SkipImplementation.pas", "SkipImplementationWithDirectiveNesting.pas"})
113+
void testShouldSkipImplementation(String filename) {
114+
File file = DelphiUtils.getResource("/au/com/integradev/delphi/file/" + filename);
115+
116+
DelphiFileConfig config =
117+
DelphiFile.createConfig(
118+
StandardCharsets.UTF_8.name(),
119+
new DelphiPreprocessorFactory(Platform.WINDOWS),
120+
TypeFactoryUtils.defaultFactory(),
121+
SearchPath.create(Collections.emptyList()),
122+
Collections.emptySet(),
123+
true);
124+
125+
assertThatNoException().isThrownBy(() -> DelphiFile.from(file, config));
126+
}
109127
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
unit SkipImplementation;
2+
3+
interface
4+
5+
implementation
6+
7+
ERROR
8+
9+
end.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
unit SkipImplementationWithDirectiveNesting;
2+
3+
interface
4+
5+
{$If False}
6+
type
7+
TFoo = ERROR class
8+
emd;
9+
implementation
10+
{$eLsE}
11+
implementation
12+
{$endif}
13+
14+
end.

0 commit comments

Comments
 (0)