fix(failed): show function
On my daily check if I can resolve some bugs in Amber I tried with https://github.com/amber-lang/amber/issues/210
I am not sure about meta.get_index() - 4 to get the function with the issue.
Using the amberr code:
import * from "std/text"
// Output
// 123
main {
echo parse("123")
}
The meta is:
Context { index: 15, expr: [Tok[import 1:1], Tok[* 1:8], Tok[from 1:10], Tok["std/text" 1:15], Tok[// Output
3:1], Tok[<new_line> 3:10], Tok[// 123
4:1], Tok[<new_line> 4:7], Tok[main 6:1], Tok[<symbol: { > 6:6], Tok[echo 7:5], Tok[parse 7:10], Tok[<symbol: ( > 7:15], Tok["123" 7:16], Tok[<symbol: ) > 7:21], Tok[<symbol: } > 8:1]]
REDACTED
So I think that the actual index is always the next symbol where it should be the failed, in this case a }, followed by the closing parenthesis of the function, the parameters, the open parenthesis and finally the function name.
Right now amber doesn't share in the context what is the function or the line is processing, but in this way with - 4 we start from the end that it is more easy to be right so we can ignore the echo token.
Anyway I am not so skilled in the internals but let me know if needs some changes internally before to be able to close that ticket.
One way we could solve this is by including an fun_name: Option<string> in the struct of this syntax module and let the function invocation module set the function name. Then if fun_name has Some we can print the alternative error message.
If this sounds convoluted, I'll open my PR tomorrow to show what I mean
You know better than anyone else so I think that your proposal is good. The purpose of the PR was to close the issue with adding the error message that it was missing (yet).
I'll try to get my hands on this pull request in a few days
@Ph0enixKM can you check this PR now that the new translation layer was added?
I've improved on this error (it didn't highlight the function at all)
Replaced by https://github.com/amber-lang/amber/pull/769