Skip to content
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

Named Arguments in Callbacks #78

Merged
merged 1 commit into from
Feb 28, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Features

- Property Change Callbacks
- Named Arguments in Callbacks

### Fixed

Expand Down
5 changes: 4 additions & 1 deletion src/main/grammars/SlintParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ private PropertyDefinitionInit::= (':' | '<=>') Expression
private CallbackDefinition ::= PURE? CALLBACK Identifier (CallbackParametersDeclaration | CallbackBindingDeclaration)? ';' {
pin=3
}
private CallbackParametersDeclaration ::= '(' Type? (',' (Type | &')'))* ')' CallbackReturnDeclaration? {
private CallbackParametersDeclaration ::= '(' CallbackNamedParameter? (',' (CallbackNamedParameter | &')'))* ')' CallbackReturnDeclaration? {
pin(".*")=1
}
private CallbackNamedParameter ::= Identifier ':' Type {
pin=3
}
private CallbackReturnDeclaration ::= '->' Type { pin=2 }
private CallbackBindingDeclaration ::= '<=>' PropertyExpression

Expand Down
9 changes: 9 additions & 0 deletions testData/ParsingTestData.slint
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,13 @@ export component Example inherits Window {
}
t := Text {}
}
}

// Named Arguments in Callbacks
export component NamedCallbackExample inherits Rectangle {
// Declare a callback with named argument
callback hello(foo: int, bar: string);
// The names can be overridden with
// anything when setting a handler
hello(aa, bb) => { /* ... */ }
}
73 changes: 71 additions & 2 deletions testData/ParsingTestData.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SLINT_FILE(0,3330)
SLINT_FILE(0,3627)
SlintImportDefinitionImpl(IMPORT_DEFINITION)(0,85)
PsiElement(import)('import')(0,6)
PsiWhiteSpace(' ')(6,7)
Expand Down Expand Up @@ -1105,4 +1105,73 @@ SLINT_FILE(0,3330)
PsiWhiteSpace('\n ')(3322,3327)
PsiElement(})('}')(3327,3328)
PsiWhiteSpace('\n')(3328,3329)
PsiElement(})('}')(3329,3330)
PsiElement(})('}')(3329,3330)
PsiWhiteSpace('\n\n')(3330,3332)
PsiComment(LINE_COMMENT)('// Named Arguments in Callbacks')(3332,3363)
PsiWhiteSpace('\n')(3363,3364)
PsiElement(export)('export')(3364,3370)
PsiWhiteSpace(' ')(3370,3371)
SlintComponentDefinitionImpl(COMPONENT_DEFINITION)(3371,3627)
PsiElement(component)('component')(3371,3380)
PsiWhiteSpace(' ')(3380,3381)
SlintComponentNameImpl(COMPONENT_NAME)(3381,3401)
PsiElement(IDENTIFIER)('NamedCallbackExample')(3381,3401)
PsiWhiteSpace(' ')(3401,3402)
PsiElement(inherits)('inherits')(3402,3410)
PsiWhiteSpace(' ')(3410,3411)
SlintComponentNameImpl(COMPONENT_NAME)(3411,3420)
PsiElement(IDENTIFIER)('Rectangle')(3411,3420)
PsiWhiteSpace(' ')(3420,3421)
SlintComponentBodyImpl(COMPONENT_BODY)(3421,3627)
PsiElement({)('{')(3421,3422)
PsiWhiteSpace('\n ')(3422,3427)
PsiComment(LINE_COMMENT)('// Declare a callback with named argument')(3427,3468)
PsiWhiteSpace('\n ')(3468,3473)
PsiElement(callback)('callback')(3473,3481)
PsiWhiteSpace(' ')(3481,3482)
PsiElement(IDENTIFIER)('hello')(3482,3487)
PsiElement(()('(')(3487,3488)
PsiElement(IDENTIFIER)('foo')(3488,3491)
PsiElement(BAD_CHARACTER)(':')(3491,3492)
PsiWhiteSpace(' ')(3492,3493)
SlintTypeImpl(TYPE)(3493,3496)
SlintBuiltinTypeImpl(BUILTIN_TYPE)(3493,3496)
PsiElement(IDENTIFIER)('int')(3493,3496)
PsiElement(,)(',')(3496,3497)
PsiWhiteSpace(' ')(3497,3498)
PsiElement(IDENTIFIER)('bar')(3498,3501)
PsiElement(BAD_CHARACTER)(':')(3501,3502)
PsiWhiteSpace(' ')(3502,3503)
SlintTypeImpl(TYPE)(3503,3509)
SlintBuiltinTypeImpl(BUILTIN_TYPE)(3503,3509)
PsiElement(IDENTIFIER)('string')(3503,3509)
PsiElement())(')')(3509,3510)
PsiElement(;)(';')(3510,3511)
PsiWhiteSpace('\n ')(3511,3516)
PsiComment(LINE_COMMENT)('// The names can be overridden with')(3516,3551)
PsiWhiteSpace('\n ')(3551,3556)
PsiComment(LINE_COMMENT)('// anything when setting a handler')(3556,3590)
PsiWhiteSpace('\n ')(3590,3595)
PsiElement(IDENTIFIER)('hello')(3595,3600)
PsiElement(()('(')(3600,3601)
SlintPropertyExpressionImpl(PROPERTY_EXPRESSION)(3601,3603)
SlintPropertyExpressionCompositeImpl(PROPERTY_EXPRESSION_COMPOSITE)(3601,3603)
PsiElement(IDENTIFIER)('aa')(3601,3603)
PsiElement(,)(',')(3603,3604)
PsiWhiteSpace(' ')(3604,3605)
SlintPropertyExpressionImpl(PROPERTY_EXPRESSION)(3605,3607)
SlintPropertyExpressionCompositeImpl(PROPERTY_EXPRESSION_COMPOSITE)(3605,3607)
PsiElement(IDENTIFIER)('bb')(3605,3607)
PsiElement())(')')(3607,3608)
PsiWhiteSpace(' ')(3608,3609)
PsiElement(=)('=')(3609,3610)
PsiElement(>)('>')(3610,3611)
PsiWhiteSpace(' ')(3611,3612)
SlintCallbackBodyImpl(CALLBACK_BODY)(3612,3625)
PsiElement({)('{')(3612,3613)
PsiWhiteSpace(' ')(3613,3614)
PsiComment(DOC_COMMENT)('/* ... */')(3614,3623)
PsiWhiteSpace(' ')(3623,3624)
PsiElement(})('}')(3624,3625)
PsiWhiteSpace('\n')(3625,3626)
PsiElement(})('}')(3626,3627)
Loading