diff --git a/cpp/generate.rb b/cpp/generate.rb index 65958753..5263c2fb 100644 --- a/cpp/generate.rb +++ b/cpp/generate.rb @@ -209,14 +209,16 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon: :probably_a_parameter, :attributes_context, :comments_context, - :string_context, - :string_context_c, :storage_types, - :operators, :vararg_ellipses, :function_pointer, :comma, - :string + # the following are a temp workaround for defaulted arguments + # e.g. aFunc(int a = 10 + 10) + :language_constants, + :number_literal, + :string_context, + :operators, ] # eventually this context will be more exclusive (can't have class definitons inside of an evaluation) # but for now it just includes everything @@ -823,7 +825,10 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon: tag_as: "punctuation.section.parameters.end.bracket.round" ), includes: [ - :function_parameter_context + :function_parameter_context, + # TODO: the function_call_context is included here as workaround for function-initializations like issue #198 + # e.g. std::string ("hello"); + :function_call_context, ] ) ], @@ -1004,7 +1009,7 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon: tag_as: "punctuation.section.parameters.end.bracket.round.function.pointer" ).then(after_declaration), includes: [ - :function_parameter_context + :function_parameter_context, ] ) # @@ -3236,6 +3241,7 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon: :attributes_context, :comments_context, :operators, + :string_context, :storage_types, :method_access, :member_access, diff --git a/syntaxes/cpp.tmLanguage.json b/syntaxes/cpp.tmLanguage.json index 481c1682..7f594bd0 100644 --- a/syntaxes/cpp.tmLanguage.json +++ b/syntaxes/cpp.tmLanguage.json @@ -336,28 +336,28 @@ "include": "#comments_context" }, { - "include": "#string_context" + "include": "#storage_types" }, { - "include": "#string_context_c" + "include": "#vararg_ellipses" }, { - "include": "#storage_types" + "include": "#function_pointer" }, { - "include": "#operators" + "include": "#comma" }, { - "include": "#vararg_ellipses" + "include": "#language_constants" }, { - "include": "#function_pointer" + "include": "#number_literal" }, { - "include": "#comma" + "include": "#string_context" }, { - "include": "#string" + "include": "#operators" } ] }, @@ -2078,6 +2078,9 @@ "patterns": [ { "include": "#function_parameter_context" + }, + { + "include": "#function_call_context" } ] } @@ -5651,6 +5654,9 @@ { "include": "#operators" }, + { + "include": "#string_context" + }, { "include": "#storage_types" }, diff --git a/syntaxes/cpp.tmLanguage.yaml b/syntaxes/cpp.tmLanguage.yaml index c62520b1..71315dca 100644 --- a/syntaxes/cpp.tmLanguage.yaml +++ b/syntaxes/cpp.tmLanguage.yaml @@ -155,14 +155,14 @@ - include: "#probably_a_parameter" - include: "#attributes_context" - include: "#comments_context" - - include: "#string_context" - - include: "#string_context_c" - include: "#storage_types" - - include: "#operators" - include: "#vararg_ellipses" - include: "#function_pointer" - include: "#comma" - - include: "#string" + - include: "#language_constants" + - include: "#number_literal" + - include: "#string_context" + - include: "#operators" evaluation_context: patterns: - include: "$base" @@ -1096,6 +1096,7 @@ name: punctuation.section.parameters.end.bracket.round.cpp patterns: - include: "#function_parameter_context" + - include: "#function_call_context" - name: meta.body.function.definition.cpp begin: "(?<=\\{)" end: "(\\})" @@ -3055,6 +3056,7 @@ - include: "#attributes_context" - include: "#comments_context" - include: "#operators" + - include: "#string_context" - include: "#storage_types" - include: "#method_access" - include: "#member_access" diff --git a/test/fixtures/issues/198.cpp b/test/fixtures/issues/198.cpp new file mode 100644 index 00000000..ee960d19 --- /dev/null +++ b/test/fixtures/issues/198.cpp @@ -0,0 +1,5 @@ +#include + +std::string s = "correct"; +std::string s("incorrect"); +std::string s("?"); // incorrect \ No newline at end of file diff --git a/test/specs/issues/002.cpp.yaml b/test/specs/issues/002.cpp.yaml index 22e4b0a5..19702fe9 100644 --- a/test/specs/issues/002.cpp.yaml +++ b/test/specs/issues/002.cpp.yaml @@ -69,8 +69,7 @@ - source: '::' scopes: - punctuation.separator.namespace.access - - >- - punctuation.separator.scope-resolution.function.definition.operator-overload + - punctuation.separator.scope-resolution.function.definition.operator-overload - source: string & scopesEnd: - entity.name.operator.overloadee diff --git a/test/specs/issues/055.cpp.yaml b/test/specs/issues/055.cpp.yaml index 51a6cd4d..fa9f6680 100644 --- a/test/specs/issues/055.cpp.yaml +++ b/test/specs/issues/055.cpp.yaml @@ -49,20 +49,27 @@ - source: ( scopes: - punctuation.section.parameters.begin.bracket.round -- source: 'enum foo::bar::baz ' +- source: 'enum' scopesBegin: - meta.function.definition.parameters -- source: quix + - meta.block.enum + - meta.head.enum scopes: - - variable.parameter - scopesEnd: - - meta.function.definition.parameters -- source: ) + - storage.type.enum +- source: foo + scopes: + - entity.name.type.enum +- source: '::' +- source: bar scopes: - - punctuation.section.parameters.end.bracket.round + - entity.name.scope-resolution +- source: '::' + scopes: + - punctuation.separator.namespace.access + - punctuation.separator.scope-resolution +- source: 'baz quix)' scopesEnd: - - meta.function.definition - - meta.head.function.definition + - meta.head.enum - source: ; scopes: - punctuation.terminator.statement diff --git a/test/specs/issues/158.cpp.yaml b/test/specs/issues/158.cpp.yaml index bee53d66..a1d44f56 100644 --- a/test/specs/issues/158.cpp.yaml +++ b/test/specs/issues/158.cpp.yaml @@ -71,7 +71,9 @@ - source: = scopes: - keyword.operator.assignment -- source: ' false' +- source: 'false' + scopes: + - constant.language.false scopesEnd: - meta.function.definition.parameters - source: ) diff --git a/test/specs/issues/198.cpp.yaml b/test/specs/issues/198.cpp.yaml new file mode 100644 index 00000000..fcef9621 --- /dev/null +++ b/test/specs/issues/198.cpp.yaml @@ -0,0 +1,142 @@ +- source: '#' + scopesBegin: + - meta.preprocessor.include + - keyword.control.directive.include + scopes: + - punctuation.definition.directive +- source: include + scopesEnd: + - keyword.control.directive.include +- source: < + scopesBegin: + - string.quoted.other.lt-gt.include + scopes: + - punctuation.definition.string.begin +- source: string +- source: '>' + scopes: + - punctuation.definition.string.end + scopesEnd: + - meta.preprocessor.include + - string.quoted.other.lt-gt.include +- source: std + scopes: + - entity.name.scope-resolution +- source: '::' + scopes: + - punctuation.separator.namespace.access + - punctuation.separator.scope-resolution +- source: 'string s ' +- source: = + scopes: + - keyword.operator.assignment +- source: '"' + scopesBegin: + - string.quoted.double + scopes: + - punctuation.definition.string.begin +- source: correct +- source: '"' + scopes: + - punctuation.definition.string.end + scopesEnd: + - string.quoted.double +- source: ; + scopes: + - punctuation.terminator.statement +- source: std + scopesBegin: + - meta.function.definition + - meta.qualified_type + scopes: + - entity.name.scope-resolution +- source: '::' + scopes: + - punctuation.separator.namespace.access + - punctuation.separator.scope-resolution +- source: string + scopes: + - entity.name.type + scopesEnd: + - meta.qualified_type +- source: s + scopesBegin: + - meta.head.function.definition + scopes: + - entity.name.function.definition +- source: ( + scopes: + - punctuation.section.parameters.begin.bracket.round +- source: '"' + scopesBegin: + - meta.function.definition.parameters + - string.quoted.double + scopes: + - punctuation.definition.string.begin +- source: incorrect +- source: '"' + scopes: + - punctuation.definition.string.end + scopesEnd: + - meta.function.definition.parameters + - string.quoted.double +- source: ) + scopes: + - punctuation.section.parameters.end.bracket.round + scopesEnd: + - meta.function.definition + - meta.head.function.definition +- source: ; + scopes: + - punctuation.terminator.statement +- source: std + scopesBegin: + - meta.function.definition + - meta.qualified_type + scopes: + - entity.name.scope-resolution +- source: '::' + scopes: + - punctuation.separator.namespace.access + - punctuation.separator.scope-resolution +- source: string + scopes: + - entity.name.type + scopesEnd: + - meta.qualified_type +- source: s + scopesBegin: + - meta.head.function.definition + scopes: + - entity.name.function.definition +- source: ( + scopes: + - punctuation.section.parameters.begin.bracket.round +- source: '"' + scopesBegin: + - meta.function.definition.parameters + - string.quoted.double + scopes: + - punctuation.definition.string.begin +- source: '?' +- source: '"' + scopes: + - punctuation.definition.string.end + scopesEnd: + - meta.function.definition.parameters + - string.quoted.double +- source: ) + scopes: + - punctuation.section.parameters.end.bracket.round + scopesEnd: + - meta.function.definition + - meta.head.function.definition +- source: ; + scopes: + - punctuation.terminator.statement +- source: // + scopesBegin: + - comment.line.double-slash + scopes: + - punctuation.definition.comment +- source: ' incorrect' diff --git a/test/specs/test.cpp.yaml b/test/specs/test.cpp.yaml index e80c45bd..aa83242d 100644 --- a/test/specs/test.cpp.yaml +++ b/test/specs/test.cpp.yaml @@ -45,7 +45,7 @@ - source: ' a comment /* no nest */' scopesEnd: - comment.line.double-slash -- source: /* +- source: '/*' scopesBegin: - comment.block scopes: @@ -54,3 +54,5 @@ - source: '*/' scopes: - punctuation.definition.comment.end + scopesEnd: + - comment.block