Skip to content

Commit 68c01bf

Browse files
committed
Fix multiline backslash comments/commands regex
1 parent 187ffbf commit 68c01bf

6 files changed

Lines changed: 32 additions & 9 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ $(INTEGRATION_TESTS): FILE_EXPECTED = /tmp/.makefile-doc_$@_expected
155155
$(INTEGRATION_TESTS): FILE_ACTUAL = /tmp/.makefile-doc_$@_actual
156156
$(INTEGRATION_TESTS): RECIPE_CMD = $(shell head -n 1 $(INTEGRATION_TEST_DIR)/$@)
157157
$(INTEGRATION_TESTS): $(AWK_BIN)/$(AWK)
158-
@echo "$(subst $,\$,$(RECIPE_CMD))" > $(FILE_CMD);
158+
@echo "$(subst $,\$,$(RECIPE_CMD))" > $(FILE_CMD)
159159
@tail -n +2 $(INTEGRATION_TEST_DIR)/$@ > $(FILE_EXPECTED)
160160
@$< -f $(MAKEFILE_DOC) $(AWK_FLAGS) $(RECIPE_CMD) \
161161
> $(FILE_ACTUAL).stdout 2> $(FILE_ACTUAL).stderr || exit 0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ without `#`). Foreground/background can be set using the tokens `FG/BG`. Unspeci
210210
+ [wak](https://github.com/raygard/wak) `v24.10`
211211
+ [goawk](https://github.com/benhoyt/goawk) `v1.29.1`
212212
+ `GNU Make`
213+
+ version 3.81 works fine for documentation generation
214+
+ I run the tests with version 4.3
213215

214216
## Running the tests
215217

makefile-doc.awk

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Author: Dimitar Dimitrov
66
# License: Apache-2.0
77
# Project: https://github.com/drdv/makefile-doc
8-
# Version: v1.6
8+
# Version: v1.7
99
#
1010
# Usage (see project README.md for more details):
1111
# awk [-v option=value] -f makefile-doc.awk [Makefile ...]
@@ -975,6 +975,9 @@ BEGIN {
975975
FILES_PROCESSED = ""
976976
SPACES_TABS_REGEX = "^[ \t]+|[ \t]+$"
977977

978+
# this is equivalent to /[^\\](\\{2})*\\$/ with an extra round of escaping
979+
ODD_NUMB_TERMINAL_BACKSLASHES_REGEX = "[^\\\\](\\\\{2})*\\\\$"
980+
978981
# used to decorate double-colon targets in the documentation
979982
DOUBLE_COLON_SEPARATOR = "~"
980983

@@ -1003,12 +1006,10 @@ FNR == 1 {
10031006
}
10041007

10051008
# Skip backslash multiline comments
1006-
# FIXME: at some point we might allow for them to constitute anchor documentation
1007-
# but for the moment they are simply ignored
1008-
/^ *#[^\\]*?([\\]{2})*\\$/ || IN_MULTILINE_BACKSLASH_COMMENT {
1009+
$0 ~ "^ *#.*" ODD_NUMB_TERMINAL_BACKSLASHES_REGEX || IN_MULTILINE_BACKSLASH_COMMENT {
10091010
if (!IN_MULTILINE_BACKSLASH_COMMENT) {
10101011
IN_MULTILINE_BACKSLASH_COMMENT = 1
1011-
} else if (!($0 ~ /^[^\\]*?([\\]{2})*\\$/)) {
1012+
} else if (!($0 ~ ODD_NUMB_TERMINAL_BACKSLASHES_REGEX)) {
10121013
IN_MULTILINE_BACKSLASH_COMMENT = 0
10131014
}
10141015

@@ -1026,9 +1027,7 @@ FNR == 1 {
10261027

10271028
IN_RULE && $0 ~ RECIPEPREFIX || IN_MULTILINE_BACKSLASH_COMMAND {
10281029
forget_descriptions_data()
1029-
1030-
# match odd number of slashes at the end
1031-
if ($0 ~ sprintf("%s[^\\\\]*?([\\\\]{2})*\\\\$", RECIPEPREFIX)) {
1030+
if ($0 ~ sprintf("%s.*%s", RECIPEPREFIX, ODD_NUMB_TERMINAL_BACKSLASHES_REGEX)) {
10321031
IN_MULTILINE_BACKSLASH_COMMAND = 1
10331032
} else {
10341033
IN_MULTILINE_BACKSLASH_COMMAND = 0

test/Makefile.backslash-comments

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ vvv5 := 1 ## 5
4040
z5:
4141
@echo $(vvv5)
4242

43+
## Spaces\ \
44+
sss2 := 1 ## 2
45+
s2:
46+
@echo $(sss2)
47+
48+
## Spaces\ \ \ \
49+
sss3 := 1 ## 3
50+
s3:
51+
@echo $(sss3)
52+
4353
## should ignore this comment and the variable
4454
## which is a part of the above recipe
4555
BAD := 1

test/Makefile.backslash-recipe

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ t5: ## i-t5
2828
@echo maybe\\\\\
2929
T5 := 1 ## v-t5 (this is not a variable)
3030

31+
## spaces between backslashes
32+
s2:
33+
@echo maybe\ \
34+
S2 := 1 ## v-s2 (this is not a variable)
35+
36+
## spaces between backslashes
37+
s3:
38+
@echo maybe\ \ \ \
39+
S3 := 1 ## v-s3 (this is not a variable)
40+
3141
t6: ## i-t6
3242
@echo maybe\
3343
T6_1 := 1 \

test/integration/test-backslash-recipe

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Available targets:
88
t3 t-t3
99
t4 t-t4
1010
t5 t-t5
11+
s2 spaces between backslashes
12+
s3 spaces between backslashes
1113
t6 i-t6
1214
t7 i-t7
1315
t8 i-t7

0 commit comments

Comments
 (0)