MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / visitFields

Method visitFields

parser/parser.cc:1107–1141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1105}
1106
1107std::vector<StructExprField> ParserVisitor::visitFields(
1108 CelParser::FieldInitializerListContext* ctx) {
1109 std::vector<StructExprField> res;
1110 if (!ctx || ctx->fields.empty()) {
1111 return res;
1112 }
1113
1114 res.reserve(ctx->fields.size());
1115 for (size_t i = 0; i < ctx->fields.size(); ++i) {
1116 if (i >= ctx->cols.size() || i >= ctx->values.size()) {
1117 // This is the result of a syntax error detected elsewhere.
1118 return res;
1119 }
1120 auto* f = ctx->fields[i];
1121 if (!f->escapeIdent()) {
1122 ABSL_DCHECK(HasErrored());
1123 // This is the result of a syntax error detected elsewhere.
1124 return res;
1125 }
1126
1127 std::string id = NormalizeIdentifier(f->escapeIdent());
1128
1129 int64_t init_id = factory_.NextId(SourceRangeFromToken(ctx->cols[i]));
1130 if (!enable_optional_syntax_ && f->opt) {
1131 factory_.ReportError(SourceRangeFromParserRuleContext(ctx),
1132 "unsupported syntax '?'");
1133 continue;
1134 }
1135 auto value = ExprFromAny(visit(ctx->values[i]));
1136 res.push_back(factory_.NewStructField(init_id, std::move(id),
1137 std::move(value), f->opt != nullptr));
1138 }
1139
1140 return res;
1141}
1142
1143std::any ParserVisitor::visitIdent(CelParser::IdentContext* ctx) {
1144 std::string ident_name;

Callers

nothing calls this directly

Calls 8

SourceRangeFromTokenFunction · 0.85
ExprFromAnyFunction · 0.85
NewStructFieldMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
NextIdMethod · 0.45
ReportErrorMethod · 0.45

Tested by

no test coverage detected