Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions parser/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ std::any ParserVisitor::visitCreateMessage(
} else {
name = absl::StrJoin(parts, ".");
}
int64_t obj_id = factory_.NextId(SourceRangeFromToken(ctx->op));
int64_t obj_id = factory_.NextId(SourceRangeFromParserRuleContext(ctx));
std::vector<StructExprField> fields;
if (ctx->entries) {
fields = visitFields(ctx->entries);
Expand Down Expand Up @@ -1191,7 +1191,7 @@ std::any ParserVisitor::visitNested(CelParser::NestedContext* ctx) {
}

std::any ParserVisitor::visitCreateList(CelParser::CreateListContext* ctx) {
int64_t list_id = factory_.NextId(SourceRangeFromToken(ctx->op));
int64_t list_id = factory_.NextId(SourceRangeFromParserRuleContext(ctx));
auto elems = visitList(ctx->elems);
return ExprToAny(factory_.NewList(list_id, std::move(elems)));
}
Expand Down Expand Up @@ -1229,7 +1229,7 @@ std::vector<Expr> ParserVisitor::visitList(CelParser::ExprListContext* ctx) {
}

std::any ParserVisitor::visitCreateMap(CelParser::CreateMapContext* ctx) {
int64_t struct_id = factory_.NextId(SourceRangeFromToken(ctx->op));
int64_t struct_id = factory_.NextId(SourceRangeFromParserRuleContext(ctx));
std::vector<MapExprEntry> entries;
if (ctx->entries) {
entries = visitEntries(ctx->entries);
Expand Down
23 changes: 23 additions & 0 deletions parser/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,29 @@ TEST_P(ExpressionTest, Parse) {
}
}

TEST(ExpressionTest, CompositeExpressionOffsets) {
ParserOptions options;
std::vector<Macro> macros = Macro::AllMacros();

std::string list_expr = "[1, 2]";
auto list_result = EnrichedParse(list_expr, macros, "<input>", options);
ASSERT_THAT(list_result, IsOk());
auto list_offsets = list_result->enriched_source_info().offsets();
EXPECT_EQ(list_offsets.at(1), std::make_pair(0, 5));

std::string map_expr = "{'a': 1}";
auto map_result = EnrichedParse(map_expr, macros, "<input>", options);
ASSERT_THAT(map_result, IsOk());
auto map_offsets = map_result->enriched_source_info().offsets();
EXPECT_EQ(map_offsets.at(1), std::make_pair(0, 7));

std::string msg_expr = "Msg{f: 1}";
auto msg_result = EnrichedParse(msg_expr, macros, "<input>", options);
ASSERT_THAT(msg_result, IsOk());
auto msg_offsets = msg_result->enriched_source_info().offsets();
EXPECT_EQ(msg_offsets.at(1), std::make_pair(0, 8));
}

TEST(ExpressionTest, TsanOom) {
Parse(
"[[a([[???[a[[??[a([[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
Expand Down