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

Function pointer parsing when not the last argument #516

Open
barclayadam opened this issue Aug 23, 2023 · 1 comment
Open

Function pointer parsing when not the last argument #516

barclayadam opened this issue Aug 23, 2023 · 1 comment

Comments

@barclayadam
Copy link

I am looking to implement an array.any function that can be passed a function, which in many cases needs to be curried with additional arguments. For example:

{{ ["", "200",  "400"] | array.any @string.contains '20' }}

This is using a function declared as:

public static bool Any(TemplateContext context, SourceSpan span, IEnumerable? list, object? function, object[] args)

Given the above an error is thrown:

Invalid number of arguments `1` passed to `string.contains '20'` while expecting `2` arguments

It appears that during parsing this is being treated as a function call to string.contains, instead of a function pointer plus additional arguments to the array.any function call

I tried using named arguments, but that does not help (i.e. array.any function: @string.contains args: '20')

I think the @ operator needs to be less greedy, to only capture the function itself (which may be from a member access), but to not parse as an actual function call, but not sure if this is intended / desired or if there is possibly a different workaround

@xoofx xoofx added the bug label Sep 6, 2023
@xoofx
Copy link
Member

xoofx commented Sep 6, 2023

I think the @ operator needs to be less greedy, to only capture the function itself (which may be from a member access), but to not parse as an actual function call, but not sure if this is intended / desired or if there is possibly a different workaround

Agreed, might be a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants