Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misparsing floats/ints starting with zeroes #157

Open
yorickvP opened this issue Mar 9, 2023 · 5 comments
Open

misparsing floats/ints starting with zeroes #157

yorickvP opened this issue Mar 9, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@yorickvP
Copy link

yorickvP commented Mar 9, 2023

Describe the bug

rnix-parser does not parse floats/ints the same as the nix official parser.

Code Snippet to reproduce

let e="e"; in [001.22e01e.30.4]

(yes, this is valid nix)

Gets parsed into
[email protected] "001.22e01"

Expected behavior

semantically equivalent to [ 1 2.2 "e" 0.3 0.4 ]

Additional context

@yorickvP yorickvP added the bug Something isn't working label Mar 9, 2023
@tazjin
Copy link

tazjin commented Mar 9, 2023

I think the bug appears in a smaller snippet already. If we remove the e situation:

nix-repl> [001.22e01.30.4]  
[ 1 2.2 0.3 0.4 ]

but in Tvix (using rnix):

> [001.22e01.30.4]
[ 12.2 0.3 0.4 ]

(AST is dumped on that link)

@yorickvP
Copy link
Author

This is how I fixed it in nixfmt: NixOS/nixfmt@a45763a

@hsjobeki
Copy link
Contributor

hsjobeki commented May 18, 2023

This error happens at the tokenizer level already. But it is questionable if this is really an error and not a mistake in nix itself (as i will question)

001.22e01.30.4

gives the following rnix tokens

TOKEN_FLOAT, "001.22e01"
TOKEN_FLOAT, ".30"
TOKEN_FLOAT, ".4"

In contrast to that,
It seems nix itself disallows leading 0 on floats in general

01.1e2 -> error: attempt to call something which is not a function but an integer
01.1 -> error: attempt to call something which is not a function but an integer
but
1.1e2 -> 110
11.1e2 -> 1110

leading number chars != 0 are no problem in nix floats it seems.

I'd like to know what IEEE says about this. But I couldn't find if this is even specified. Maybe @RaitoBezarius knows where to look at?

To describe nix's behavior:

0 Chars, must be:

  • either of an Integer OR
  • immediately preceded by an .(DOT) which makes them part of a float. The remaining chars must then tokenize into a valid float.

Implementing this into rnix should solve this issue I think. (I will come back to this when I got some time)

@hsjobeki
Copy link
Contributor

Update: it seem ieee doesnt specify leading 0‘s its the responsibility of the app to ignore leading 0‘s. So in summary this is a bug in the nix tokenizer. rnix is right, but doesnt follow nix‘s broken behavior. It may be up to the maintainer (@oberblastmeister ) to decide whether rnix should follow this logic.

I‘ll open an issue for this in nix.

@RGBCube
Copy link

RGBCube commented Jun 16, 2024

Update: it seem ieee doesnt specify leading 0‘s its the responsibility of the app to ignore leading 0‘s. So in summary this is a bug in the nix tokenizer. rnix is right, but doesnt follow nix‘s broken behavior. It may be up to the maintainer (@oberblastmeister ) to decide whether rnix should follow this logic.

I‘ll open an issue for this in nix.

Do you have a link to the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants