From b6f8d3209f0e59a176c0e3a4b168eec07722b7cc Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 26 Sep 2025 08:12:16 +0000 Subject: [PATCH 1/3] [protobuf2] Verification and declaration keywords Fixes #4629. --- protobuf/protobuf2/Protobuf2.g4 | 43 ++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/protobuf/protobuf2/Protobuf2.g4 b/protobuf/protobuf2/Protobuf2.g4 index 83892abb5b..188460ff6c 100644 --- a/protobuf/protobuf2/Protobuf2.g4 +++ b/protobuf/protobuf2/Protobuf2.g4 @@ -132,7 +132,28 @@ type_ // Extensions extensions - : EXTENSIONS ranges SEMI + : EXTENSIONS ranges (LB (verificationDef | declarationsDef) RB)? SEMI + ; + +verificationDef + : VERIFICATION EQ verification + ; + +verification + : DECLARATION_LIT + | UNVERIFIED_LIT + ; + +declarationsDef + : declarationDef (COMMA declarationDef)* + ; + +declarationDef + : DECLARATION EQ LC (declaration (declaration)*)? RC + ; + +declaration + : fieldName COLON constant (COMMA)? ; // Reserved @@ -472,6 +493,22 @@ MAX : 'max' ; +VERIFICATION + : 'verification' + ; + +DECLARATION + : 'declaration' + ; + +DECLARATION_LIT + : 'DECLARATION' + ; + +UNVERIFIED_LIT + : 'UNVERIFIED' + ; + ENUM : 'enum' ; @@ -707,4 +744,8 @@ keywords | STREAM | RETURNS | BOOL_LIT + | DECLARATION + | VERIFICATION + | DECLARATION_LIT + | UNVERIFIED_LIT ; From d9b8d722faa96221146950af5ceceb3eb7b564ab Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 26 Sep 2025 08:51:55 +0000 Subject: [PATCH 2/3] Add example that fails build on master --- protobuf/protobuf2/examples/extension.proto | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 protobuf/protobuf2/examples/extension.proto diff --git a/protobuf/protobuf2/examples/extension.proto b/protobuf/protobuf2/examples/extension.proto new file mode 100644 index 0000000000..41b2936aa4 --- /dev/null +++ b/protobuf/protobuf2/examples/extension.proto @@ -0,0 +1,16 @@ +syntax = 'proto2'; + +message UserContent { + extensions 100 to 199 [verification = DECLARATION]; +} + +message OtherContent { + extensions 100 to 199 [ + declaration = { + number: 126, + full_name: ".kittens.kitten_videos", + type: ".kittens.Video", + repeated: true + } + ]; +} \ No newline at end of file From 72088a4974b19ee00a852195a207598e58ddf6c3 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 26 Sep 2025 09:00:30 +0000 Subject: [PATCH 3/3] Simplify extension declaration a bit Duplicates one of the changes from #4632 --- protobuf/protobuf2/Protobuf2.g4 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/protobuf/protobuf2/Protobuf2.g4 b/protobuf/protobuf2/Protobuf2.g4 index 188460ff6c..253cc8b43a 100644 --- a/protobuf/protobuf2/Protobuf2.g4 +++ b/protobuf/protobuf2/Protobuf2.g4 @@ -132,7 +132,7 @@ type_ // Extensions extensions - : EXTENSIONS ranges (LB (verificationDef | declarationsDef) RB)? SEMI + : EXTENSIONS ranges (LB (verificationDef | declarations) RB)? SEMI ; verificationDef @@ -144,16 +144,12 @@ verification | UNVERIFIED_LIT ; -declarationsDef - : declarationDef (COMMA declarationDef)* - ; - -declarationDef - : DECLARATION EQ LC (declaration (declaration)*)? RC +declarations + : declaration (COMMA declaration)* ; declaration - : fieldName COLON constant (COMMA)? + : DECLARATION EQ blockLit ; // Reserved