silverbulletmd / silverbullet

The knowledge hacker's notebook
https://silverbullet.md
MIT License
2.14k stars 155 forks source link

Passing negative numbers as space script arguments #691

Closed Maarrk closed 5 months ago

Maarrk commented 5 months ago

Space script throws a parse error when passing a negative number directly:

Error: Parse error in: addDays(today(), -7)

Demonstrated in the following page:

```space-script
silverbullet.registerFunction("addDays", (date, days) => {
  const plainDate = Temporal.PlainDate.from(date);
  const offsetDate = plainDate.add(Temporal.Duration.from({ days: Number(days) }));
  return offsetDate.toString();
});
```

Works:
```template
{{addDays(today(), 7)}}
```

Doesn't work:
```template
{{addDays(today(), -7)}}
```

Works:
```template
{{addDays(today(), 0-7)}}
```

Works if there is conversion with Number inside function:
```template
{{addDays(today(), '-7')}}
```
zefhemel commented 5 months ago

Heh. Right. Probably didn't add negative numbers to the expression language grammar yet.