summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-lexer.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-06-27 14:28:01 -0400
committerGitHub <noreply@github.com>2023-06-27 14:28:01 -0400
commit9ddbea318d347f55c81c82e71ee09c45aeb89c59 (patch)
treed4f9458f9518c9f0754e190beee4078df74ee474 /source/compiler-core/slang-lexer.cpp
parent1b01ff909afa1eb6700c0dc947e679b9c3890880 (diff)
Support for infinite literal of from 34.2432#INF (#2944)
Diffstat (limited to 'source/compiler-core/slang-lexer.cpp')
-rw-r--r--source/compiler-core/slang-lexer.cpp34
1 files changed, 34 insertions, 0 deletions
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))
{