Skip to content

Commit 33a8b54

Browse files
fix: accept option-name extensions, group options, and extension range options
Four places where the grammar was stricter than the language spec and than what protoc and protocompile accept: - optionName permits a parenthesized extension in every dot-separated part, each optionally fully qualified, not just a bare identifier after the first part. This is what edition feature options look like in practice: option features.(pb.go).api_level = API_OPAQUE; - group takes an optional field-option list, like any other field. - oneof bodies may contain a group. - extensions takes an optional extension-range-option list. Parsing 7693 .proto files collected from module caches, these four account for 347 of 686 files that failed to parse.
1 parent 49ebc24 commit 33a8b54

8 files changed

Lines changed: 4806 additions & 3434 deletions

File tree

grammar.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ module.exports = grammar({
7979
';',
8080
),
8181

82+
// optionName = ( ident | "(" [ "." ] fullIdent ")" )
83+
// { "." ( ident | "(" [ "." ] fullIdent ")" ) }
8284
_option_name: $ => seq(
8385
choice(
8486
$.identifier,
85-
seq('(', $.full_ident, ')'),
87+
seq('(', optional('.'), $.full_ident, ')'),
8688
),
8789
repeat(seq(
8890
'.',
89-
$.identifier,
91+
choice(
92+
$.identifier,
93+
seq('(', optional('.'), $.full_ident, ')'),
94+
),
9095
)),
9196
),
9297

@@ -171,7 +176,7 @@ module.exports = grammar({
171176
$.message_body,
172177
),
173178

174-
// group = label "group" groupName "=" fieldNumber messageBody
179+
// group = label "group" groupName "=" fieldNumber [ "[" fieldOptions "]" ] messageBody
175180
// label = "required" | "optional" | "repeated"
176181
// Proto2 only; deprecated but still valid.
177182
group: $ => seq(
@@ -180,6 +185,7 @@ module.exports = grammar({
180185
$.message_name,
181186
'=',
182187
$.field_number,
188+
optional(seq('[', $.field_options, ']')),
183189
$.message_body,
184190
),
185191

@@ -220,6 +226,7 @@ module.exports = grammar({
220226
repeat(choice(
221227
$.option,
222228
$.oneof_field,
229+
$.group,
223230
$.empty_statement,
224231
)),
225232
'}',
@@ -297,9 +304,11 @@ module.exports = grammar({
297304
';',
298305
),
299306

307+
// extensions = "extensions" ranges [ "[" fieldOptions "]" ] ";"
300308
extensions: $ => seq(
301309
'extensions',
302310
$.ranges,
311+
optional(seq('[', $.field_options, ']')),
303312
';',
304313
),
305314

src/grammar.json

Lines changed: 102 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)