Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Stringize and concatenate macros (# and ##) are not highlighted properly #318

Open
1 task done
prati0100 opened this issue Jan 16, 2019 · 1 comment
Open
1 task done

Comments

@prati0100
Copy link

prati0100 commented Jan 16, 2019

Prerequisites

Description

When using # and ## operators, the tree-sitter parser incorrectly highlights them like #defines, which is not consistent with the part preceeding them. This was also partly a problem without tree-sitter, but only for using ## in function name.

With tree-sitter:
atom_with_tree_sitter

Without tree-sitter:
atom_without_tree_sitter

In the images, name is being highlighted incorrectly whenever the # and ## operators are used. taskqueue_define_##name should instead be highlighted like a function name. #name should be highlighted like a variable name (or a string? I'll let you guys decide).

Steps to Reproduce

  1. Use the stringify and token concatenation preprocessor operators.

edit by @rsese to add code for copy/paste and more screenshots

/*
 * Define and initialize...
 */
#define TASKQUEUE_DEFINE(name, enqueue, context, init)                     \
                                                                           \
struct taskqueue *taskqueue_##name;                                        \
                                                                           \
static void                                                                \
taskqueue_define_##name(void *arg)                                         \
{                                                                          \
  taskqueue_##name =                                                       \
    taskqueue_create(#name, M_WAITOK, (enqueue), (context));               \
  init;                                                                    \
}                                                                          \

Tree-sitter:

tree-sitter

Without:

tree-sitter-disabled

Reproduces how often: 100%

Versions

atom --version:
Atom : 1.34.0
Electron: 2.0.16
Chrome : 61.0.3163.100
Node : 8.9.3

apm --version:
apm 2.1.3
npm 6.2.0
node 8.9.3 x64
atom 1.34.0
python 2.7.15rc1
git 2.17.1

OS:
Ubuntu 18.04

@rsese
Copy link

rsese commented Jan 23, 2019

Thanks for the report! Reproduce with 1.34.0 on macOS 10.12.6:

Tree-sitter:

tree-sitter

Without:

tree-sitter-disabled

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

No branches or pull requests

2 participants