rev 209 - trunk/src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: bcollins
Date: 2004-03-30 10:33:18 -0500 (Tue, 30 Mar 2004)
New Revision: 209

Modified:
   trunk/src/builtins.c
   trunk/src/prothon.y
Log:
Fix bug #3. Also cleanup str_tuple_list to act more like python.


Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-30 13:50:37 UTC (rev 208)
+++ trunk/src/builtins.c	2004-03-30 15:33:18 UTC (rev 209)
@@ -324,26 +324,41 @@
 }
 
 
-static obj_p str_tuple_list(isp ist, obj_p self, char* ldelim, char* rdelim) {
+static obj_p str_tuple_list(isp ist, obj_p self, char* ldelim, char* rdelim)
+{
 	int i, len=list_len(ist, self);
-	char msg[1024], *res = pr_malloc(2); 
+	char msg[64], *res;
+
+	/* Need enough room for just empty list */
+	res = pr_malloc(strlen(ldelim) + strlen(rdelim) + 1);
+
 	strcpy(res, ldelim);
-	for (i=0; i < len; i++) {
+
+	for (i = 0; i < len; i++) {
 		char* item_str;
 		obj_p item = list_item(ist, self,i);
-		if ((uintptr_t)item > 10) item_str = as_str(ist, item);
-		else {
+		int is_str = 0;
+
+		if ((uintptr_t)item > 10) {
+			item_str = as_str(ist, item);
+			is_str = 1;
+		} else {
 			apr_snprintf(msg, sizeof(msg), "<objptr:%lx>", (unsigned long)(uintptr_t)item);
 			item_str = msg;
 		}
-		res = pr_realloc(res, strlen(res)+strlen(item_str)+4);
+
+		res = pr_realloc(res, strlen(res) + strlen(item_str) + strlen(rdelim) + 6);
+		if (is_str)
+			strcat(res, "'");
 		strcat(res, item_str);
-		if (i != len-1) strcat(res, ", ");
+		if (is_str)
+			strcat(res,"'");
+
+		if (i != len-1)
+			strcat(res, ", ");
 	}
 	strcat(res, rdelim);
-	if (res[0]=='(' && res[1]==')') {
-		res[1]=','; res[2]=')'; res[3]=0;
-	}
+
 	return new_string_obj(res);
 }
 

Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y	2004-03-30 13:50:37 UTC (rev 208)
+++ trunk/src/prothon.y	2004-03-30 15:33:18 UTC (rev 209)
@@ -596,7 +596,8 @@
 		expr ':' expr												{ $$ = new_list2(yylex_param, $1, $3); }
 	;
 tuple_params:
-		expr ','													{ $$ = new_list(yylex_param, $1); }
+		{ $$ = new_clist(0); }
+	|	expr ','													{ $$ = new_list(yylex_param, $1); }
 	|	tuple_params2
 	|	tuple_params2 ','
 	;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.