Skip to content

Commit

Permalink
add function_pointer fix #26
Browse files Browse the repository at this point in the history
  • Loading branch information
matter123 committed May 10, 2019
1 parent 7f10704 commit 43726b7
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 44 deletions.
10 changes: 8 additions & 2 deletions cpp/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,12 @@ def blockFinderFor( name:"", tag_as:"", start_pattern:nil, needs_semicolon: true
#
# function pointer
#
array_brackets = /\[/.then(
match: /\w*/,
includes: [:evaluation_context]
).then(/\]/).maybe(@spaces)
after_declaration = maybe(@spaces).lookAheadToAvoid(/\(/).zeroOrMoreOf(array_brackets)
.lookAheadFor(/[{=,);]|\n/)
cpp_grammar[:function_pointer] = PatternRange.new(
start_pattern: qualified_type.maybe(@spaces).then(/\(/).maybe(@spaces).then(
match: /\*/,
Expand All @@ -823,7 +829,7 @@ def blockFinderFor( name:"", tag_as:"", start_pattern:nil, needs_semicolon: true
).maybe(@spaces).zeroOrMoreOf(array_brackets).then(/\)/).maybe(@spaces).then(/\(/),
end_pattern: /\)/.then(after_declaration),
includes: [
:function_parameters,
:parameter_struct, :function_context_c,
]
)
#
Expand Down Expand Up @@ -1211,7 +1217,7 @@ def blockFinderFor( name:"", tag_as:"", start_pattern:nil, needs_semicolon: true
:template_call_range,
:comments_context,
],
body_includes: [ :constructor_context, :$initial_context ],
body_includes: [ :function_pointer, :constructor_context, :$initial_context ],
)
end
cpp_grammar[:class_block] = generateClassOrStructBlockFinder["class"]
Expand Down
3 changes: 3 additions & 0 deletions cpp/tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ entity.name.function.preprocessor.cpp
entity.name.operator.overloadee.cpp
entity.name.tag.pragma-mark.cpp
entity.name.type.$3.cpp
entity.name.type.cpp
entity.name.type.enum.cpp
entity.name.type.inherited.cpp
entity.name.type.namespace.cpp
Expand Down Expand Up @@ -143,6 +144,7 @@ meta.preprocessor.diagnostic.cpp
meta.preprocessor.include.cpp
meta.preprocessor.macro.cpp
meta.preprocessor.pragma.cpp
meta.qualified_type.cpp
meta.scope-resolution.cpp
meta.section.cpp
meta.static_assert.message.cpp
Expand Down Expand Up @@ -289,6 +291,7 @@ variable.other.object.access.cpp
variable.other.object.cpp
variable.other.object.declare.cpp
variable.other.object.property.cpp
variable.other.pointer.function.cpp
variable.other.property.cpp
variable.parameter.cpp
variable.parameter.defaulted.cpp
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/cpp.tmLanguage.json

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions syntaxes/cpp.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,35 @@
'4':
name: punctuation.separator.namespace.access.cpp
name: meta.scope-resolution.cpp
qualified_type:
match: "\\s*(?<!\\w)(?=\\w)(?!(?:not|compl|sizeof|new|delete|not_eq|bitand|xor|bitor|and|or|throw|and_eq|xor_eq|or_eq|alignof|alignas|typeid|noexcept|static_cast|dynamic_cast|const_cast|reinterpret_cast|while|for|do|if|else|goto|switch|try|catch|return|break|case|continue|default|NULL|true|false|nullptr|const|static|volatile|register|restrict|extern|inline|constexpr|mutable|friend|explicit|virtual|final|override|volatile|const|noexcept|constexpr|mutable|constexpr|consteval|private|protected|public|if|elif|else|endif|ifdef|ifndef|define|undef|include|line|error|warning|pragma|_Pragma|defined|__has_include|__has_cpp_attribute|this|template|namespace|using|operator|typedef|decltype|typename|asm|__asm__|concept|requires|export|thread_local|atomic_cancel|atomic_commit|atomic_noexcept|co_await|co_return|co_yield|import|module|reflexpr|synchronized|audit|axiom|transaction_safe|transaction_safe_dynamic)(?![\\w])\\s*)(?:((?:(?:(?:\\[\\[).*?(?:\\]\\])|(?:__attribute\\(\\(|__attribute__\\(\\().*?(?:\\)\\)))|(?:__declspec\\().*?(?:\\)))(?!\\))))?\\s*(?:(?:(?:short|signed|unsigned|long)|(?:class|struct|union|enum))\\s+)*(?:(((?:(?:[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*(?:(?-mix:(?:(?<!<)<(?!<)(?:[\\s<>:,\\w])*>\\s*)))?::)*\\s*)((?:[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<>:,\\w])*>\\s*))?(::)))?\\s*(?:[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])))*(?:(?-mix:(?:(?<!<)<(?!<)(?:[\\s<>:,\\w])*>\\s*)))?(?![\\w<:.])"
captures:
'0':
name: entity.name.type.cpp meta.qualified_type.cpp
patterns:
- match: "(?:class|struct|union|enum)"
name: storage.type.$0.cpp
- include: "#function_type"
- include: "#storage_types"
- include: "#number_literal"
- include: "#string_context_c"
- include: "#comma"
'1':
patterns:
- include: "#attributes"
'2':
name: meta.scope-resolution.cpp
'3':
patterns:
- include: "#scope_resolution"
'4':
name: entity.name.type.namespace.scope-resolution.cpp
'5':
name: meta.template.call.cpp
patterns:
- include: "#template_call_context"
'6':
name: punctuation.separator.namespace.access.cpp
struct_declare:
match: "(struct)\\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))\\s+((?:\\*|&\\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))"
captures:
Expand Down Expand Up @@ -703,6 +732,50 @@
assignment_operator:
match: "\\="
name: keyword.operator.assignment.cpp
function_pointer:
begin: "(\\s*(?<!\\w)(?=\\w)(?!(?:not|compl|sizeof|new|delete|not_eq|bitand|xor|bitor|and|or|throw|and_eq|xor_eq|or_eq|alignof|alignas|typeid|noexcept|static_cast|dynamic_cast|const_cast|reinterpret_cast|while|for|do|if|else|goto|switch|try|catch|return|break|case|continue|default|NULL|true|false|nullptr|const|static|volatile|register|restrict|extern|inline|constexpr|mutable|friend|explicit|virtual|final|override|volatile|const|noexcept|constexpr|mutable|constexpr|consteval|private|protected|public|if|elif|else|endif|ifdef|ifndef|define|undef|include|line|error|warning|pragma|_Pragma|defined|__has_include|__has_cpp_attribute|this|template|namespace|using|operator|typedef|decltype|typename|asm|__asm__|concept|requires|export|thread_local|atomic_cancel|atomic_commit|atomic_noexcept|co_await|co_return|co_yield|import|module|reflexpr|synchronized|audit|axiom|transaction_safe|transaction_safe_dynamic)(?![\\w])\\s*)(?:((?:(?:(?:\\[\\[).*?(?:\\]\\])|(?:__attribute\\(\\(|__attribute__\\(\\().*?(?:\\)\\)))|(?:__declspec\\().*?(?:\\)))(?!\\))))?\\s*(?:(?:(?:short|signed|unsigned|long)|(?:class|struct|union|enum))\\s+)*(?:(((?:(?:[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*(?:(?-mix:(?:(?<!<)<(?!<)(?:[\\s<>:,\\w])*>\\s*)))?::)*\\s*)((?:[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<>:,\\w])*>\\s*))?(::)))?\\s*(?:[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])))*(?:(?-mix:(?:(?<!<)<(?!<)(?:[\\s<>:,\\w])*>\\s*)))?(?![\\w<:.]))\\s*\\(\\s*(\\*)\\s*((?:[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*(?:\\[(\\w*)\\]\\s*)*\\)\\s*\\("
beginCaptures:
'1':
name: entity.name.type.cpp meta.qualified_type.cpp
patterns:
- match: "(?:class|struct|union|enum)"
name: storage.type.$0.cpp
- include: "#function_type"
- include: "#storage_types"
- include: "#number_literal"
- include: "#string_context_c"
- include: "#comma"
'2':
patterns:
- include: "#attributes"
'3':
name: meta.scope-resolution.cpp
'4':
patterns:
- include: "#scope_resolution"
'5':
name: entity.name.type.namespace.scope-resolution.cpp
'6':
name: meta.template.call.cpp
patterns:
- include: "#template_call_context"
'7':
name: punctuation.separator.namespace.access.cpp
'8':
name: variable.other.pointer.function.cpp
'9':
name: variable.other.pointer.function.cpp
'10':
patterns:
- include: "#evaluation_context"
end: "\\)\\s*(?!\\()(?:\\[(\\w*)\\]\\s*)*(?=[{=,);]|\\n)"
endCaptures:
'1':
patterns:
- include: "#evaluation_context"
patterns:
- include: "#parameter_struct"
- include: "#function_context_c"
probably_a_parameter:
match: "(?:((?:[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*(?==))|((?<=\\w
|\\*\\/|[&*>\\]\\)]|\\.\\.\\.)\\s*(?:[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*)?(?:,|\\)))))"
Expand Down Expand Up @@ -1044,6 +1117,7 @@
'1':
name: punctuation.section.block.end.bracket.curly.class.cpp
patterns:
- include: "#function_pointer"
- include: "#constructor_context"
- include: "$base"
- name: meta.tail.class.cpp
Expand Down Expand Up @@ -1099,6 +1173,7 @@
'1':
name: punctuation.section.block.end.bracket.curly.struct.cpp
patterns:
- include: "#function_pointer"
- include: "#constructor_context"
- include: "$base"
- name: meta.tail.struct.cpp
Expand Down Expand Up @@ -1154,6 +1229,7 @@
'1':
name: punctuation.section.block.end.bracket.curly.union.cpp
patterns:
- include: "#function_pointer"
- include: "#constructor_context"
- include: "$base"
- name: meta.tail.union.cpp
Expand Down
55 changes: 14 additions & 41 deletions test/specs/issues/026.cpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,19 @@
- source: int
scopesBegin:
- meta.body.struct.cpp
- meta.function.constructor.cpp
scopes:
- entity.name.function.constructor.cpp
- source: (
scopes:
- punctuation.definition.parameters.begin.constructor.cpp
- entity.name.type
- meta.qualified_type
- storage.type.primitive
- source: ' ('
- source: '*'
scopes:
- keyword.operator.cpp
- variable.other.pointer.function
- source: bar
scopes:
- variable.parameter.cpp
- source: )
scopes:
- punctuation.definition.parameters.end.constructor.cpp
scopesEnd:
- meta.function.constructor.cpp
- source: (
scopesBegin:
- meta.parens.cpp
scopes:
- punctuation.section.parens.begin.bracket.round.cpp
- variable.other.pointer.function
- source: )(
- source: )
scopes:
- punctuation.section.parens.end.bracket.round.cpp
scopesEnd:
- meta.parens.cpp
- source: ;
scopes:
- punctuation.terminator.statement.cpp
Expand Down Expand Up @@ -72,33 +58,20 @@
- source: int
scopesBegin:
- meta.body.union.cpp
- meta.function.constructor.cpp
scopes:
- entity.name.function.constructor.cpp
- source: (
scopes:
- punctuation.definition.parameters.begin.constructor.cpp
- entity.name.type
- meta.qualified_type
- storage.type.primitive
- source: ' ('
- source: '*'
scopes:
- keyword.operator.cpp
- variable.other.pointer.function
- source: quz
scopes:
- variable.parameter.cpp
- variable.other.pointer.function
- source: )(
- source: )
scopes:
- punctuation.definition.parameters.end.constructor.cpp
scopesEnd:
- meta.function.constructor.cpp
- source: (
scopesBegin:
- meta.parens.cpp
scopes:
- punctuation.section.parens.begin.bracket.round.cpp
- source: )
scopes:
- punctuation.section.parens.end.bracket.round.cpp
scopesEnd:
- meta.parens.cpp
- source: ;
scopes:
- punctuation.terminator.statement.cpp
Expand Down

0 comments on commit 43726b7

Please sign in to comment.