Arithmetic operator parsing inconsistency
Just a very minor bug/inconsistency but it may be noteworthy.
The - operator apparently needs a space before it when it is preceded by an identifier while the + operator does not. E.g.
#{
let a = 2;
a = a+1; // fine
a = 1-a; // fine
a = 2-3; // fine
a = a -1; // finer
a = a-1; // error
}
This is because that currently a- will be treated as an identifier.
See https://github.com/typst/typst/blob/bce83d330f0efc0f8cdd6fb01d8244cb9f01ac27/src/syntax/lexer.rs#L727
I think that - should stop being accepted as identifier continuations, but I'm interested in knowing whether this came from a request or was just there from the beginning.
(I noticed that the project is currently using unicode-xid, perhaps typst should use dtolnay's crate for better performance? https://github.com/dtolnay/unicode-ident)
Oh I see. Well, it is not really a problem but at first it is surprising and maybe a dedicated error message could be shown suggesting the solution in such a case.
Wait, I thought it was considered idiomatic to name variables, just as in Closure, with dashes:
let a-b = 7
Is this not the case? (This likely ties into #872).
I thought it was considered idiomatic to name variables, just as in Closure, with dashes
It is. It would still be nice to have a helpful hint if the variable does not exist. I'm leaving this issue open to track that hint.