comparison src/lread.c @ 5247:02d875ebd1ea

Make Lisp reader errors more informative with over-long hex, octal characters src/ChangeLog addition: 2010-08-21 Aidan Kehoe <kehoea@parhasard.net> * lread.c (read_escape): Make error messages better reflect the text that was encountered, when overlong hex character escapes or non-Latin-1 octal character escapes are encountered. man/ChangeLog addition: 2010-08-21 Aidan Kehoe <kehoea@parhasard.net> * lispref/objects.texi (Character Type): Go into more detail here on the specific type of error provoked on overlong hex character escapes and non-Latin-1 octal character escapes; give details of why the latter may be encountered, and what to do with such code.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 21 Aug 2010 19:02:44 +0100
parents 808131ba4a57
children c096d8051f89 308d34e9f07d
comparison
equal deleted inserted replaced
5244:04811a268716 5247:02d875ebd1ea
1816 unreadchar (readcharfun, c); 1816 unreadchar (readcharfun, c);
1817 break; 1817 break;
1818 } 1818 }
1819 } 1819 }
1820 if (i >= 0400) 1820 if (i >= 0400)
1821 syntax_error ("Non-ISO-8859-1 character specified with octal escape", 1821 {
1822 make_int (i)); 1822 read_syntax_error ((Ascbyte *) emacs_sprintf_malloc
1823 (NULL,
1824 "Non-ISO-8859-1 octal character escape, "
1825 "?\\%.3o", i));
1826 }
1823 return i; 1827 return i;
1824 } 1828 }
1825 1829
1826 case 'x': 1830 case 'x':
1827 /* A hex escape, as in ANSI C, except that we only allow latin-1 1831 /* A hex escape, as in ANSI C, except that we only allow latin-1
1828 characters to be read this way. What is "\x4e03" supposed to 1832 characters to be read this way. What is "\x4e03" supposed to
1829 mean, anyways, if the internal representation is hidden? 1833 mean, anyways, if the internal representation is hidden?
1830 This is also consistent with the treatment of octal escapes. */ 1834 This is also consistent with the treatment of octal escapes.
1835
1836 Note that we don't accept ?\XAB as specifying the character with
1837 numeric value 171; it must be ?\xAB. */
1831 { 1838 {
1839 #define OVERLONG_INFO "Overlong hex character escape, ?\\x"
1840
1832 REGISTER Ichar i = 0; 1841 REGISTER Ichar i = 0;
1833 REGISTER int count = 0; 1842 REGISTER int count = 0;
1843 Ascbyte seen[] = OVERLONG_INFO "\0\0\0\0\0";
1844 REGISTER Ascbyte *seenp = seen + sizeof (OVERLONG_INFO) - 1;
1845
1846 #undef OVERLONG_INFO
1847
1834 while (++count <= 2) 1848 while (++count <= 2)
1835 { 1849 {
1836 c = readchar (readcharfun); 1850 c = readchar (readcharfun), *seenp = c, ++seenp;
1837 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */ 1851 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */
1838 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); 1852 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
1839 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; 1853 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
1840 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; 1854 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
1841 else 1855 else
1845 } 1859 }
1846 } 1860 }
1847 1861
1848 if (count == 3) 1862 if (count == 3)
1849 { 1863 {
1850 c = readchar (readcharfun); 1864 c = readchar (readcharfun), *seenp = c, ++seenp;
1851 if ((c >= '0' && c <= '9') || 1865 if ((c >= '0' && c <= '9') ||
1852 (c >= 'a' && c <= 'f') || 1866 (c >= 'a' && c <= 'f') ||
1853 (c >= 'A' && c <= 'F')) 1867 (c >= 'A' && c <= 'F'))
1854 { 1868 {
1855 Lisp_Object args[2]; 1869 read_syntax_error (seen);
1856
1857 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
1858 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
1859 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
1860
1861 args[0] = build_ascstring ("?\\x%x");
1862 args[1] = make_int (i);
1863 syntax_error ("Overlong hex character escape",
1864 Fformat (2, args));
1865 } 1870 }
1866 unreadchar (readcharfun, c); 1871 unreadchar (readcharfun, c);
1867 } 1872 }
1868 1873
1869 return i; 1874 return i;