ctags icon indicating copy to clipboard operation
ctags copied to clipboard

lregex: wrong line adjustment when filling end: fields

Open masatake opened this issue 10 months ago • 0 comments

$ ./ctags --options=./Units/option-regex-attaching-role.r/extending-existing-parser.d/args.ctags ./Units/option-regex-attaching-role.r/extending-existing-parser.d/input.scm
ctags: Warning: given end line (3) for the tag () in the file (./Units/option-regex-attaching-role.r/extending-existing-parser.d/input.scm) is smaller than its start line: 4

The args.ctags is written well. The warning message comes from {scope=set}.

My analysis

(define-module foo
  (use bar)
  (export baz0 baz1))
(select-module foo)
 ^

ctags sets a scope when processing the input at ^ with the following option:

--_mtable-regex-myGauche=main/select-module[ \t\n]+([-a-zA-Z0-9]+)/\1/m/{_role=selected}{scope=set}

The way to set the scope in main/lregex.c:matchTagPattern() is broken:

		/*
		 * SCOPE_CLEAR|SCOPE_PUSH implies that "set" was specified as the scope action.
		 * If the specified action is "set", getInputLineNumberInRegPType()
		 * returns the start line of the NEW scope. The cleared scopes are ended BEFORE
		 * the new scope. There is a gap. We must adjust the "end:" field here.
		 */
		if (patbuf->scopeActions & SCOPE_PUSH && endline > 0)
			endline--;

Just decrementing the line number is too sloppy in byte-oriented table parsers.

Some preparations are needed to fix this issue.

  • Add the way to detect whether the current parser is defined in an optlib file.

  • Add an assertion to the code after the line that warns the message: Warning: given end line ...

    --- a/main/entry.c
    +++ b/main/entry.c
    @@ -1660,6 +1660,7 @@ extern void setTagEndLine(tagEntryInfo *tag, unsigned long endLine)
                   tag->name,
                   tag->inputFileName,
                   tag->lineNumber);
    +       Assert ((endLine == 0 || endLine >= tag->lineNumber) && IsTheParserBuiltIn());
            return;
        }
    
    
  • Revise the implementation of getInputLineNumberInRegPType(). Related to #4212.

masatake avatar Apr 29 '25 03:04 masatake