From 9ddbea318d347f55c81c82e71ee09c45aeb89c59 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 27 Jun 2023 14:28:01 -0400 Subject: Support for infinite literal of from 34.2432#INF (#2944) --- source/compiler-core/slang-lexer.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source') diff --git a/source/compiler-core/slang-lexer.cpp b/source/compiler-core/slang-lexer.cpp index 7bb9aa84d..24cd3034b 100644 --- a/source/compiler-core/slang-lexer.cpp +++ b/source/compiler-core/slang-lexer.cpp @@ -438,6 +438,22 @@ namespace Slang static bool _maybeLexNumberExponent(Lexer* lexer, int base) { + if (_peek(lexer) == '#') + { + // Special case #INF + const auto inf = toSlice("#INF"); + for (auto c : inf) + { + if (_peek(lexer) != c) + { + return false; + } + _advance(lexer); + } + + return true; + } + if(!_isNumberExponent(_peek(lexer), base)) return false; @@ -626,6 +642,24 @@ namespace Slang } } + if (*cursor == '#') + { + // It must be INF + const auto inf = toSlice("#INF"); + + if (UnownedStringSlice(cursor, end).startsWith(inf)) + { + if(outSuffix) + { + *outSuffix = UnownedStringSlice(cursor + inf.getLength(), end); + } + + value = INFINITY; + + return value; + } + } + // Now read optional exponent if(_isNumberExponent(*cursor, radix)) { -- cgit v1.2.3