2 // This file contains a slimmed down version of read_complex().
3 // It does not pull in all the complex function code.
9 #include "cln/real_io.h"
15 #include "cl_spushstring.h"
16 #include "cln/input.h"
20 // We read an entire token (or even more, if it begins with #C) into a
21 // buffer and then call read_real() on the buffer.
23 class pushstring_hack : public cl_spushstring {
25 char* start_pointer (void) { return buffer; }
26 char* end_pointer (void) { return buffer+index; }
29 static cl_boolean number_char_p (char c)
31 if ((c >= '0') && (c <= '9'))
33 if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))
36 case '+': case '-': case '.': case '_': case '/':
43 const cl_R read_real (std::istream& stream, const cl_read_flags& flags)
45 // One pre-allocated buffer. This reduces the allocation/free cost.
46 static pushstring_hack buffer;
49 // Skip whitespace at the beginning.
51 c = freadchar(stream);
52 if (c == cl_EOF) goto eof;
53 if ((c == ' ') || (c == '\t') || (c == '\n'))
58 // Found first non-whitespace character.
59 // Numbers cannot cross lines. We can treat EOF and '\n' the same way.
62 if (!(flags.lsyntax & lsyntax_commonlisp))
65 // Read some digits, then a letter, then a token.
67 c = freadchar(stream);
68 if (c == cl_EOF) goto eof;
70 if ((c >= '0') && (c <= '9'))
75 if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
77 c = freadchar(stream);
78 if (c == cl_EOF) goto eof;
80 // Read a number token.
81 if (!number_char_p(c))
85 c = freadchar(stream);
88 if (!number_char_p(c)) {
89 funreadchar(stream,c);
94 return read_real(flags,
95 buffer.start_pointer(), buffer.end_pointer(),
99 // Handle syntax error.
100 syntax1: buffer.push(c);
101 throw read_number_bad_syntax_exception(buffer.start_pointer(),buffer.end_pointer());
103 // Handle premature EOF.
104 eof: throw read_number_eof_exception();