typst icon indicating copy to clipboard operation
typst copied to clipboard

More helpful error message on `text*//`

Open astrale-sharp opened this issue 1 year ago • 10 comments
trafficstars

Description

No reason to fail there since we accept text//

Reproduction URL

No response

Operating system

No response

Typst version

  • [X] I am using the latest version of Typst

astrale-sharp avatar Mar 20 '24 14:03 astrale-sharp

I believe the reason for this is that commenting something out never fail due to spurious */. So, for instance you have a document:

"Hello W*/rld," says Karl the robot.

You can't really comment it out easily:

/*"Hello W*/rld," says Karl the robot.*/

frozolotl avatar Mar 20 '24 14:03 frozolotl

Oh great remark! If that's indeed the problem we could be a bit more explicit in the error message :thinking:

astrale-sharp avatar Mar 20 '24 15:03 astrale-sharp

@frozolotl is on point here with the reasoning. if the message is too vague, we can add a hint.

laurmaedje avatar Mar 20 '24 15:03 laurmaedje

I was thinking of adding the word ambiguous in the error but ambiguous end of comment is a bit long and not that clear

astrale-sharp avatar Mar 20 '24 19:03 astrale-sharp

The error message I get is error: unexpected end of block comment, which I think is clear. More ideas are unopened block comment closure/end or ambiguous block comment closure/end.

@laurmaedje Is the hint different than the message printed in the console?

jmskov avatar Apr 24 '24 23:04 jmskov

@laurmaedje Is the hint different than the message printed in the console?

Could you clarify what you mean?

laurmaedje avatar Apr 29 '24 13:04 laurmaedje

I wasn't sure about the mechanics of hints, but I've learned hints are inserted into an error message. We could insert the hints add \* to open the block comment and/or add space after * to avoid ambiguity or similar.

jmskov avatar Apr 29 '24 20:04 jmskov

The first one sounds fine. Regarding the second, it might be a better suggestion to escape the * since otherwise there'll (a) be a space, (b) the lone asterisk will be interpreted as syntax for strongly emphasized text.

laurmaedje avatar Apr 30 '24 09:04 laurmaedje

After poking around, it looks like the error member of the Lexer structure does not support adding hints , like SyntaxError. My initial idea is to use SyntaxError in the Lexer structure, but I am not sure if an easier solution exists (aside from putting the hints as newlines in the error message). I am still new to the whole architecture of this so I will think about it and learn more :)

jmskov avatar May 01 '24 02:05 jmskov

If switching the Lexer to SyntaxError doesn't cause any problems, it should be fine.

laurmaedje avatar May 01 '24 08:05 laurmaedje