Skip to content

Document integer literal parsing#5462

Merged
laurmaedje merged 2 commits intotypst:mainfrom
jakobjpeters:integer_literal_documentation
Dec 8, 2024
Merged

Document integer literal parsing#5462
laurmaedje merged 2 commits intotypst:mainfrom
jakobjpeters:integer_literal_documentation

Conversation

@jakobjpeters
Copy link
Contributor

Closes #2284

@PgBiel
Copy link
Contributor

PgBiel commented Nov 24, 2024

To be honest, besides the documentation addition, I'd also prefer to add a warning when using a literal that is out of bounds. This behavior seems too unpredictable to me, as is. (Or, should I say, rather surprising.)

@jakobjpeters
Copy link
Contributor Author

jakobjpeters commented Nov 24, 2024

It looks like it happens here. Can you give a hint about how to implement such a warning? Or alternatively, I can make it produce an error guiding the user to use a float instead.

@wrzian
Copy link
Contributor

wrzian commented Nov 24, 2024

We don't yet have any real infrastructure for adding warnings to the parser (I ran into this as well in #5229). We do have error infrastructure, so we could also just start by erroring on out-of-bounds literals. If we do want warnings, then there are many ways we could do so.

One way to add parser warnings may be to add a Warning variant to the SyntaxKind enum and extend the options for SyntaxNode::Repr to include warnings and an interface for creating them. Warning nodes could then transparently wrap an underlying SyntaxNode plus the warning and any hints, and we would expose a new set of functions from SyntaxNode to access them.

However, I would recommend that we discuss if this is the right design before starting to implement it. Best would be to join the contributors channel on Discord, but we could also continue here (maybe in a new issue).

And if you want any help talking through the parser infrastructure, let me know!

@laurmaedje laurmaedje enabled auto-merge December 8, 2024 16:50
@laurmaedje
Copy link
Member

Thanks!

Since implementing a warning is a little more complex, let's not block this on it.

@laurmaedje laurmaedje added this pull request to the merge queue Dec 8, 2024
Merged via the queue into typst:main with commit 57f7c16 Dec 8, 2024
@jakobjpeters jakobjpeters deleted the integer_literal_documentation branch December 18, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Min integer value gets parsed as a float

4 participants