Skip to content

Commit 4fe51ed

Browse files
committed
lregex: warn if mgroup= flag is not given in --mline-regex-<LANG>=
Close #3513. Close #2918. Specifying mgroup is a must if --mline-regex-<LANG>= records a tag with \[0-9]. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 61b7ee3 commit 4fe51ed

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ctags: Notice: No options will be read from files or environment
2+
ctags: Warning: FOO: no {mgroup=N} flag given in --mline-regex-<LANG>=/(.)/\1/{_advanceTo=1start}... (addTagRegexOption)
23
ctags: Warning: a multi line regex pattern doesn't advance the input cursor: (.)
34
ctags: Warning: Language: FOO, input file: ./input.foo, pos: 0

Tmain/optlib-message-flag.d/args.ctags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
--mline-regex-FOO=/namespace ([a-zA-Z]+) /\1/m,mlineNamespace/{mgroup=1}{warning="got namespace"}
1414
--mline-regex-FOO=/var ([a-zA-Z]+) ([a-zA-Z]+);/\2/V,mlineVariable/{warning="got variable '\2' of type \1"}{mgroup=2}
15-
--mline-regex-FOO=/bad multi-line ([a-zA-Z-]+)/\1/x,bad/{fatal="bad='\1'"}
15+
--mline-regex-FOO=/bad multi-line ([a-zA-Z-]+)/\1/x,bad/{fatal="bad='\1'"}{mgroup=1}
1616

1717

1818
--_tabledef-FOO=main

docs/optlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ Multiline pattern flags
917917

918918
.. TODO: Q: isn't the above restriction really a bug? I think it is. I should fix it.
919919
Q to @masatake-san: Do you mean that {mgroup=0} can be omitted? -> #2918 is opened
920-
920+
A. as proposed in #3514, I made {mgroup=N} be a must flag.
921921
922922
``{_advanceTo=N[start|end]}``
923923

main/lregex.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,8 +2290,16 @@ extern void addTagMultiLineRegex (struct lregexControlBlock *lcb, const char* co
22902290
const char* const name, const char* const kinds, const char* const flags,
22912291
bool *disabled)
22922292
{
2293-
addTagRegexInternal (lcb, TABLE_INDEX_UNUSED,
2294-
REG_PARSER_MULTI_LINE, regex, name, kinds, flags, disabled);
2293+
regexPattern *ptrn = addTagRegexInternal (lcb, TABLE_INDEX_UNUSED,
2294+
REG_PARSER_MULTI_LINE, regex, name, kinds, flags, disabled);
2295+
if (ptrn->mgroup.forLineNumberDetermination == NO_MULTILINE)
2296+
{
2297+
if (hasNameSlot(ptrn))
2298+
error (WARNING, "%s: no {mgroup=N} flag given in --mline-regex-<LANG>=/%s/... (%s)",
2299+
regex,
2300+
getLanguageName (lcb->owner), ASSERT_FUNCTION);
2301+
ptrn->mgroup.forLineNumberDetermination = 0;
2302+
}
22952303
}
22962304

22972305
extern void addTagMultiTableRegex(struct lregexControlBlock *lcb,
@@ -2383,8 +2391,19 @@ static void addTagRegexOption (struct lregexControlBlock *lcb,
23832391
regex_pat = eStrdup (pattern);
23842392

23852393
if (parseTagRegex (regptype, regex_pat, &name, &kinds, &flags))
2386-
addTagRegexInternal (lcb, table_index, regptype, regex_pat, name, kinds, flags,
2387-
NULL);
2394+
{
2395+
regexPattern *ptrn = addTagRegexInternal (lcb, table_index, regptype, regex_pat, name, kinds, flags,
2396+
NULL);
2397+
if (regptype == REG_PARSER_MULTI_LINE
2398+
&& ptrn->mgroup.forLineNumberDetermination == NO_MULTILINE)
2399+
{
2400+
if (hasNameSlot(ptrn))
2401+
error (WARNING, "%s: no {mgroup=N} flag given in --mline-regex-<LANG>=%s... (%s)",
2402+
getLanguageName (lcb->owner),
2403+
pattern, ASSERT_FUNCTION);
2404+
ptrn->mgroup.forLineNumberDetermination = 0;
2405+
}
2406+
}
23882407

23892408
eFree (regex_pat);
23902409
}

0 commit comments

Comments
 (0)