MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / ParseParameterListStatement

Function ParseParameterListStatement

InterfaceCompiler/main.cpp:314–357  ·  view source on GitHub ↗

(TYPE IDENTIFIER, ...)

Source from the content-addressed store, hash-verified

312
313// (TYPE IDENTIFIER, ...)
314ParameterList ParseParameterListStatement(const std::vector<Token>::iterator& end, std::vector<Token>::iterator& it){
315 std::vector<std::pair<Type, std::string>> parameters;
316
317 while(it != end){
318 Token tok = *(it++);
319 Type type;
320
321 if(tok.type == TokenIdentifier && IsType(tok.value)){ // Check if the token is a typename
322 type = types.at(tok.value);
323 } else if(tok.type == TokenRightParens) { // Check if list is beign terminated
324 return ParameterList(parameters);
325 } else if(tok.type == TokenEndline) {
326 continue; // Eat line ending
327 } else {
328 printf("error: [line %d:%d] Invalid type '%s'!", tok.lineNum, tok.linePos, tok.value.c_str());
329 exit(4);
330 }
331
332 Token idTok = *(it++);
333 while(it != end && idTok.type == TokenEndline) idTok = *(it++); // Eat line endings
334
335 if(idTok.type != TokenIdentifier){
336 printf("error: [line %d:%d] Unexpected token '%s', expected identifier!", idTok.lineNum, idTok.linePos, tokenNames[idTok.type].c_str());
337 exit(4);
338 }
339
340 Token nextTok = *(it++);
341 while(it != end && nextTok.type == TokenEndline) nextTok = *(it++); // Eat line endings
342
343 if(nextTok.type == TokenComma){
344 parameters.push_back({type, idTok.value});
345 continue;
346 } else if(nextTok.type == TokenRightParens) { // Check if list is beign terminated
347 parameters.push_back({type, idTok.value});
348 return ParameterList(parameters);
349 } else {
350 printf("error: [line %d:%d] Unexpected token '%s'!", nextTok.lineNum, nextTok.linePos, tokenNames[nextTok.type].c_str());
351 exit(4);
352 }
353 }
354
355 printf("error: Unterminated parameter list!");
356 exit(4);
357}
358
359void Parse(){
360 std::stack<ParserState> states;

Callers 1

ParseFunction · 0.85

Calls 2

IsTypeFunction · 0.85
ParameterListClass · 0.85

Tested by

no test coverage detected