Browse Source

Fix: lexer

AnnulusGames 1 year ago
parent
commit
619914a3b7
2 changed files with 21 additions and 28 deletions
  1. 20 27
      src/Lua/CodeAnalysis/Syntax/Lexer.cs
  2. 1 1
      src/Lua/Internal/HexConverter.cs

+ 20 - 27
src/Lua/CodeAnalysis/Syntax/Lexer.cs

@@ -232,13 +232,18 @@ public ref struct Lexer
 
                 ReadDigit(ref span, ref offset, out var readCount);
 
-                if (span.Length > offset)
+                if (span.Length > offset && span[offset] is '.')
                 {
-                    if (span[offset] is '.')
-                    {
-                        Advance(1);
-                        ReadDigit(ref span, ref offset, out _);
-                    }
+                    Advance(1);
+                    ReadDigit(ref span, ref offset, out _);
+                }
+
+                if (span.Length > offset && span[offset] is 'p' or 'P')
+                {
+                    Advance(1);
+                    if (span[offset] is '-' or '+') Advance(1);
+
+                    ReadDigit(ref span, ref offset, out _);
                 }
 
                 if (readCount == 0)
@@ -250,30 +255,18 @@ public ref struct Lexer
             {
                 ReadNumber(ref span, ref offset, out _);
 
-                if (span.Length > offset)
+                if (span.Length > offset && span[offset] is '.')
                 {
-                    var c = span[offset];
-
-                    if (c is '.')
-                    {
-                        Advance(1);
-                        ReadNumber(ref span, ref offset, out _);
-
-                        if (span.Length > offset && span[offset] is 'e' or 'E')
-                        {
-                            Advance(1);
-                            if (span[offset] is '-' or '+') Advance(1);
+                    Advance(1);
+                    ReadNumber(ref span, ref offset, out _);
+                }
 
-                            ReadNumber(ref span, ref offset, out _);
-                        }
-                    }
-                    else if (c is 'e' or 'E')
-                    {
-                        Advance(1);
-                        if (span[offset] is '-' or '+') Advance(1);
+                if (span.Length > offset && span[offset] is 'e' or 'E')
+                {
+                    Advance(1);
+                    if (span[offset] is '-' or '+') Advance(1);
 
-                        ReadNumber(ref span, ref offset, out _);
-                    }
+                    ReadNumber(ref span, ref offset, out _);
                 }
             }
 

+ 1 - 1
src/Lua/Internal/HexConverter.cs

@@ -20,7 +20,7 @@ public static class HexConverter
         }
 
         var dotIndex = text.IndexOf('.');
-        var expIndex = text.IndexOf('p');
+        var expIndex = text.IndexOfAny('p', 'P');
 
         if (dotIndex == -1 && expIndex == -1)
         {