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

Does ctags have multiline regex support? #219

Closed
andreicristianpetcu opened this issue Jan 29, 2015 · 10 comments
Closed

Does ctags have multiline regex support? #219

andreicristianpetcu opened this issue Jan 29, 2015 · 10 comments
Assignees
Milestone

Comments

@andreicristianpetcu
Copy link

Hello,
I have some Java code

@Subscribe
public void catchEvent(SomeEvent

And I want to match it with something like this in my ~/.ctags

--langdef=javaspring
--langmap=javaspring:.java
--regex-javaspring=/@Subscribe(\s)*([a-z ]+)\s([a-zA-Z]*)\(([a-zA-Z]*)/\3-\4/

This should generate something like "catchEvent-SomeEvent" but it does not. If I remove the newline between @subscribe and public void it gets it.

@Subscribe public void catchEvent(SomeEvent
rm -rf tags && ctags -R . && cat tags|grep Subs
catchEvent-SomeEvent    PathToMyFile.java    /^@Subscribe public void catchEvent(SomeEvent event) {$/;"      r

Do you have any idea if I can do this with the current ctag implementation. Am I doing something wrong or ctags does not support multi-line regex now.

Thank you!

@andreicristianpetcu
Copy link
Author

ctags --version
Exuberant Ctags 5.9~svn20110310, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Oct  7 2014, 13:52:37
  Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex

@masatake
Copy link
Member

masatake commented Feb 3, 2015

As far as I know ctags utilizes the regex engine in line oriented way.
We don't have any concrete plan to extend it to handle multiple line.

@andreicristianpetcu
Copy link
Author

Thank you @masatake do you think I can make a workaround like using other regex engine or something?

@masatake
Copy link
Member

masatake commented Feb 3, 2015

There are some approaches.

If you don't have enough time, and you know well aobut a script language, you can use xcmd.
See https://github.com/fishman/ctags/blob/master/docs/xcmd.rst.

If you have time and know C language, look at parseJavaAnnotation in c.c and extend it as you want.

If you have enough time, tell us your idea how ctags should deal java's annotation(not only spring.)
#64 and #80 may be related to this issue.

@andreicristianpetcu
Copy link
Author

The beauty of ctags is the fact that anybody can extend it with project specific settings by writing just some small regex. Please take a look at what I did for AngularJS (http://bit.ly/16gcKd7). My ctags settings (and vim) figure out AngularJS controllers, directives, modules etc. This is something that IntelliJ cannot. AngularJS is hip now, tomorrow it will not be. I think that ctags should have basic support for languages but not for frameworks. The JavaScript and Java support is great. I just wanted to have something with vim+ctags that no IDE offers. Multiline regex would give me the possibility to lookaround for stuff before and after and build a tag based on that. This is not language specific, it should not be in ctags source code, it should be in people's ~/.ctags on github :P

I have no C skills but I plan to learn. I see no need to extend parseJavaAnnotation now, it is great the way it is. I will check out xcmd and the two issues you pointed out.

Thank you again @masatake

@masatake
Copy link
Member

masatake commented Feb 4, 2015

(I think it is nice if we have multiline regex support, however I cannot have an image how to implement it well in the current ctags code base. See lregex.c. )

@andreicristianpetcu
Copy link
Author

@masatake I understand implementing it is complicated with the current codebase. I took a look at ---xcmd=COMMAND syntax and I will try to use it. I only read the documentation and it seems it is too much for me. From what I get from the documentation it will be invoked twice, once some sort of init that returns an exit code 0, something else or 77 and after that once for each file. It seems that the COMMAND needs to keep some sort of internal state.

I don't think current implementation is very good for my case since oneliners using grep do not keep state. I will try to use it and post on this issue an example if it works, if not, I will post what issues I had. Thank you for your input.

@masatake masatake modified the milestone: Feature plan May 22, 2015
@masatake
Copy link
Member

After learning etags.c of emacs, I know how can we implment multiline regex parser in ctags.
Search "multi_line" in https://searchcode.com/codesearch/view/56189132/.

You can accumulate all input at iFileGetLine of read.c.
You can run multipeline regex matcher at fileClose.

@masatake
Copy link
Member

masatake commented Dec 3, 2016

Now Universal-ctags has the most of all facilities for implementing multline regex parser.

masatake added a commit to masatake/ctags that referenced this issue Dec 3, 2016
Close universal-ctags#219

    [jet@localhost ctags]$ cat foo.java
    @subscribe
    public void catchEvent(SomeEvent e)
    {
	return;
    }

    @subscribe
    public void
	recover(Exception e)
    {
	return;
    }
    [jet@localhost ctags]$ ./ctags  \
    		   --langdef=javaspring --langmap=javaspring:.java \
                   '--regex-javaspring=/@subscribe(\s)*([a-z ]+)\s*([a-zA-Z]*)\(([a-zA-Z]*)/\3-\4/{multiline=3}' \
		   -o - foo.java
    Event-SomeEvent	foo.java	/^public void catchEvent(SomeEvent e)$/;"	r
    recover-Exception	foo.java	/^    recover(Exception e)$/;"	r

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
masatake added a commit to masatake/ctags that referenced this issue Dec 3, 2016
Close universal-ctags#219

    [jet@localhost ctags]$ cat foo.java
    @subscribe
    public void catchEvent(SomeEvent e)
    {
	return;
    }

    @subscribe
    public void
	recover(Exception e)
    {
	return;
    }
    [jet@localhost ctags]$ ./ctags  \
    		   --langdef=javaspring --langmap=javaspring:.java \
                   '--regex-javaspring=/@subscribe(\s)*([a-z ]+)\s*([a-zA-Z]*)\(([a-zA-Z]*)/\3-\4/{multiline=3}' \
		   -o - foo.java
    Event-SomeEvent	foo.java	/^public void catchEvent(SomeEvent e)$/;"	r
    recover-Exception	foo.java	/^    recover(Exception e)$/;"	r

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@masatake
Copy link
Member

masatake commented Dec 3, 2016

It works. Please, try #1224 if you have still interest.

masatake added a commit to masatake/ctags that referenced this issue Dec 3, 2016
Close universal-ctags#219

    $ cat foo.java
    @subscribe
    public void catchEvent(SomeEvent e)
    {
	return;
    }

    @subscribe
    public void
	recover(Exception e)
    {
	return;
    }
    $ ./ctags  \
    		   --langdef=javaspring --langmap=javaspring:.java \
                   '--regex-javaspring=/@subscribe(\s)*([a-z ]+)\s*([a-zA-Z]*)\(([a-zA-Z]*)/\3-\4/{_multiline=3}' \
		   -o - foo.java
    Event-SomeEvent	foo.java	/^public void catchEvent(SomeEvent e)$/;"	r
    recover-Exception	foo.java	/^    recover(Exception e)$/;"	r

This is still experimental, so an underscore char is used as
prefix for the regex flag.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
masatake added a commit to masatake/ctags that referenced this issue Dec 3, 2016
masatake added a commit to masatake/ctags that referenced this issue Dec 3, 2016
Close universal-ctags#219

    $ cat foo.java
    @subscribe
    public void catchEvent(SomeEvent e)
    {
	return;
    }

    @subscribe
    public void
	recover(Exception e)
    {
	return;
    }
    $ ./ctags  \
    		   --langdef=javaspring --langmap=javaspring:.java \
                   '--regex-javaspring=/@subscribe(\s)*([a-z ]+)\s*([a-zA-Z]*)\(([a-zA-Z]*)/\3-\4/{_multiline=3}' \
		   -o - foo.java
    Event-SomeEvent	foo.java	/^public void catchEvent(SomeEvent e)$/;"	r
    recover-Exception	foo.java	/^    recover(Exception e)$/;"	r

This is still experimental, so an underscore char is used as
prefix for the regex flag.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
masatake added a commit to masatake/ctags that referenced this issue Dec 3, 2016
masatake added a commit to masatake/ctags that referenced this issue Dec 5, 2016
Close universal-ctags#219

    $ cat foo.java
    @subscribe
    public void catchEvent(SomeEvent e)
    {
	return;
    }

    @subscribe
    public void
	recover(Exception e)
    {
	return;
    }
    $ ./ctags  \
    		   --langdef=javaspring --langmap=javaspring:.java \
                   '--regex-javaspring=/@subscribe(\s)*([a-z ]+)\s*([a-zA-Z]*)\(([a-zA-Z]*)/\3-\4/{_multiline=3}' \
		   -o - foo.java
    Event-SomeEvent	foo.java	/^public void catchEvent(SomeEvent e)$/;"	r
    recover-Exception	foo.java	/^    recover(Exception e)$/;"	r

This is still experimental, so an underscore char is used as
prefix for the regex flag.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
masatake added a commit to masatake/ctags that referenced this issue Dec 5, 2016
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