#include <ctype.h>
#include "cos-read.h"
-int
+static int
+is_delimiter (int ch)
+{
+ return isspace (ch)
+ || ( ch == '(' )
+ || ( ch == ')' )
+ || ( ch == '[' )
+ || ( ch == ']' )
+ || ( ch == '"' )
+ || ( ch == '#' )
+ || ( ch == ';' );
+}
+
+static int
cos_skip_space (unsigned char *str, size_t len, size_t start, size_t* endp)
{
int i = start;
dest = dest * 10 + c - '0';
i++;
}
- else if ( isspace (c)
- || ( c == '(' )
- || ( c == ')' )
- || ( c == '[' )
- || ( c == ']' )
- || ( c == '"' ) )
+ else if ( is_delimiter (c) )
{
*endp = i;
return cos_make_int ( negative_flag ? - dest : dest );
{
if ( c == '"' )
{
- return cos_make_string ((char*)&str[1], i - 2);
+ *endp = i;
+ return cos_make_string ((char*)&str[start + 1], i - 2 - start);
}
else if ( c == '\\' )
{
}
+COS_Symbol
+cos_read_symbol (unsigned char *str, size_t len, size_t start, size_t* endp)
+{
+ size_t i = start;
+ int c;
+
+ if ( i < len )
+ {
+ while ( ( i < len )
+ && ( (c = cos_read_utf8 (str, len, i, &i)) >= 0 )
+ )
+ {
+ if ( is_delimiter (c) )
+ {
+ i--;
+ if ( i == start )
+ return NULL;
+ else
+ {
+ *endp = i;
+ return
+ cos_intern (cos_make_string (&str[start], i - start));
+ }
+ }
+ else if ( c == '\\' )
+ {
+ i++;
+ if ( cos_read_utf8 (str, len, i, &i) < 0 )
+ return NULL;
+ }
+ }
+ }
+ if ( i == start )
+ return NULL;
+ else
+ {
+ *endp = i;
+ return cos_intern (cos_make_string (&str[start], i - start));
+ }
+}
+
+
static COS_Cons
cos_read_list0 (unsigned char *str, size_t len, size_t start, size_t* endp)
{
start = cos_skip_space (str, len, start, endp);
+ val_obj = cos_read_list (str, len, start, endp);
+ if ( val_obj != NULL )
+ return val_obj;
+
val_obj = cos_read_int (str, len, start, endp);
if ( val_obj != NULL )
return val_obj;
if ( val_str != NULL )
return val_str;
- val_obj = cos_read_list (str, len, start, endp);
+ val_obj = cos_read_symbol (str, len, start, endp);
if ( val_obj != NULL )
return val_obj;