Skip to content

Pack indexing #680

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions language_examples/pack_indexing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template <typename... T>
constexpr auto first_plus_last(T... values) -> T...[0] {
return T...[0](values...[0] + values...[sizeof...(values)-1]);
}
140 changes: 140 additions & 0 deletions language_examples/pack_indexing.spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
- source: template
scopes:
- storage.type.template
- source: <
scopes:
- punctuation.section.angle-brackets.begin.template.definition
- source: typename
scopesBegin:
- meta.template.definition
scopes:
- storage.type.template.argument.typename
- source: ...
scopes:
- punctuation.vararg-ellipses.template.definition
- source: T
scopes:
- entity.name.type.template
scopesEnd:
- meta.template.definition
- source: '>'
scopes:
- punctuation.section.angle-brackets.end.template.definition
- source: constexpr
scopesBegin:
- meta.function.definition
scopes:
- storage.modifier.constexpr
- source: auto
scopes:
- meta.qualified-type
- storage.type.primitive
- storage.type.built-in.primitive
- source: first_plus_last
scopesBegin:
- meta.head.function.definition
scopes:
- entity.name.function.definition
- source: (
scopes:
- punctuation.section.parameters.begin.bracket.round
- source: T
scopesBegin:
- meta.function.definition.parameters
- meta.parameter
scopes:
- entity.name.type.parameter
- source: ...
scopes:
- punctuation.vararg-ellipses
- source: values
scopes:
- variable.parameter
scopesEnd:
- meta.function.definition.parameters
- meta.parameter
- source: )
scopes:
- punctuation.section.parameters.end.bracket.round
- source: '->'
scopes:
- punctuation.separator.pointer-access
- source: T
scopes:
- variable.other.property
- source: ...
- source: '['
scopesBegin:
- meta.bracket.square.access
scopes:
- punctuation.definition.begin.bracket.square
- source: '0'
scopes:
- constant.numeric.decimal
- source: ']'
scopes:
- punctuation.definition.end.bracket.square
scopesEnd:
- meta.bracket.square.access
- source: '{'
scopes:
- punctuation.section.block.begin.bracket.curly.function.definition
scopesEnd:
- meta.head.function.definition
- source: return
scopesBegin:
- meta.body.function.definition
scopes:
- keyword.control.return
- source: 'T...['
- source: '0'
scopes:
- constant.numeric.decimal
- source: ']'
- source: (
scopesBegin:
- meta.parens
scopes:
- punctuation.section.parens.begin.bracket.round
- source: 'values...['
- source: '0'
scopes:
- constant.numeric.decimal
- source: ']'
- source: +
scopes:
- keyword.operator.arithmetic
- source: 'values...['
- source: sizeof...
scopes:
- keyword.operator.functionlike
- keyword.operator.sizeof.variadic
- source: (
scopes:
- punctuation.section.arguments.begin.bracket.round.operator.sizeof.variadic
- source: values
scopes:
- meta.arguments.operator.sizeof.variadic
- variable.lower-case
- variable.other.unknown.values
- source: )
scopes:
- punctuation.section.arguments.end.bracket.round.operator.sizeof.variadic
- source: '-'
scopes:
- keyword.operator.arithmetic
- source: '1'
scopes:
- constant.numeric.decimal
- source: ']'
- source: )
scopes:
- punctuation.section.parens.end.bracket.round
scopesEnd:
- meta.parens
- source: ;
scopes:
- punctuation.terminator.statement
- source: '}'
scopes:
- punctuation.section.block.end.bracket.curly.function.definition
18 changes: 18 additions & 0 deletions main/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
:functional_specifiers_pre_parameters, # TODO: these probably need to be moved inside the function definition pattern
:storage_types,
# misc
:pack_indexing,
:lambdas,
:attributes_context, # this is here because it needs to be lower than :operators. TODO: once all the contexts are cleaned up, this should be put in a better spot
:parentheses,
Expand Down Expand Up @@ -2204,6 +2205,23 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
],
)

#
# Pack indexing
#
grammar[:pack_indexing] = PatternRange.new(
start_pattern: Pattern.new(
match: identifier,
).maybe(@spaces).then(
match: /\.\.\./,
).maybe(@spaces).then(
match: /\[/,
),
end_pattern: Pattern.new(
match: /\]/,
),
includes: [:evaluation_context]
)

#
# Lambdas
#
Expand Down