MCPcopy Create free account
hub / github.com/boutproject/BOUT-dev / parseContextExpr

Method parseContextExpr

src/sys/expressionparser.cxx:452–502  ·  view source on GitHub ↗

This will return a pointer to a FieldContext.

Source from the content-addressed store, hash-verified

450
451// This will return a pointer to a FieldContext.
452FieldGeneratorPtr ExpressionParser::parseContextExpr(LexInfo& lex) const {
453 lex.nextToken(); // eat '['
454
455 FieldContext::variable_list variables;
456
457 while (lex.curtok != ']') {
458 if (lex.curtok == 0) {
459 throw ParseException("Expecting ']' in context expression");
460 }
461
462 // Definition, ident = expression
463 // First comes the identifier symbol
464 if (lex.curtok != -2) {
465 throw ParseException(
466 "Expecting an identifier in context expression, but got curtok={:d} ({:c})",
467 static_cast<int>(lex.curtok), lex.curtok);
468 }
469 string symbol = lex.curident;
470 lex.nextToken();
471
472 // Now should be '='
473 if (lex.curtok != '=') {
474 throw ParseException(
475 "Expecting '=' after '{:s}' in context expression, but got curtok={:d} ({:c})",
476 symbol, static_cast<int>(lex.curtok), lex.curtok);
477 }
478 lex.nextToken();
479
480 // Should be expression
481 FieldGeneratorPtr value = parseExpression(lex);
482
483 variables.push_back(std::make_pair(symbol, value));
484
485 if (lex.curtok == ',') {
486 lex.nextToken(); // Skip comma
487 }
488 }
489 lex.nextToken(); // eat ']'
490
491 // Should now be '('
492 if (lex.curtok != '(') {
493 throw ParseException(
494 "Expecting '(' after ] context expression, but got curtok={:d} ({:c})",
495 static_cast<int>(lex.curtok), static_cast<char>(lex.curtok));
496 }
497
498 // Get the next expression to evaluate, put into FieldContext
499 // Note: Ensure that only the first expression in parentheses is parsed
500 // by calling parseParenExpr rather than parseExpression
501 return std::make_shared<FieldContext>(variables, parseParenExpr(lex));
502}
503
504FieldGeneratorPtr ExpressionParser::parsePrimary(LexInfo& lex) const {
505 switch (lex.curtok) {

Callers

nothing calls this directly

Calls 2

parseExpressionFunction · 0.85
nextTokenMethod · 0.80

Tested by

no test coverage detected