parser.cxx

changeset 13
4a5b86aed1d6
parent 12
1bdbfcca2fc6
child 14
bb18fa5af076
equal deleted inserted replaced
12:1bdbfcca2fc6 13:4a5b86aed1d6
122 // Check if it's a command. 122 // Check if it's a command.
123 CommandDef* comm = GetCommandByName (token); 123 CommandDef* comm = GetCommandByName (token);
124 if (comm) { 124 if (comm) {
125 w->Write<long> (DH_COMMAND); 125 w->Write<long> (DH_COMMAND);
126 w->Write<long> (comm->number); 126 w->Write<long> (comm->number);
127 w->Write<long> (comm->numargs); 127 w->Write<long> (comm->maxargs);
128 MustNext ("("); 128 MustNext ("(");
129 int curarg = 0; 129 int curarg = 0;
130 while (1) { 130 while (1) {
131 if (curarg >= comm->numargs) { 131 if (curarg >= comm->maxargs) {
132 if (!PeekNext().compare (","))
133 ParserError ("got `,` while expecting command-terminating `)`, are you passing too many parameters? (max %d)",
134 comm->maxargs);
132 MustNext (")"); 135 MustNext (")");
133 break; 136 break;
134 } 137 }
135 138
136 if (!Next ()) 139 if (!Next ())
146 ParserError ("argument %d (`%s`) is not a number", curarg, token.chars()); 149 ParserError ("argument %d (`%s`) is not a number", curarg, token.chars());
147 150
148 int i = atoi (token.chars ()); 151 int i = atoi (token.chars ());
149 w->Write<long> (i); 152 w->Write<long> (i);
150 153
151 if (curarg != comm->numargs - 1) 154 if (curarg < comm->numargs - 1) {
152 MustNext (","); 155 MustNext (",");
156 } else if (curarg < comm->maxargs - 1) {
157 // Can continue, but can terminate as well.
158 if (!PeekNext ().compare (")")) {
159 MustNext (")");
160 break;
161 } else
162 MustNext (",");
163 }
153 164
154 curarg++; 165 curarg++;
155 } 166 }
156 MustNext (";"); 167 MustNext (";");
157 } else 168 } else

mercurial