Known to be at \u
(shouldEmitInvalidEscapeError bool)
| 1853 | |
| 1854 | // Known to be at \u |
| 1855 | func (s *Scanner) scanUnicodeEscape(shouldEmitInvalidEscapeError bool) rune { |
| 1856 | s.pos += 2 |
| 1857 | start := s.pos |
| 1858 | extended := s.char() == '{' |
| 1859 | var hexDigits string |
| 1860 | if extended { |
| 1861 | s.pos++ |
| 1862 | hexDigits = s.scanHexDigits(1, true, false) |
| 1863 | } else { |
| 1864 | s.tokenFlags |= ast.TokenFlagsUnicodeEscape |
| 1865 | hexDigits = s.scanHexDigits(4, false, false) |
| 1866 | } |
| 1867 | if hexDigits == "" { |
| 1868 | s.tokenFlags |= ast.TokenFlagsContainsInvalidEscape |
| 1869 | if shouldEmitInvalidEscapeError { |
| 1870 | s.error(diagnostics.Hexadecimal_digit_expected) |
| 1871 | } |
| 1872 | return -1 |
| 1873 | } |
| 1874 | hexValue, _ := strconv.ParseInt(hexDigits, 16, 32) |
| 1875 | if extended { |
| 1876 | isInvalidExtendedEscape := false |
| 1877 | if hexValue > 0x10FFFF { |
| 1878 | if shouldEmitInvalidEscapeError { |
| 1879 | s.errorAt(diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive, start+1, s.pos-start-1) |
| 1880 | } |
| 1881 | isInvalidExtendedEscape = true |
| 1882 | } |
| 1883 | if s.pos >= s.end { |
| 1884 | if shouldEmitInvalidEscapeError { |
| 1885 | s.error(diagnostics.Unexpected_end_of_text) |
| 1886 | } |
| 1887 | isInvalidExtendedEscape = true |
| 1888 | } else if s.char() == '}' { |
| 1889 | s.pos++ |
| 1890 | } else { |
| 1891 | if shouldEmitInvalidEscapeError { |
| 1892 | s.error(diagnostics.Unterminated_Unicode_escape_sequence) |
| 1893 | } |
| 1894 | isInvalidExtendedEscape = true |
| 1895 | } |
| 1896 | if isInvalidExtendedEscape { |
| 1897 | s.tokenFlags |= ast.TokenFlagsContainsInvalidEscape |
| 1898 | return -1 |
| 1899 | } |
| 1900 | s.tokenFlags |= ast.TokenFlagsExtendedUnicodeEscape |
| 1901 | } |
| 1902 | return rune(hexValue) |
| 1903 | } |
| 1904 | |
| 1905 | // scanLowSurrogateEscape attempts to consume a low-surrogate Unicode escape |
| 1906 | // (either '\uLow' or '\u{Low}') immediately following an already-scanned high |
no test coverage detected