Skip to content

Commit 5866249

Browse files
committed
temp fix for then using keyword
1 parent 0f969ee commit 5866249

File tree

8 files changed

+623
-71
lines changed

8 files changed

+623
-71
lines changed

cpp/generate.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
152152
:static_assert,
153153
:other_keywords,
154154
:memory_operators,
155+
:using_name,
155156
:the_this_keyword,
156157
:language_constants,
157158
:template_isolated_definition,
@@ -312,6 +313,7 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
312313
#
313314
# Keywords and Keyword-ish things
314315
#
316+
cpp_grammar[:using_name] = newPattern(match: /using/, tag_as: "keyword.other.using.directive").then(@spaces).lookAheadToAvoid(/namespace\b/)
315317
cpp_grammar[:functional_specifiers_pre_parameters] = newPattern(
316318
match: variableBounds[ @cpp_tokens.that(:isFunctionSpecifier) ],
317319
tag_as: "storage.modifier.specificer.functional.pre-parameters.$match"
@@ -466,10 +468,7 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
466468
:string_context_c,
467469
],
468470
),
469-
newPattern(match: /using/, tag_as: "keyword.other.using.directive").then(@spaces).then(
470-
match: variable_name,
471-
tag_as: "entity.name.namespace",
472-
),
471+
:using_name,
473472
newPattern(match: /,/, tag_as: "punctuation.separator.attribute"),
474473
newPattern(match: /:/, tag_as: "punctuation.accessor.attribute"),
475474
newPattern(
@@ -1187,7 +1186,7 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
11871186
tag_as: "storage.modifier.inline"
11881187
)
11891188
)
1190-
]
1189+
],
11911190
)
11921191

11931192
#

