Skip to content

Commit fc79767

Browse files
committed
Improve parsing of compiler conditions
1 parent c876895 commit fc79767

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/hx/doctest/internal/SourceFile.hx

+12-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ class SourceFile {
6161
return fileInput == null || fileInput.eof();
6262

6363

64+
function extractCondition(line:String, startToken:String) {
65+
var condition = line.substringAfter(startToken);
66+
if (condition.contains("#else")) condition = condition.substringBefore("#else");
67+
if (condition.contains("/*")) condition = condition.substringBefore("/*");
68+
if (condition.contains("//")) condition = condition.substringBefore("//");
69+
return condition.trim();
70+
}
71+
72+
6473
public function nextLine():Bool {
6574
while (!isLastLine()) {
6675
var line:String;
@@ -81,17 +90,17 @@ class SourceFile {
8190
}
8291

8392
if (lineTrimmed.startsWith("#if ")) {
84-
currentLine = CompilerConditionStart(lineTrimmed.substringAfter("#if ").trim());
93+
currentLine = CompilerConditionStart(extractCondition(lineTrimmed, "#if "));
8594
return true;
8695
}
8796

8897
if (lineTrimmed.startsWith("#elseif ")) {
89-
currentLine = CompilerConditionElseIf(lineTrimmed.substringAfter("#elseif ").trim());
98+
currentLine = CompilerConditionElseIf(extractCondition(lineTrimmed, "#elseif "));
9099
return true;
91100
}
92101

93102
if (lineTrimmed.startsWith("#else if ")) {
94-
currentLine = CompilerConditionElseIf(lineTrimmed.substringAfter("#else if ").trim());
103+
currentLine = CompilerConditionElseIf(extractCondition(lineTrimmed, "#else if "));
95104
return true;
96105
}
97106

0 commit comments

Comments
 (0)