diff --git a/src/numen/lexer.cpp b/src/numen/lexer.cpp index 4cd16c6..536368d 100644 --- a/src/numen/lexer.cpp +++ b/src/numen/lexer.cpp @@ -204,7 +204,11 @@ std::optional Lexer::next() { return tryCommit(); } - if (isAlnum(c) || isSpace(c)) { return tryCommit(); } + // anything that starts another token ends the operator: '*.5', '*$5', '*"a"' + if (isAlnum(c) || isSpace(c) || isValidChar(c) || c == '"' || c == '\'' || + (isFractionDelim(c) && m_cursor + 1 < m_data.size() && isDigit(m_data[m_cursor + 1]))) { + return tryCommit(); + } break; } case State::String: { diff --git a/tests/corpus/arithmetic.corpus b/tests/corpus/arithmetic.corpus index 5ff39e3..756179e 100644 --- a/tests/corpus/arithmetic.corpus +++ b/tests/corpus/arithmetic.corpus @@ -222,6 +222,12 @@ pi => 3.141593 -.5 => -0.5 .25 * 4 => 1 +# an operator glued to a following leading-dot decimal reads the same as the spaced form +3*.3 => 0.9 +2**.5 => 1.414214 +2<.5 => false +1!=.5 => true + # whole results stay exact past the 64 bit signed range 2 ^ 64 => 18,446,744,073,709,551,616 10000000000 * 1000000000 => 10,000,000,000,000,000,000