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

Cython cppclass not recognized #4133

Open
user202729 opened this issue Nov 27, 2024 · 3 comments
Open

Cython cppclass not recognized #4133

user202729 opened this issue Nov 27, 2024 · 3 comments

Comments

@user202729
Copy link

user202729 commented Nov 27, 2024


The name of the parser:

Python, IPythonCell

The command line you used to run ctags:

$ ctags --options=NONE -o - /tmp/a.pyx

The content of input file: (extracted from SageMath source code)

cdef extern from "bliss/graph.hh" namespace "bliss":

    cdef cppclass Stats:
        pass

    cdef cppclass AbstractGraph:
        pass

    cdef cppclass Graph(AbstractGraph):
        Graph(const unsigned int)

The tags output you are not satisfied with:

Graph   /tmp/a.pyx      /^    cdef cppclass Graph(AbstractGraph):$/;"   f

The tags output you expect:

AbstractGraph   /tmp/a.pyx      /^    cdef cppclass AbstractGraph:$/;"        c
Graph   /tmp/a.pyx      /^    cdef cppclass Graph(AbstractGraph):$/;"   c
Stats   /tmp/a.pyx      /^    cdef cppclass Stats:$/;"        c

The version of ctags:

$ ctags --version
Universal Ctags 6.1.0(v6.1.0), Copyright (C) 2015-2023 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Mar 17 2024, 12:18:39
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript, +pcre2

How do you get ctags binary:

Arch Linux package

@masatake
Copy link
Member

Thank you. Cython is yet another parser I would like to rewrite.
Here is a quick solution.

diff --git a/parsers/python.c b/parsers/python.c
index 0403fcc43..f23ccdbdd 100644
--- a/parsers/python.c
+++ b/parsers/python.c
@@ -156,6 +156,7 @@ static const keywordTable PythonKeywordTable[] = {
 	{ "cimport",		KEYWORD_import			},
 	{ "class",			KEYWORD_class			},
 	{ "cpdef",			KEYWORD_cpdef			},
+	{ "cppclass",		KEYWORD_class			},
 	{ "def",			KEYWORD_def				},
 	{ "extern",			KEYWORD_extern			},
 	{ "from",			KEYWORD_from			},

@masatake
Copy link
Member

I will make a pull request after solving the CI/CD related issues.

@masatake
Copy link
Member

masatake commented Dec 3, 2024

I read https://github.com/mkoeppe/bliss/blob/sage_package/graph.hh.

It is challenging (and interesting) to make a model for a language to glue languages together.

    cdef cppclass Stats:
        pass

The primary task of ctags is extracting the name defining something.
e.g.

ctags extracts foo from the following Python script:

def foo(n):
    pass

However, ctags doesn't extract bar as a definition tag from the following Python script:

import bar;

because this code doesn't define bar. This code refers bar defined somewhere.
Instead, ctags extracts bar as a reference tag.

    cdef cppclass Stats:
        pass

I wonder whether this code defines Stats.
From a point of view, this code refers to a C++ class defined somewhere and declared in bliss/graph.hh. ctags can make a reference tag in this case.

From a point of view, this code defines a new Python class.
Making two tag entries for Stats looks better.

I discussed a similar topic ago when enhancing Basic parser.
#3284

The modeling for solving this issue must be consistent with the discussion.

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