diff --git a/language_tags/cpp.txt b/language_tags/cpp.txt index 54b515e3..ca951dfa 100644 --- a/language_tags/cpp.txt +++ b/language_tags/cpp.txt @@ -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 @@ -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 diff --git a/scripts/generate.rb b/scripts/generate.rb index 0c4aea27..42a155b8 100644 --- a/scripts/generate.rb +++ b/scripts/generate.rb @@ -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 diff --git a/scripts/lint.rb b/scripts/lint.rb index cbefd89c..ae0bad5b 100644 --- a/scripts/lint.rb +++ b/scripts/lint.rb @@ -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 \ No newline at end of file diff --git a/source/languages/cpp/generate.rb b/source/languages/cpp/generate.rb index 8aee1c6c..93d551d4 100644 --- a/source/languages/cpp/generate.rb +++ b/source/languages/cpp/generate.rb @@ -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, @@ -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, @@ -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 (?:(? { - 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 (?:(? { - 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((?#{preprocessor_name_no_bounds}))\t # macro name\n(?:\n (\\()\n\t(\n\t \\s* \\g \\s*\t\t # first argument\n\t ((,) \\s* \\g \\s*)* # additional arguments\n\t (?:\\.\\.\\.)?\t\t\t# varargs ellipsis?\n\t)\n (\\))\n)?", diff --git a/syntaxes/cpp.tmLanguage.json b/syntaxes/cpp.tmLanguage.json index e4eb8ce8..07846fad 100644 --- a/syntaxes/cpp.tmLanguage.json +++ b/syntaxes/cpp.tmLanguage.json @@ -199,9 +199,6 @@ { "include": "#destructor" }, - { - "include": "#destructor_prototype" - }, { "include": "#lambdas" }, @@ -405,9 +402,6 @@ { "include": "#destructor" }, - { - "include": "#destructor_prototype" - }, { "include": "#lambdas" }, @@ -5119,50 +5113,19 @@ "name": "storage.modifier.cpp" }, "destructor": { - "name": "meta.function.destructor.cpp", - "begin": "(?x)\n(?:\n ^ | # beginning of line\n (?:(?(?:[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 (?:(?(?:[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 - (?:(?(?-mix:[a-zA-Z_$][\\w$]*)))\t diff --git a/test/fixtures/issues/080.cpp b/test/fixtures/issues/080.cpp new file mode 100644 index 00000000..1debd58f --- /dev/null +++ b/test/fixtures/issues/080.cpp @@ -0,0 +1,5 @@ +class foo { + ~foo(); +}; +foo::~foo() {} +foo::~bar() {} \ No newline at end of file diff --git a/test/specs/issues/080.cpp.yaml b/test/specs/issues/080.cpp.yaml new file mode 100644 index 00000000..a1be8a52 --- /dev/null +++ b/test/specs/issues/080.cpp.yaml @@ -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 diff --git a/test/specs/vscode/misc.mm.yaml b/test/specs/vscode/misc.mm.yaml index 538be4c6..37be1d41 100644 --- a/test/specs/vscode/misc.mm.yaml +++ b/test/specs/vscode/misc.mm.yaml @@ -18,6 +18,8 @@ scopes: - entity.scope.name - source: '::' + scopes: + - punctuation.separator.namespace.access scopesEnd: - punctuation.separator.namespace.access - source: optional @@ -560,6 +562,8 @@ scopes: - entity.scope.name - source: '::' + scopes: + - punctuation.separator.namespace.access scopesEnd: - punctuation.separator.namespace.access - source: vector @@ -752,6 +756,8 @@ scopes: - entity.scope.name - source: '::' + scopes: + - punctuation.separator.namespace.access scopesEnd: - punctuation.separator.namespace.access - source: 'cout ' @@ -907,6 +913,8 @@ scopes: - entity.scope.name - source: '::' + scopes: + - punctuation.separator.namespace.access scopesEnd: - punctuation.separator.namespace.access - source: 'cout ' @@ -1062,6 +1070,8 @@ scopes: - entity.scope.name - source: '::' + scopes: + - punctuation.separator.namespace.access scopesEnd: - punctuation.separator.namespace.access - source: 'cout ' diff --git a/test/specs/vscode/misc001.cpp.yaml b/test/specs/vscode/misc001.cpp.yaml index 564ef437..e20dd52c 100644 --- a/test/specs/vscode/misc001.cpp.yaml +++ b/test/specs/vscode/misc001.cpp.yaml @@ -298,6 +298,7 @@ - meta.function.destructor scopes: - entity.name.function.destructor + - entity.name.function.special.destructor - source: ( scopes: - punctuation.definition.parameters.begin.destructor diff --git a/test/specs/vscode/misc004.m.yaml b/test/specs/vscode/misc004.m.yaml index 48df92da..62385501 100644 --- a/test/specs/vscode/misc004.m.yaml +++ b/test/specs/vscode/misc004.m.yaml @@ -79,17 +79,16 @@ - source: end scopesEnd: - meta.interface-or-protocol + - storage.type - source: '@' - scopes: + scopesBegin: - meta.implementation + - storage.type + scopes: - punctuation.definition.storage.type - scopesEnd: - - meta.interface-or-protocol - source: implementation - scopes: - - meta.implementation scopesEnd: - - meta.interface-or-protocol + - meta.implementation - storage.type - source: ViewController scopesBegin: