// Does not include sign, Infinity, NaN, which are concepted in parser // 1E1000 => -Infinity (netcore vs net framework) // TODO parse 1_000 // TODO parse 0xffff private Token NumberToken() { Next(); while (Chars.IsDigit(c)) { Next(); } if (c == '.') { var c1 = Peek(1); if (Chars.IsDigit(c1)) { Next(2); while (Chars.IsDigit(c)) { Next(); } } } if (c == 'e' || c == 'E') { var n = 1; var cn = Peek(n); if (cn == '+' || cn == '-') { n++; } cn = Peek(n); if (Chars.IsDigit(cn)) { n++; } Next(n); while (Chars.IsDigit(c)) { Next(); } } var value = SigoConverter.ToDouble(src.Substring(start, end - start)); return(CreateToken(Kind.Number, value)); }
private void ScanStringEscape() { Next(); switch (c) { case Eof: throw new Exception("UnterminatedStringLiteral"); case '\r': Next(); if (c == '\n') { Next(); } break; case '\n': Next(); break; case '\\': case '"': case '\'': sb.Append(c); Next(); break; case 'b': sb.Append('\b'); Next(); break; case 'f': sb.Append('\f'); Next(); break; case 'r': sb.Append('\r'); Next(); break; case 'n': sb.Append('\n'); Next(); break; case 't': sb.Append('\t'); Next(); break; case 'u': Next(); var u = 0; var i = 0; for (; i < 4; i++) { var h = SigoConverter.TryConvertHexChar2Int(c); if (h >= 0) { Next(); u = u * 16 + h; } else { break; } } if (i == 4) { sb.Append((char)u); } else { throw new Exception("HexadecimalDigitExpected"); } break; default: // /c sb.Append(c); // warning unknown escape Next(); break; } // switch (the letter after \) }