History

docs: kdoc: replace NestedMatch with CMatch

Our previous approach to solve nested structs were to use NestedMatch. It works well, but adding support to parse delimiters is very complex. Instead, use CMatch, which uses a C tokenizer, making the code more reliable and simpler.

Mauro Carvalho Chehab committed 8 months ago

Commit 600079f1 parent c22aa122 files · +17 −16Browse files

Showing the changes to tools/lib/python (2 of 2 files). Show all

Unified · Split

2 files
  1. tools/lib/python/kdoc/kdoc_parser.py +1 −1
  2. tools/lib/python/kdoc/xforms_lists.py +16 −15
tools/lib/python/kdoc/kdoc_parser.py+1−1
@@ -14,7 +14,7 @@ import re · 13 unmodified lines
1414 from pprint import pformat
1515
1616 from kdoc.c_lex import CTokenizer
17−from kdoc.kdoc_re import NestedMatch, KernRe
17+from kdoc.kdoc_re import KernRe
1818 from kdoc.kdoc_item import KdocItem
1919
2020 #
tools/lib/python/kdoc/xforms_lists.py+16−15
@@ -4,7 +4,8 @@ · 3 unmodified lines
44
55 import re
66
7−from kdoc.kdoc_re import KernRe, NestedMatch
7+from kdoc.kdoc_re import KernRe
8+from kdoc.c_lex import CMatch
89
910 struct_args_pattern = r'([^,)]+)'
1011
@@ -60,7 +61,7 @@ class CTransforms: · 49 unmodified lines
6061 #
6162 # As it doesn't properly match the end parenthesis on some cases.
6263 #
63− # So, a better solution was crafted: there's now a NestedMatch
64+ # So, a better solution was crafted: there's now a CMatch
6465 # class that ensures that delimiters after a search are properly
6566 # matched. So, the implementation to drop STRUCT_GROUP() will be
6667 # handled in separate.
@@ -72,9 +73,9 @@ class CTransforms: · 5 unmodified lines
7273 #
7374 # Replace macros
7475 #
75− # TODO: use NestedMatch for FOO($1, $2, ...) matches
76+ # TODO: use CMatch for FOO($1, $2, ...) matches
7677 #
77− # it is better to also move those to the NestedMatch logic,
78+ # it is better to also move those to the CMatch logic,
7879 # to ensure that parentheses will be properly matched.
7980 #
8081 (KernRe(r'__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)', re.S),
@@ -95,17 +96,17 @@ class CTransforms: · 14 unmodified lines
9596 (KernRe(r'DEFINE_DMA_UNMAP_LEN\s*\(' + struct_args_pattern + r'\)', re.S), r'__u32 \1'),
9697 (KernRe(r'VIRTIO_DECLARE_FEATURES\(([\w_]+)\)'), r'union { u64 \1; u64 \1_array[VIRTIO_FEATURES_U64S]; }'),
9798
98− (NestedMatch(r"__cond_acquires\s*\("), ""),
99− (NestedMatch(r"__cond_releases\s*\("), ""),
100− (NestedMatch(r"__acquires\s*\("), ""),
101− (NestedMatch(r"__releases\s*\("), ""),
102− (NestedMatch(r"__must_hold\s*\("), ""),
103− (NestedMatch(r"__must_not_hold\s*\("), ""),
104− (NestedMatch(r"__must_hold_shared\s*\("), ""),
105− (NestedMatch(r"__cond_acquires_shared\s*\("), ""),
106− (NestedMatch(r"__acquires_shared\s*\("), ""),
107− (NestedMatch(r"__releases_shared\s*\("), ""),
108− (NestedMatch(r'\bSTRUCT_GROUP\('), r'\0'),
99+ (CMatch(r"__cond_acquires"), ""),
100+ (CMatch(r"__cond_releases"), ""),
101+ (CMatch(r"__acquires"), ""),
102+ (CMatch(r"__releases"), ""),
103+ (CMatch(r"__must_hold"), ""),
104+ (CMatch(r"__must_not_hold"), ""),
105+ (CMatch(r"__must_hold_shared"), ""),
106+ (CMatch(r"__cond_acquires_shared"), ""),
107+ (CMatch(r"__acquires_shared"), ""),
108+ (CMatch(r"__releases_shared"), ""),
109+ (CMatch(r"STRUCT_GROUP"), r'\0'),
109110 ]
110111
111112 #: Transforms for function prototypes.