scriban / scriban

A fast, powerful, safe and lightweight scripting language and engine for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function pointer parsing when not the last argument

barclayadam opened this issue · comments

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

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.