MCPcopy Create free account
hub / github.com/WheretIB/nullc / ParseForExpr

Function ParseForExpr

NULLC/Parser.cpp:1466–1582  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1464}
1465
1466bool ParseForExpr(Lexeme** str)
1467{
1468 if(!ParseLexem(str, lex_for))
1469 return false;
1470
1471 IncreaseCycleDepth();
1472
1473 if(!ParseLexem(str, lex_oparen))
1474 ThrowError((*str)->pos, "ERROR: '(' not found after 'for'");
1475
1476 BeginBlock();
1477
1478 bool isForEach = false;
1479 const char *condPos = NULL;
1480 Lexeme *curr = *str;
1481 if((curr + 1)->type == lex_in || (ParseSelectType(&curr) && (curr + 1)->type == lex_in))
1482 {
1483 isForEach = true;
1484
1485 TypeInfo *type = (*str + 1)->type == lex_in ? NULL : GetSelectedType();
1486 *str = curr;
1487 if((*str)->type != lex_string)
1488 ThrowError((*str)->pos, "ERROR: variable name expected before 'in'");
1489 if((*str)->length >= NULLC_MAX_VARIABLE_NAME_LENGTH)
1490 ThrowError((*str)->pos, "ERROR: variable name length is limited to 2048 symbols");
1491 Lexeme *varName = *str;
1492 condPos = (*str)->pos;
1493 (*str) += 2; // Skip name and 'in'
1494
1495 // Parse expression
1496 if(!ParseTernaryExpr(str))
1497 ThrowError((*str)->pos, "ERROR: expression expected after 'in'");
1498 AddArrayIterator(varName->pos, InplaceStr(varName->pos, varName->length), type);
1499
1500 while(ParseLexem(str, lex_comma))
1501 {
1502 TypeInfo *type = NULL;
1503 if(ParseSelectType(str))
1504 type = GetSelectedType();
1505
1506 if((*str)->type != lex_string)
1507 ThrowError((*str)->pos, "ERROR: variable name expected before 'in'");
1508 if((*str)->length >= NULLC_MAX_VARIABLE_NAME_LENGTH)
1509 ThrowError((*str)->pos, "ERROR: variable name length is limited to 2048 symbols");
1510 Lexeme *varName = *str;
1511 condPos = (*str)->pos;
1512 (*str)++;
1513 if(!ParseLexem(str, lex_in))
1514 ThrowError((*str)->pos, "ERROR: 'in' expected after variable name");
1515
1516 // Parse expression
1517 if(!ParseTernaryExpr(str))
1518 ThrowError((*str)->pos, "ERROR: expression expected after 'in'");
1519 AddArrayIterator(varName->pos, InplaceStr(varName->pos, varName->length), type);
1520 MergeArrayIterators();
1521 }
1522 }else{
1523 if(ParseLexem(str, lex_ofigure))

Callers 1

ParseExpressionFunction · 0.85

Calls 15

ParseLexemFunction · 0.85
IncreaseCycleDepthFunction · 0.85
ThrowErrorFunction · 0.85
BeginBlockFunction · 0.85
ParseSelectTypeFunction · 0.85
GetSelectedTypeFunction · 0.85
ParseTernaryExprFunction · 0.85
AddArrayIteratorFunction · 0.85
InplaceStrClass · 0.85
MergeArrayIteratorsFunction · 0.85
ParseCodeFunction · 0.85
AddVoidNodeFunction · 0.85

Tested by

no test coverage detected