jank-lang / jank

A Clojure dialect hosted on LLVM with native C++ interop
https://jank-lang.org
Mozilla Public License 2.0
1.64k stars 48 forks source link

Support lexing reals with scientific notation #96

Open jeaye opened 2 weeks ago

jeaye commented 2 weeks 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 6 days ago

@jeaye, working on this