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

Add destructor pattern #217

Merged
merged 3 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion language_tags/cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ entity.name.function.definition.cpp
entity.name.function.destructor.cpp
entity.name.function.member.cpp
entity.name.function.preprocessor.cpp
entity.name.function.special.destructor.cpp
entity.name.namespace.alias.cpp
entity.name.namespace.cpp
entity.name.operator.overloadee.cpp
Expand Down Expand Up @@ -406,7 +407,6 @@ meta.function.definition.parameters.cpp
meta.function.definition.parameters.lambda.cpp
meta.function.definition.parameters.operator-overload.cpp
meta.function.destructor.cpp
meta.function.destructor.prototype.cpp
meta.head.class.cpp
meta.head.enum.cpp
meta.head.extern.cpp
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
exit_code = Integer($?)
if exit_code != 0
puts "\n\nGenerating the syntax for #{File.basename(each_dir)} failed: #{exit_code}"
exit(exit_code)
exit(false)
end
end
2 changes: 1 addition & 1 deletion scripts/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
Process.wait(Process.spawn("node", "lint/index.js", each_file))
exit_code = Integer($?)
if exit_code != 0
exit(exit_code)
exit(false)
end
end
68 changes: 20 additions & 48 deletions source/languages/cpp/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
:template_definition,
:misc_storage_modifiers_1,
:destructor,
:destructor_prototype,
:lambdas,
:preprocessor_context,
:comments_context,
Expand Down Expand Up @@ -240,7 +239,6 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
:template_definition,
:misc_storage_modifiers_1,
:destructor,
:destructor_prototype,
:lambdas,
:preprocessor_context,
:comments_context,
Expand Down Expand Up @@ -1616,52 +1614,26 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
match: /\b(const|extern|register|restrict|static|volatile|inline)\b/,
name: "storage.modifier"
}
cpp_grammar[:destructor] = {
name: "meta.function.destructor",
begin: "(?x)\n(?:\n ^ | # beginning of line\n (?:(?<!else|new|=)) # or word + space before name\n)\n((?:[A-Za-z_][A-Za-z0-9_]*::)*+~[A-Za-z_][A-Za-z0-9_]*) # actual name\n\\s*(\\() # opening bracket",
beginCaptures: {
"1" => {
name: "entity.name.function.destructor"
},
"2" => {
name: "punctuation.definition.parameters.begin.destructor"
}
},
end: /\)/,
endCaptures: {
"0" => {
name: "punctuation.definition.parameters.end.destructor"
}
},
patterns: [
{
include: "#root_context"
}
]
}
cpp_grammar[:destructor_prototype] = {
name: "meta.function.destructor.prototype",
begin: "(?x)\n(?:\n ^ | # beginning of line\n (?:(?<!else|new|=)) # or word + space before name\n)\n((?:[A-Za-z_][A-Za-z0-9_]*::)*+~[A-Za-z_][A-Za-z0-9_]*) # actual name\n\\s*(\\() # opening bracket",
beginCaptures: {
"1" => {
name: "entity.name.function"
},
"2" => {
name: "punctuation.definition.parameters.begin"
}
},
end: /\)/,
endCaptures: {
"0" => {
name: "punctuation.definition.parameters.end"
}
},
patterns: [
{
include: "#root_context"
}
]
}
#destructors accept no parameters
cpp_grammar[:destructor] = newPattern(
should_fully_match: ["~bar()", "foo::~foo()"],
tag_as: "meta.function.destructor",
match: lookBehindToAvoid(/[a-zA-Z0-9_]/).then(
match: newPattern(
newPattern(match: identifier, reference: "class_name", dont_back_track?: true).maybe(@spaces).then(/::/).maybe(@spaces)
.then(/~/).backReference("class_name")
).or(
newPattern(/~/).then(match: identifier, dont_back_track?: true)
),
tag_as: "entity.name.function.destructor entity.name.function.special.destructor"
).maybe(@spaces).then(
match: /\(/,
tag_as: "punctuation.definition.parameters.begin.destructor",
).maybe(@spaces).then(
match: /\)/,
tag_as: "punctuation.definition.parameters.end.destructor",
)
)
cpp_grammar[:meta_preprocessor_macro] = {
name: "meta.preprocessor.macro",
begin: "(?x)\n^\\s* ((\\#)\\s*define) \\s+\t# define\n((?<id>#{preprocessor_name_no_bounds}))\t # macro name\n(?:\n (\\()\n\t(\n\t \\s* \\g<id> \\s*\t\t # first argument\n\t ((,) \\s* \\g<id> \\s*)* # additional arguments\n\t (?:\\.\\.\\.)?\t\t\t# varargs ellipsis?\n\t)\n (\\))\n)?",
Expand Down
51 changes: 7 additions & 44 deletions syntaxes/cpp.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@
{
"include": "#destructor"
},
{
"include": "#destructor_prototype"
},
{
"include": "#lambdas"
},
Expand Down Expand Up @@ -405,9 +402,6 @@
{
"include": "#destructor"
},
{
"include": "#destructor_prototype"
},
{
"include": "#lambdas"
},
Expand Down Expand Up @@ -5119,50 +5113,19 @@
"name": "storage.modifier.cpp"
},
"destructor": {
"name": "meta.function.destructor.cpp",
"begin": "(?x)\n(?:\n ^ | # beginning of line\n (?:(?<!else|new|=)) # or word + space before name\n)\n((?:[A-Za-z_][A-Za-z0-9_]*::)*+~[A-Za-z_][A-Za-z0-9_]*) # actual name\n\\s*(\\() # opening bracket",
"beginCaptures": {
"match": "(?<![a-zA-Z0-9_])((?:((?>(?:[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])))*))\\s*::\\s*~\\2|~(?>(?:[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])))*)))\\s*(\\()\\s*(\\))",
"captures": {
"1": {
"name": "entity.name.function.destructor.cpp"
"name": "entity.name.function.destructor.cpp entity.name.function.special.destructor.cpp"
},
"2": {
"3": {
"name": "punctuation.definition.parameters.begin.destructor.cpp"
}
},
"end": "(?-mix:\\))",
"endCaptures": {
"0": {
"name": "punctuation.definition.parameters.end.destructor.cpp"
}
},
"patterns": [
{
"include": "#root_context"
}
]
},
"destructor_prototype": {
"name": "meta.function.destructor.prototype.cpp",
"begin": "(?x)\n(?:\n ^ | # beginning of line\n (?:(?<!else|new|=)) # or word + space before name\n)\n((?:[A-Za-z_][A-Za-z0-9_]*::)*+~[A-Za-z_][A-Za-z0-9_]*) # actual name\n\\s*(\\() # opening bracket",
"beginCaptures": {
"1": {
"name": "entity.name.function.cpp"
},
"2": {
"name": "punctuation.definition.parameters.begin.cpp"
}
},
"end": "(?-mix:\\))",
"endCaptures": {
"0": {
"name": "punctuation.definition.parameters.end.cpp"
"4": {
"name": "punctuation.definition.parameters.end.destructor.cpp"
}
},
"patterns": [
{
"include": "#root_context"
}
]
"name": "meta.function.destructor.cpp"
},
"meta_preprocessor_macro": {
"name": "meta.preprocessor.macro.cpp",
Expand Down
46 changes: 6 additions & 40 deletions syntaxes/cpp.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
- include: "#template_definition"
- include: "#misc_storage_modifiers_1"
- include: "#destructor"
- include: "#destructor_prototype"
- include: "#lambdas"
- include: "#preprocessor_context"
- include: "#comments_context"
Expand Down Expand Up @@ -179,7 +178,6 @@
- include: "#template_definition"
- include: "#misc_storage_modifiers_1"
- include: "#destructor"
- include: "#destructor_prototype"
- include: "#lambdas"
- include: "#preprocessor_context"
- include: "#comments_context"
Expand Down Expand Up @@ -2642,47 +2640,15 @@
match: !ruby/regexp /\b(const|extern|register|restrict|static|volatile|inline)\b/
name: storage.modifier.cpp
destructor:
name: meta.function.destructor.cpp
begin: |-
(?x)
(?:
^ | # beginning of line
(?:(?<!else|new|=)) # or word + space before name
)
((?:[A-Za-z_][A-Za-z0-9_]*::)*+~[A-Za-z_][A-Za-z0-9_]*) # actual name
\s*(\() # opening bracket
beginCaptures:
match: "(?<![a-zA-Z0-9_])((?:((?>(?:[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])))*))\\s*::\\s*~\\2|~(?>(?:[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])))*)))\\s*(\\()\\s*(\\))"
captures:
'1':
name: entity.name.function.destructor.cpp
'2':
name: entity.name.function.destructor.cpp entity.name.function.special.destructor.cpp
'3':
name: punctuation.definition.parameters.begin.destructor.cpp
end: !ruby/regexp /\)/
endCaptures:
'0':
'4':
name: punctuation.definition.parameters.end.destructor.cpp
patterns:
- include: "#root_context"
destructor_prototype:
name: meta.function.destructor.prototype.cpp
begin: |-
(?x)
(?:
^ | # beginning of line
(?:(?<!else|new|=)) # or word + space before name
)
((?:[A-Za-z_][A-Za-z0-9_]*::)*+~[A-Za-z_][A-Za-z0-9_]*) # actual name
\s*(\() # opening bracket
beginCaptures:
'1':
name: entity.name.function.cpp
'2':
name: punctuation.definition.parameters.begin.cpp
end: !ruby/regexp /\)/
endCaptures:
'0':
name: punctuation.definition.parameters.end.cpp
patterns:
- include: "#root_context"
name: meta.function.destructor.cpp
meta_preprocessor_macro:
name: meta.preprocessor.macro.cpp
begin: "(?x)\n^\\s* ((\\#)\\s*define) \\s+\t# define\n((?<id>(?-mix:[a-zA-Z_$][\\w$]*)))\t
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/issues/080.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class foo {
~foo();
};
foo::~foo() {}
foo::~bar() {}
96 changes: 96 additions & 0 deletions test/specs/issues/080.cpp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
- source: class
scopesBegin:
- source
- meta.block.class
- meta.head.class
scopes:
- storage.type.class
- source: foo
scopes:
- entity.name.type.class
- source: '{'
scopes:
- punctuation.section.block.begin.bracket.curly.class
scopesEnd:
- meta.head.class
- source: ~foo
scopesBegin:
- meta.body.class
- meta.function.destructor
scopes:
- entity.name.function.destructor
- entity.name.function.special.destructor
- source: (
scopes:
- punctuation.definition.parameters.begin.destructor
- source: )
scopes:
- punctuation.definition.parameters.end.destructor
scopesEnd:
- meta.function.destructor
- source: ;
scopes:
- punctuation.terminator.statement
- source: '}'
scopes:
- punctuation.section.block.end.bracket.curly.class
scopesEnd:
- meta.body.class
- source: ;
scopes:
- punctuation.terminator.statement
scopesEnd:
- meta.block.class
- source: 'foo::~foo'
scopesBegin:
- meta.function.destructor
scopes:
- entity.name.function.destructor
- entity.name.function.special.destructor
- source: (
scopes:
- punctuation.definition.parameters.begin.destructor
- source: )
scopes:
- punctuation.definition.parameters.end.destructor
scopesEnd:
- meta.function.destructor
- source: '{'
scopesBegin:
- meta.block
scopes:
- punctuation.section.block.begin.bracket.curly
- source: '}'
scopes:
- punctuation.section.block.end.bracket.curly
scopesEnd:
- meta.block
- source: foo
scopes:
- entity.name.scope-resolution
- source: '::'
scopes:
- punctuation.separator.namespace.access
- punctuation.separator.scope-resolution
- source: ~bar
scopesBegin:
- meta.function.destructor
scopes:
- entity.name.function.destructor
- entity.name.function.special.destructor
- source: (
scopes:
- punctuation.definition.parameters.begin.destructor
- source: )
scopes:
- punctuation.definition.parameters.end.destructor
scopesEnd:
- meta.function.destructor
- source: '{'
scopesBegin:
- meta.block
scopes:
- punctuation.section.block.begin.bracket.curly
- source: '}'
scopes:
- punctuation.section.block.end.bracket.curly
Loading