diff --git a/language_tags/cpp.txt b/language_tags/cpp.txt index 90bb17c3..8aa9c9d3 100644 --- a/language_tags/cpp.txt +++ b/language_tags/cpp.txt @@ -32,6 +32,8 @@ entity.name.function.definition.special.member.destructor.cpp entity.name.function.destructor.cpp entity.name.function.member.cpp entity.name.function.preprocessor.cpp +entity.name.label.call.cpp +entity.name.label.cpp entity.name.namespace.alias.cpp entity.name.namespace.cpp entity.name.operator.cpp @@ -342,6 +344,7 @@ keyword.control.directive.pragma.cpp keyword.control.directive.pragma.pragma-mark.cpp keyword.control.directive.undef.cpp keyword.control.exception.$0.cpp +keyword.control.goto.cpp keyword.control.switch.cpp keyword.operator.$0.cpp keyword.operator.alignas.cpp @@ -584,6 +587,7 @@ punctuation.separator.delimiter.inheritance.cpp punctuation.separator.dot-access.cpp punctuation.separator.inheritance.cpp punctuation.separator.initializers.cpp +punctuation.separator.label.cpp punctuation.separator.namespace.access.cpp punctuation.separator.parameters.cpp punctuation.separator.pointer-access.cpp diff --git a/package.json b/package.json index 3d39cd97..979d2432 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Better Syntax", "description": "The bleeding edge of C-like syntaxes", "icon": "icon.png", - "version": "1.12.4", + "version": "1.12.5", "scripts": { "build": "ruby scripts/generate.rb", "perfall": "ruby scripts/perf_all.rb", diff --git a/source/languages/cpp/generate.rb b/source/languages/cpp/generate.rb index 8c4b5fff..3f33efc2 100644 --- a/source/languages/cpp/generate.rb +++ b/source/languages/cpp/generate.rb @@ -240,8 +240,10 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon: # TODO: fill out all of the statements here, variable declares, assignment, etc # control flow :switch_statement, # needs to be above the "switch" keyword (which will eventually be removed) + :goto_statement, # eventually, probably, the evaluation_context should be removed from here - :evaluation_context + :evaluation_context, + :label ] cpp_grammar[:evaluation_context] = [ :ever_present_context, @@ -563,6 +565,26 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon: # # Control flow # + cpp_grammar[:goto_statement] = newPattern( + newPattern( + match: variableBounds[/goto/], + tag_as: "keyword.control.goto", + ).then(std_space).then( + match: identifier, + tag_as: "entity.name.label.call" + ) + ) + cpp_grammar[:label] = newPattern( + std_space.then( + tag_as: "entity.name.label", + match: variableBounds[identifier], + ).then(@word_boundary).lookBehindToAvoid(/case|default/).then( + std_space + ).then( + match: /:/, + tag_as: "punctuation.separator.label", + ) + ) cpp_grammar[:default_statement] = PatternRange.new( tag_as: "meta.conditional.case", start_pattern: newPattern( diff --git a/syntaxes/cpp.tmLanguage.json b/syntaxes/cpp.tmLanguage.json index 9882e150..107e105b 100644 --- a/syntaxes/cpp.tmLanguage.json +++ b/syntaxes/cpp.tmLanguage.json @@ -532,8 +532,14 @@ { "include": "#switch_statement" }, + { + "include": "#goto_statement" + }, { "include": "#evaluation_context" + }, + { + "include": "#label" } ] }, @@ -1212,6 +1218,103 @@ "match": "(?\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))*)", + "captures": { + "1": { + "name": "keyword.control.goto.cpp" + }, + "2": { + "patterns": [ + { + "include": "#inline_comment" + } + ] + }, + "3": { + "name": "comment.block.cpp punctuation.definition.comment.begin.cpp" + }, + "4": { + "name": "comment.block.cpp" + }, + "5": { + "patterns": [ + { + "match": "\\*\\/", + "name": "comment.block.cpp punctuation.definition.comment.end.cpp" + }, + { + "match": "\\*", + "name": "comment.block.cpp" + } + ] + }, + "6": { + "name": "entity.name.label.call.cpp" + } + } + }, + "label": { + "match": "((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))(:)", + "captures": { + "1": { + "patterns": [ + { + "include": "#inline_comment" + } + ] + }, + "2": { + "name": "comment.block.cpp punctuation.definition.comment.begin.cpp" + }, + "3": { + "name": "comment.block.cpp" + }, + "4": { + "patterns": [ + { + "match": "\\*\\/", + "name": "comment.block.cpp punctuation.definition.comment.end.cpp" + }, + { + "match": "\\*", + "name": "comment.block.cpp" + } + ] + }, + "5": { + "name": "entity.name.label.cpp" + }, + "6": { + "patterns": [ + { + "include": "#inline_comment" + } + ] + }, + "7": { + "name": "comment.block.cpp punctuation.definition.comment.begin.cpp" + }, + "8": { + "name": "comment.block.cpp" + }, + "9": { + "patterns": [ + { + "match": "\\*\\/", + "name": "comment.block.cpp punctuation.definition.comment.end.cpp" + }, + { + "match": "\\*", + "name": "comment.block.cpp" + } + ] + }, + "10": { + "name": "punctuation.separator.label.cpp" + } + } + }, "default_statement": { "name": "meta.conditional.case.cpp", "begin": "((?\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))*)" + captures: + '1': + name: keyword.control.goto.cpp + '2': + patterns: + - include: "#inline_comment" + '3': + name: comment.block.cpp punctuation.definition.comment.begin.cpp + '4': + name: comment.block.cpp + '5': + patterns: + - match: "\\*\\/" + name: comment.block.cpp punctuation.definition.comment.end.cpp + - match: "\\*" + name: comment.block.cpp + '6': + name: entity.name.label.call.cpp + label: + match: "((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))(:)" + captures: + '1': + patterns: + - include: "#inline_comment" + '2': + name: comment.block.cpp punctuation.definition.comment.begin.cpp + '3': + name: comment.block.cpp + '4': + patterns: + - match: "\\*\\/" + name: comment.block.cpp punctuation.definition.comment.end.cpp + - match: "\\*" + name: comment.block.cpp + '5': + name: entity.name.label.cpp + '6': + patterns: + - include: "#inline_comment" + '7': + name: comment.block.cpp punctuation.definition.comment.begin.cpp + '8': + name: comment.block.cpp + '9': + patterns: + - match: "\\*\\/" + name: comment.block.cpp punctuation.definition.comment.end.cpp + - match: "\\*" + name: comment.block.cpp + '10': + name: punctuation.separator.label.cpp default_statement: name: meta.conditional.case.cpp begin: "((?