Skip to content

Commit

Permalink
Kconfig: make regex patterns more strict not to be fooled
Browse files Browse the repository at this point in the history
Unlike the real Kconfig processor in Linux, the Kconfig parser in ctags doesn't
consider indentation. So the keywords like "menu", "endmenu",
"choice", and "endchoice" in help messages can make the parser fooled.

To mitigating the incompleteness of the parser, this change makes
regex patterns more strict.

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Aug 23, 2024
1 parent e8578f4 commit 0d56602
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Units/parser-kconfig.r/unbalance.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--sort=no
--map-Kconfig=.kconfig
--extras-Kconfig=-{configPrefixed}
--fields=+e
--extras=+r
10 changes: 10 additions & 0 deletions Units/parser-kconfig.r/unbalance.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
A input.kconfig /^config A$/;" c typeref:typename:bool
B input.kconfig /^config B$/;" c typeref:typename:bool
Y input-0.kconfig /^menu "Y"$/;" m end:11
C input-0.kconfig /^config C$/;" c menu:Y typeref:typename:bool
D input-0.kconfig /^config D$/;" c menu:Y typeref:typename:bool
E input-1.kconfig /^config E$/;" c typeref:typename:bool
F input-1.kconfig /^config F$/;" c typeref:typename:bool
W input-2.kconfig /^choice W$/;" C end:8
G input-2.kconfig /^ config G$/;" c choice:W typeref:typename:bool
H input-3.kconfig /^config H$/;" c typeref:typename:bool
11 changes: 11 additions & 0 deletions Units/parser-kconfig.r/unbalance.d/input-0.kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
menu "Y"

config C
bool
help
endmenu - a dummy

config D
bool

endmenu
8 changes: 8 additions & 0 deletions Units/parser-kconfig.r/unbalance.d/input-1.kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config E
bool
help
choice Z0 or Z1

config F
bool

8 changes: 8 additions & 0 deletions Units/parser-kconfig.r/unbalance.d/input-2.kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
choice W
help
endchoice but this is a part of help message

config G
bool

endchoice
4 changes: 4 additions & 0 deletions Units/parser-kconfig.r/unbalance.d/input-3.kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config H
bool
help
source "V" is a part of a help message.
7 changes: 7 additions & 0 deletions Units/parser-kconfig.r/unbalance.d/input.kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config A
bool
help
menu "X" rest

config B
bool
12 changes: 6 additions & 6 deletions optlib/kconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ extern parserDefinition* KconfigParser (void)
"c", "{scope=ref}{_extra=configPrefixed}", NULL, false},
{"^[ \t]*(menu)?config[ \t]+([A-Za-z0-9_]+)[ \t]*$", "CONFIG_\\2_MODULE",
"c", "{scope=ref}{_extra=configPrefixed}{exclusive}", NULL, false},
{"^[ \t]*menu[ \t]+\"([^\"]+)\"[ \t]*", "\\1",
{"^[ \t]*menu[ \t]+\"([^\"]+)\"[ \t]*$", "\\1",
"m", "{scope=push}{exclusive}", NULL, false},
{"^[ \t]*endmenu[ \t]*", "",
{"^[ \t]*endmenu[ \t]*$", "",
"", "{scope=pop}{placeholder}{exclusive}", NULL, false},
{"^[ \t]*source[ \t]+\"?([^\"]+)\"?[ \t]*", "\\1",
{"^[ \t]*source[ \t]+\"?([^\"]+)\"?[ \t]*$", "\\1",
"k", "{_role=source}{exclusive}{scope=ref}", NULL, false},
{"^[ \t]*choice[ \t]+([A-Za-z0-9_]+)[ \t]*", "\\1",
{"^[ \t]*choice[ \t]+([A-Za-z0-9_]+)[ \t]*$", "\\1",
"C", "{scope=push}{exclusive}", NULL, false},
{"^[ \t]*choice[ \t]*$", "",
"C", "{_anonymous=choice}{scope=push}{exclusive}", NULL, false},
{"^[ \t]*endchoice[ \t]*", "",
{"^[ \t]*endchoice[ \t]*$", "",
"", "{scope=pop}{placeholder}{exclusive}", NULL, false},
{"^[ \t]*mainmenu[ \t]+\"([^\"]+)\"[ \t]*", "\\1",
{"^[ \t]*mainmenu[ \t]+\"([^\"]+)\"[ \t]*$", "\\1",
"M", "{exclusive}", NULL, false},
{"^([-a-zA-Z0-9_$]+)[ \t]*:?=", "\\1",
"v", "{exclusive}", NULL, false},
Expand Down
12 changes: 6 additions & 6 deletions optlib/kconfig.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@
--regex-Kconfig=/^[ \t]*(menu)?config[ \t]+([A-Za-z0-9_]+)[ \t]*$/CONFIG_\2/c/{scope=ref}{_extra=configPrefixed}
--regex-Kconfig=/^[ \t]*(menu)?config[ \t]+([A-Za-z0-9_]+)[ \t]*$/CONFIG_\2_MODULE/c/{scope=ref}{_extra=configPrefixed}{exclusive}

--regex-Kconfig=/^[ \t]*menu[ \t]+"([^"]+)"[ \t]*/\1/m/{scope=push}{exclusive}
--regex-Kconfig=/^[ \t]*endmenu[ \t]*//{scope=pop}{placeholder}{exclusive}
--regex-Kconfig=/^[ \t]*menu[ \t]+"([^"]+)"[ \t]*$/\1/m/{scope=push}{exclusive}
--regex-Kconfig=/^[ \t]*endmenu[ \t]*$//{scope=pop}{placeholder}{exclusive}

# Qemu's Kconfig does't use double quotes
--regex-Kconfig=/^[ \t]*source[ \t]+"?([^"]+)"?[ \t]*/\1/k/{_role=source}{exclusive}{scope=ref}
--regex-Kconfig=/^[ \t]*source[ \t]+"?([^"]+)"?[ \t]*$/\1/k/{_role=source}{exclusive}{scope=ref}

--regex-Kconfig=/^[ \t]*choice[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/C/{scope=push}{exclusive}
--regex-Kconfig=/^[ \t]*choice[ \t]+([A-Za-z0-9_]+)[ \t]*$/\1/C/{scope=push}{exclusive}
--regex-Kconfig=/^[ \t]*choice[ \t]*$//C/{_anonymous=choice}{scope=push}{exclusive}
--regex-Kconfig=/^[ \t]*endchoice[ \t]*//{scope=pop}{placeholder}{exclusive}
--regex-Kconfig=/^[ \t]*endchoice[ \t]*$//{scope=pop}{placeholder}{exclusive}

--regex-Kconfig=/^[ \t]*mainmenu[ \t]+"([^"]+)"[ \t]*/\1/M/{exclusive}
--regex-Kconfig=/^[ \t]*mainmenu[ \t]+"([^"]+)"[ \t]*$/\1/M/{exclusive}

--regex-Kconfig=/^([-a-zA-Z0-9_$]+)[ \t]*:?=/\1/v/{exclusive}

0 comments on commit 0d56602

Please sign in to comment.