Skip to content

Commit 006f2a9

Browse files
fix(discover): split dep-rule targets on every D whitespace
is_dep_rule_line split targets only on space, tab and CR, so valid D such as "import\fstd.stdio : writeln;" kept the keyword and the dotted module name in one path-like target and was dropped as dep-info. Vertical tab, form feed and the UTF-8 separators U+2028/U+2029 now split targets too. Over 12,062 real D files and 4,494 real files under deps/ dirs, no classification changes. Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
1 parent ceb729d commit 006f2a9

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/discover/language.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,20 @@ static bool is_rule_colon(const char *p, bool whole_file) {
13381338
(next == '\0' && whole_file));
13391339
}
13401340

1341+
/* Bytes of D whitespace at p, or 0: space, tab, vertical tab, form feed, CR
1342+
* and the UTF-8 line and paragraph separators U+2028/U+2029, all of which split
1343+
* D tokens. '\n' ends the line and is the caller's. */
1344+
static size_t d_space_len(const char *p) {
1345+
if (*p == ' ' || *p == '\t' || *p == '\v' || *p == '\f' || *p == '\r') {
1346+
return SKIP_ONE;
1347+
}
1348+
if (strncmp(p, "\xE2\x80\xA8", SLEN("\xE2\x80\xA8")) == 0 ||
1349+
strncmp(p, "\xE2\x80\xA9", SLEN("\xE2\x80\xA9")) == 0) {
1350+
return SLEN("\xE2\x80\xA8");
1351+
}
1352+
return 0;
1353+
}
1354+
13411355
/* True if the line at p is a make rule "target...: prereq..." whose targets all
13421356
* look like paths (contain '/', '\' or '.'); a backslash-escaped space stays
13431357
* inside its target. D source fails this: "public:", "@safe:", "extern(C):"
@@ -1353,12 +1367,14 @@ static bool is_dep_rule_line(const char *p, bool whole_file) {
13531367
if (is_rule_colon(p, whole_file)) {
13541368
return in_target ? path_like : any_target;
13551369
}
1356-
if (*p == ' ' || *p == '\t' || *p == '\r') {
1370+
size_t space = d_space_len(p);
1371+
if (space) {
13571372
if (in_target && !path_like) {
13581373
return false;
13591374
}
13601375
in_target = false;
13611376
path_like = false;
1377+
p += space - SKIP_ONE;
13621378
continue;
13631379
}
13641380
if (strchr("(){};=\"',@", *p)) {

‎tests/test_language.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,16 @@ TEST(lang_d_source_stays_dlang) {
886886
ASSERT_EQ(disambiguate_d_content("public/**/:\nvoid f() {}\n"), CBM_LANG_DLANG);
887887
ASSERT_EQ(disambiguate_d_content("public/+ +/:\nvoid f() {}\n"), CBM_LANG_DLANG);
888888
ASSERT_EQ(disambiguate_d_content("public//note: x\nvoid f() {}\n"), CBM_LANG_DLANG);
889+
/* Every D whitespace splits tokens, not only space, tab and CR: form feed,
890+
* vertical tab, U+2028 and U+2029. */
891+
ASSERT_EQ(disambiguate_d_content("import\fstd.stdio : writeln;\n"), CBM_LANG_DLANG);
892+
ASSERT_EQ(disambiguate_d_content("import\vstd.stdio : writeln;\n"), CBM_LANG_DLANG);
893+
ASSERT_EQ(disambiguate_d_content("import\xE2\x80\xA8"
894+
"std.stdio : writeln;\n"),
895+
CBM_LANG_DLANG);
896+
ASSERT_EQ(disambiguate_d_content("import\xE2\x80\xA9"
897+
"std.stdio : writeln;\n"),
898+
CBM_LANG_DLANG);
889899
/* Default on doubt: empty or unreadable. */
890900
ASSERT_EQ(disambiguate_d_content(""), CBM_LANG_DLANG);
891901
ASSERT_EQ(cbm_disambiguate_d("/tmp/nonexistent_file_12345.d"), CBM_LANG_DLANG);

0 commit comments

Comments
 (0)