syntaxes/cpp.tmLanguage.json

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
{
4444
"include": "#memory_operators"
4545
},
46+
{
47+
"include": "#using_name"
48+
},
4649
{
4750
"include": "#the_this_keyword"
4851
},
@@ -735,6 +738,14 @@
735738
}
736739
]
737740
},
741+
"using_name": {
742+
"match": "(using)\\s+(?!namespace\\b)",
743+
"captures": {
744+
"1": {
745+
"name": "keyword.other.using.directive.cpp"
746+
}
747+
}
748+
},
738749
"functional_specifiers_pre_parameters": {
739750
"match": "(?<!\\w)(?:inline|constexpr|mutable|friend|explicit|virtual)(?!\\w)",
740751
"name": "storage.modifier.specificer.functional.pre-parameters.$0.cpp"
@@ -952,15 +963,7 @@
952963
]
953964
},
954965
{
955-
"match": "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))",
956-
"captures": {
957-
"1": {
958-
"name": "keyword.other.using.directive.cpp"
959-
},
960-
"2": {
961-
"name": "entity.name.namespace.cpp"
962-
}
963-
}
966+
"include": "#using_name"
964967
},
965968
{
966969
"match": ",",
@@ -1014,15 +1017,7 @@
10141017
]
10151018
},
10161019
{
1017-
"match": "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))",
1018-
"captures": {
1019-
"1": {
1020-
"name": "keyword.other.using.directive.cpp"
1021-
},
1022-
"2": {
1023-
"name": "entity.name.namespace.cpp"
1024-
}
1025-
}
1020+
"include": "#using_name"
10261021
},
10271022
{
10281023
"match": ",",
@@ -1076,15 +1071,7 @@
10761071
]
10771072
},
10781073
{
1079-
"match": "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))",
1080-
"captures": {
1081-
"1": {
1082-
"name": "keyword.other.using.directive.cpp"
1083-
},
1084-
"2": {
1085-
"name": "entity.name.namespace.cpp"
1086-
}
1087-
}
1074+
"include": "#using_name"
10881075
},
10891076
{
10901077
"match": ",",
@@ -1138,15 +1125,7 @@
11381125
]
11391126
},
11401127
{
1141-
"match": "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))",
1142-
"captures": {
1143-
"1": {
1144-
"name": "keyword.other.using.directive.cpp"
1145-
},
1146-
"2": {
1147-
"name": "entity.name.namespace.cpp"
1148-
}
1149-
}
1128+
"include": "#using_name"
11501129
},
11511130
{
11521131
"match": ",",

syntaxes/cpp.tmLanguage.yaml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- include: "#static_assert"
1919
- include: "#other_keywords"
2020
- include: "#memory_operators"
21+
- include: "#using_name"
2122
- include: "#the_this_keyword"
2223
- include: "#language_constants"
2324
- include: "#template_isolated_definition"
@@ -369,6 +370,11 @@
369370
name: punctuation.section.arguments.end.bracket.round.decltype.cpp
370371
patterns:
371372
- include: "#evaluation_context"
373+
using_name:
374+
match: "(using)\\s+(?!namespace\\b)"
375+
captures:
376+
'1':
377+
name: keyword.other.using.directive.cpp
372378
functional_specifiers_pre_parameters:
373379
match: "(?<!\\w)(?:inline|constexpr|mutable|friend|explicit|virtual)(?!\\w)"
374380
name: storage.modifier.specificer.functional.pre-parameters.$0.cpp
@@ -499,12 +505,7 @@
499505
patterns:
500506
- include: "#attributes_context"
501507
- include: "#string_context_c"
502-
- match: "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))"
503-
captures:
504-
'1':
505-
name: keyword.other.using.directive.cpp
506-
'2':
507-
name: entity.name.namespace.cpp
508+
- include: "#using_name"
508509
- match: ","
509510
name: punctuation.separator.attribute.cpp
510511
- match: ":"
@@ -531,12 +532,7 @@
531532
patterns:
532533
- include: "#attributes_context"
533534
- include: "#string_context_c"
534-
- match: "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))"
535-
captures:
536-
'1':
537-
name: keyword.other.using.directive.cpp
538-
'2':
539-
name: entity.name.namespace.cpp
535+
- include: "#using_name"
540536
- match: ","
541537
name: punctuation.separator.attribute.cpp
542538
- match: ":"
@@ -563,12 +559,7 @@
563559
patterns:
564560
- include: "#attributes_context"
565561
- include: "#string_context_c"
566-
- match: "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))"
567-
captures:
568-
'1':
569-
name: keyword.other.using.directive.cpp
570-
'2':
571-
name: entity.name.namespace.cpp
562+
- include: "#using_name"
572563
- match: ","
573564
name: punctuation.separator.attribute.cpp
574565
- match: ":"
@@ -595,12 +586,7 @@
595586
patterns:
596587
- include: "#attributes_context"
597588
- include: "#string_context_c"
598-
- match: "(using)\\s+((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F]))(?:(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U000[0-9a-fA-F])))*(?!\\w))"
599-
captures:
600-
'1':
601-
name: keyword.other.using.directive.cpp
602-
'2':
603-
name: entity.name.namespace.cpp
589+
- include: "#using_name"
604590
- match: ","
605591
name: punctuation.separator.attribute.cpp
606592
- match: ":"

test/fixtures/vscode/misc001.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "compiler/rule.h"
2+
#include "compiler/util/hash_combine.h"
3+
4+
namespace tree_sitter {
5+
namespace rules {
6+
7+
using std::move;
8+
using std::vector;
9+
using until::hash_combine;
10+
11+
Rule::Rule(const Rule &other) : blank_(Blank{}), type(BlankType) {
12+
*this = other;
13+
}
14+
15+
static void destroy_value(Rule *rule) {
16+
switch (rule->type) {
17+
case Rule::BlankType: return rule->blank.~Blank();
18+
}
19+
}
20+
21+
Rule &Rule::operator=(const Rule &other) {
22+
destroy_value(this);
23+
type = other.type;
24+
switch(type) {
25+
case BlankType:
26+
new (&blank_) Blank(other.blank);
27+
break;
28+
case CharacterSetType:
29+
new (&charater_set_) CharacterSet(other.character_set_);
30+
break;
31+
}
32+
}
33+
34+
}
35+
36+
}

test/specs/issues/002.cpp.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
- source: '::'
7070
scopes:
7171
- punctuation.separator.namespace.access
72-
- punctuation.separator.scope-resolution.function.definition.operator-overload
72+
- >-
73+
punctuation.separator.scope-resolution.function.definition.operator-overload
7374
- source: string &
7475
scopesEnd:
7576
- entity.name.operator.overloadee

test/specs/issues/055.cpp.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
- source: (
5050
scopes:
5151
- punctuation.section.parameters.begin.bracket.round
52-
- source: 'enum'
52+
- source: enum
5353
scopesBegin:
5454
- meta.function.definition.parameters
5555
- meta.block.enum
@@ -67,7 +67,7 @@
6767
scopes:
6868
- punctuation.separator.namespace.access
6969
- punctuation.separator.scope-resolution
70-
- source: 'baz quix)'
70+
- source: baz quix)
7171
scopesEnd:
7272
- meta.head.enum
7373
- source: ;

test/specs/test.cpp.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
- source: ' a comment /* no nest */'
4646
scopesEnd:
4747
- comment.line.double-slash
48-
- source: '/*'
48+
- source: /*
4949
scopesBegin:
5050
- comment.block
5151
scopes:
@@ -54,5 +54,3 @@
5454
- source: '*/'
5555
scopes:
5656
- punctuation.definition.comment.end
57-
scopesEnd:
58-
- comment.block

0 commit comments

Comments
 (0)