jank-lang / jank

The native Clojure dialect hosted on LLVM
https://jank-lang.org
Mozilla Public License 2.0
1.69k stars 50 forks source link

Support lexing reals with scientific notation #96

Closed jeaye closed 1 week ago

jeaye commented 1 month ago

Clojure inherits Java's support for scientific notation: https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.2 C++'s floating point docs: https://en.cppreference.com/w/cpp/language/floating_literal

For jank, we want to expand the lexer to support this for reals. Fortunately, we just need to be able to figure out when the token ends. Then we can use std::stold in order to get the actual value from it: https://en.cppreference.com/w/cpp/string/basic_string/stof

I'm sure there are many possible ways to misrepresent these numbers, so the negative test cases for this should be aplenty.

The lexing of numbers starts here: https://github.com/jank-lang/jank/blob/main/compiler%2Bruntime/src/cpp/jank/read/lex.cpp#L370 The tests for reals start here: https://github.com/jank-lang/jank/blob/main/compiler%2Bruntime/test/cpp/jank/read/lex.cpp#L448

Samy-33 commented 1 month ago

@jeaye, working on this

jeaye commented 1 week ago

This was done in #109.