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

more complete support for $ in C/C++ identifiers #1971

Merged
merged 1 commit into from Jan 11, 2019

Conversation

pskocik
Copy link
Contributor

@pskocik pskocik commented Jan 10, 2019

ctags seemed to have some support for $ in identifiers, like it would index $BAR from #define $BAR but not $name from extern int $name;. Similarly it wouldn't let me define replacement macros e.g., '-D$my$struct=struct and then have foo from $my$struct foo indexed. This minipatch appears to fix these issues.

@coveralls
Copy link

coveralls commented Jan 10, 2019

Coverage Status

Coverage remained the same at 84.906% when pulling 8228c5f on pskocik:master into b60a7b9 on universal-ctags:master.

Copy link
Contributor

@pragmaware pragmaware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure about $ being standard-compliant as part of an identifier but gcc seems to support in certain configurations so I agree ctags should too. If you can fix the small parenthesis detail I'll merge this without adding my own overrides.

parsers/cpreprocessor.c Show resolved Hide resolved
@pskocik
Copy link
Contributor Author

pskocik commented Jan 10, 2019

Oh, it's definitely nonstandard. But it looked like universal ctags was already trying to support it:

parsers/cpreprocessor.h:

#define cppIsident(c)  (cppIsalnum(c)					\
						|| (c) == '_' || (c) == '$')

/*  Is the character valid as the first character of a C identifier?
 *  C++ allows '~' in destructors.
 *  VMS allows '$' in identifiers.
 */
#define cppIsalpha(c)   (cppIsascii(c) && isalpha(c))
#define cppIsident1(c)  (cppIsalpha(c)					\
						  || (c) == '_' || (c) == '~' || (c) == '$')

and I found myself wanting it supported fully, hence the patch.

(so I guess the if and while better be replaced with:
if ( !cppIsident1(*c) )
and
while (cppIsident(*c) )
(I pushed this to https://github.com/pskocik/ctags/tree/alternative_dollar))

Apologies for messing up the parenthesis there. I forced-pushed a fixed version.

@pragmaware
Copy link
Contributor

Great! Thank you!

@pragmaware pragmaware merged commit a20bb99 into universal-ctags:master Jan 11, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants