Parser now can read optional arguments properly.

Sat, 14 Jul 2012 16:24:57 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 14 Jul 2012 16:24:57 +0300
changeset 13
4a5b86aed1d6
parent 12
1bdbfcca2fc6
child 14
bb18fa5af076

Parser now can read optional arguments properly.

parser.cxx file | annotate | diff | comparison | revisions
--- a/parser.cxx	Sat Jul 14 16:12:59 2012 +0300
+++ b/parser.cxx	Sat Jul 14 16:24:57 2012 +0300
@@ -124,11 +124,14 @@
 			if (comm) {
 				w->Write<long> (DH_COMMAND);
 				w->Write<long> (comm->number);
-				w->Write<long> (comm->numargs);
+				w->Write<long> (comm->maxargs);
 				MustNext ("(");
 				int curarg = 0;
 				while (1) {
-					if (curarg >= comm->numargs) {
+					if (curarg >= comm->maxargs) {
+						if (!PeekNext().compare (","))
+							ParserError ("got `,` while expecting command-terminating `)`, are you passing too many parameters? (max %d)",
+								comm->maxargs);
 						MustNext (")");
 						break;
 					}
@@ -148,8 +151,16 @@
 					int i = atoi (token.chars ());
 					w->Write<long> (i);
 					
-					if (curarg != comm->numargs - 1)
+					if (curarg < comm->numargs - 1) {
 						MustNext (",");
+					} else if (curarg < comm->maxargs - 1) {
+						// Can continue, but can terminate as well.
+						if (!PeekNext ().compare (")")) {
+							MustNext (")");
+							break;
+						} else
+							MustNext (",");
+					}
 					
 					curarg++;
 				}

mercurial