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
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ class SyntaxReader(
val start = pos
loop@ while (pos < data.size) {
when (data[pos]) {
in 'a'..'z', in 'A'..'Z', in '0'..'9', '_', '-', '.' -> pos++
in 'a'..'z', in 'A'..'Z', in '0'..'9', '_', '-' -> pos++
// A dot immediately followed by '(' or '[' is a separator before a parenthesized or
// bracketed extension (e.g. the second dot in "(foo.field).string.(foo.datetime)"), not
// part of this word.
'.' -> {
if (pos + 1 < data.size && (data[pos + 1] == '(' || data[pos + 1] == '[')) break@loop
pos++
}
else -> break@loop
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2549,6 +2549,54 @@ class ProtoParserTest {
assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected)
}

// https://github.com/square/wire/issues/3672
@Test
fun deepOptionAssignmentWithParenthesizedExtensionAfterFieldPathComponent() {
val proto = """
|message Foo {
| optional string a = 1 [(foo.field).string.(foo.datetime) = true];
|}
|
""".trimMargin()
val expected = ProtoFileElement(
location = location,
types = listOf(
MessageElement(
location = location.at(1, 1),
name = "Foo",
fields = listOf(
FieldElement(
location = location.at(2, 3),
label = OPTIONAL,
type = "string",
name = "a",
tag = 1,
options = listOf(
OptionElement(
name = "foo.field",
kind = Kind.OPTION,
isParenthesized = true,
value = OptionElement(
name = "string",
kind = Kind.OPTION,
isParenthesized = false,
value = OptionElement(
name = "foo.datetime",
kind = Kind.BOOLEAN,
isParenthesized = true,
value = "true",
),
),
),
),
),
),
),
),
)
assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected)
}

@Test fun protoKeywordAsEnumConstants() {
// Note: this is consistent with protoc.
val proto = """
Expand Down