Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra tags in multiline regex tables #2795

Closed
bernardjoseph opened this issue Jan 8, 2021 · 6 comments
Closed

Extra tags in multiline regex tables #2795

bernardjoseph opened this issue Jan 8, 2021 · 6 comments

Comments

@bernardjoseph
Copy link

bernardjoseph commented Jan 8, 2021

Multiline regex tables do not support conditional tagging with extra. The following patch seems to solve the problem, but I do not know if there are drawbacks.

diff -urN ctags-orig/main/lregex.c ctags/main/lregex.c
--- ctags-orig/main/lregex.c	2021-01-06 18:31:30.000000000 +0100
+++ ctags/main/lregex.c	2021-01-08 02:45:40.000000000 +0100
@@ -2407,6 +2407,11 @@
 	{
 		regexTableEntry *entry = ptrArrayItem(table->entries, i);
 		regexPattern *ptrn = entry->pattern;
+
+		if ((entry->pattern->xtagType != XTAG_UNKNOWN)
+			&& (!isXtagEnabled (entry->pattern->xtagType)))
+			continue;
+
 		struct guestSpec  *guest = &ptrn->guest;
 
 		Assert (ptrn);
@masatake
Copy link
Member

masatake commented Jan 9, 2021

Thank you very much. You are correct. Can I ask you to make a pull request for this?
You can move the lines upward like:

 		regexTableEntry *entry = ptrArrayItem(table->entries, i);
+		if ((entry->pattern->xtagType != XTAG_UNKNOWN)
+			&& (!isXtagEnabled (entry->pattern->xtagType)))
+			continue;
+
 		regexPattern *ptrn = entry->pattern;
 		struct guestSpec  *guest = &ptrn->guest;

Could you add a test case I wrote to the pull request?
For adding, do "git am 0001-Tmain-add-a-case-for-testing-_extra-mtable-regex-fla.txt"
0001-Tmain-add-a-case-for-testing-_extra-mtable-regex-fla.txt
.

@masatake
Copy link
Member

masatake commented Jan 9, 2021

I wonder how do you find this bug because _extra flag is so minor.
You will be interested in my blog article. https://ctags.io/2021/01/05/optscript/.

@bernardjoseph
Copy link
Author

I am currently working on a parser for Markdown wiki links and Pandoc citations in Markdown files for a Zettelkasten (slip box). This is why I have found the bug, because I have defined an extra flag there. My goal is rather unusual for Universal ctags, I believe. I want to follow links and citations inside a Zettelkasten with the help of tags.

@masatake
Copy link
Member

I am currently working on a parser for Markdown wiki links ...

Are you extending optlib/markdown.ctags or writing a new markdown parser from scratch?

I have tried to tag links in a markdown file. However, I found it is not so easy.

    [link-I-would-like-to-tag] (URL)

Though the markdown parser in u-ctags is written in _mtable-regex-flags, it is line oriented.
I think full-rewriting may be needed to support the links.

If you feel the current version of u-ctags is not enough for your goal, rememer #2794. I'm implementing a general purpose interpreter to u-ctags command line.

@masatake
Copy link
Member

Fixed by your pull request. Thank you.

@masatake
Copy link
Member

It seems that you may be an elisp hacker, so you may be interested in https://github.com/AmaiKinono/citre .
It has a good tags file accessors. The author has very deep knowledges about tags file format. FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants