Skip to content

Constant does not support MessageValue #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alex-ac opened this issue Feb 20, 2025 · 1 comment
Open

Constant does not support MessageValue #95

alex-ac opened this issue Feb 20, 2025 · 1 comment
Labels
question Further information is requested

Comments

@alex-ac
Copy link

alex-ac commented Feb 20, 2025

The language spec: https://protobuf.dev/reference/protobuf/edition-2023-spec/#constant

States the following:

Constant

constant = fullIdent | ( [ "-" | "+" ] intLit ) | ( [ "-" | "+" ] floatLit ) |
                strLit | boolLit | MessageValue

MessageValue is defined in the Text Format Language Specification.

However, at the moment Lexer does not MessageValue when reading constants: https://github.com/yoheimuta/go-protoparser/blob/master/lexer/constant.go#L11

Without this support it's impossible to parse all possible values for options. Example from the impleminting editions support page:

edition = "2023";

package foo;

import "google/protobuf/descriptor.proto";

extend google.protobuf.FeatureSet {
  MyFeatures features = <extension #>;
}

message MyFeatures {
  enum FeatureValue {
    FEATURE_VALUE_UNKNOWN = 0;
    VALUE1 = 1;
    VALUE2 = 2;
  }

  FeatureValue feature_value = 1 [
    targets = TARGET_TYPE_FIELD,
    targets = TARGET_TYPE_FILE,
    feature_support = {
      edition_introduced: EDITION_2023,
      edition_deprecated: EDITION_2024,
      deprecation_warning: "Feature will be removed in 2025",
      edition_removed: EDITION_2025,
    },
    edition_defaults = { edition: EDITION_LEGACY, value: "VALUE1" },
    edition_defaults = { edition: EDITION_2024, value: "VALUE2" }
  ];
}

However, this issue is not limited to editions, because any custom option which value type is a message, will be impossible to parse.

I understand, it's quite a complex thing to support, because it pulls in complete support of protobuf text format language. It also possible that parsing message values properly will introduce the backward-incompatibility in *Option types.

@yoheimuta
Copy link
Owner

Without this support it's impossible to parse all possible values for options. Example from the impleminting editions support page:

Can you give me the specific error message?
I couldn't reproduce it.

diff --git a/_example/dump/main.go b/_example/dump/main.go
index 59ae9a4..edbd5a4 100644
--- a/_example/dump/main.go
+++ b/_example/dump/main.go
@@ -12,7 +12,7 @@ import (
 )

 var (
-       proto      = flag.String("proto", "_testdata/simple.proto", "path to the Protocol Buffer file")
+       proto      = flag.String("proto", "_testdata/messageValue.proto", "path to the Protocol Buffer file")
        debug      = flag.Bool("debug", false, "debug flag to output more parsing process detail")
        permissive = flag.Bool("permissive", true, "permissive flag to allow the permissive parsing rather than the just documented spec")
        unordered  = flag.Bool("unordered", false, "unordered flag to output another one without interface{}")
11:51:56 ~/yoheimuta/go-protoparser $ cat _testdata/messageValue.proto                                                                                     git/master
edition = "2023";

package foo;

import "google/protobuf/descriptor.proto";

message MyFeatures {
  enum FeatureValue {
    FEATURE_VALUE_UNKNOWN = 0;
    VALUE1 = 1;
    VALUE2 = 2;
  }

  FeatureValue feature_value = 1 [
    targets = TARGET_TYPE_FIELD,
    targets = TARGET_TYPE_FILE,
    feature_support = {
      edition_introduced: EDITION_2023,
      edition_deprecated: EDITION_2024,
      deprecation_warning: "Feature will be removed in 2025",
      edition_removed: EDITION_2025,
    },
    edition_defaults = { edition: EDITION_LEGACY, value: "VALUE1" },
    edition_defaults = { edition: EDITION_2024, value: "VALUE2" }
  ];
}
11:46:59 ~/yoheimuta/go-protoparser $ make run/dump/example                                                                                                git/master
go run _example/dump/main.go -debug=false -permissive=true -unordered=false
{
  "Syntax": null,
  "Edition": {
    "Edition": "2023",
    "EditionQuote": "\"2023\"",
    "Comments": null,
    "InlineComment": null,
    "Meta": {
      "Pos": {
        "Filename": "messageValue.proto",
        "Offset": 0,
        "Line": 1,
        "Column": 1
      },
      "LastPos": {
        "Filename": "messageValue.proto",
        "Offset": 16,
        "Line": 1,
        "Column": 17
      }
    }
  },
  "ProtoBody": [
    {
      "Name": "foo",
      "Comments": null,
      "InlineComment": null,
      "Meta": {
        "Pos": {
          "Filename": "messageValue.proto",
          "Offset": 19,
          "Line": 3,
          "Column": 1
        },
        "LastPos": {
          "Filename": "messageValue.proto",
          "Offset": 30,
          "Line": 3,
          "Column": 12
        }
      }
    },
    {
      "Modifier": 0,
      "Location": "\"google/protobuf/descriptor.proto\"",
      "Comments": null,
      "InlineComment": null,
      "Meta": {
        "Pos": {
          "Filename": "messageValue.proto",
          "Offset": 33,
          "Line": 5,
          "Column": 1
        },
        "LastPos": {
          "Filename": "messageValue.proto",
          "Offset": 74,
          "Line": 5,
          "Column": 42
        }
      }
    },
    {
      "MessageName": "MyFeatures",
      "MessageBody": [
        {
          "EnumName": "FeatureValue",
          "EnumBody": [
            {
              "Ident": "FEATURE_VALUE_UNKNOWN",
              "Number": "0",
              "EnumValueOptions": null,
              "Comments": null,
              "InlineComment": null,
              "Meta": {
                "Pos": {
                  "Filename": "messageValue.proto",
                  "Offset": 124,
                  "Line": 9,
                  "Column": 5
                },
                "LastPos": {
                  "Filename": "messageValue.proto",
                  "Offset": 149,
                  "Line": 9,
                  "Column": 30
                }
              }
            },
            {
              "Ident": "VALUE1",
              "Number": "1",
              "EnumValueOptions": null,
              "Comments": null,
              "InlineComment": null,
              "Meta": {
                "Pos": {
                  "Filename": "messageValue.proto",
                  "Offset": 155,
                  "Line": 10,
                  "Column": 5
                },
                "LastPos": {
                  "Filename": "messageValue.proto",
                  "Offset": 165,
                  "Line": 10,
                  "Column": 15
                }
              }
            },
            {
              "Ident": "VALUE2",
              "Number": "2",
              "EnumValueOptions": null,
              "Comments": null,
              "InlineComment": null,
              "Meta": {
                "Pos": {
                  "Filename": "messageValue.proto",
                  "Offset": 171,
                  "Line": 11,
                  "Column": 5
                },
                "LastPos": {
                  "Filename": "messageValue.proto",
                  "Offset": 181,
                  "Line": 11,
                  "Column": 15
                }
              }
            }
          ],
          "Comments": null,
          "InlineComment": null,
          "InlineCommentBehindLeftCurly": null,
          "Meta": {
            "Pos": {
              "Filename": "messageValue.proto",
              "Offset": 100,
              "Line": 8,
              "Column": 3
            },
            "LastPos": {
              "Filename": "messageValue.proto",
              "Offset": 185,
              "Line": 12,
              "Column": 3
            }
          }
        },
        {
          "IsRepeated": false,
          "IsRequired": false,
          "IsOptional": false,
          "Type": "FeatureValue",
          "FieldName": "feature_value",
          "FieldNumber": "1",
          "FieldOptions": [
            {
              "OptionName": "targets",
              "Constant": "TARGET_TYPE_FIELD"
            },
            {
              "OptionName": "targets",
              "Constant": "TARGET_TYPE_FILE"
            },
            {
              "OptionName": "feature_support",
              "Constant": "{edition_introduced:EDITION_2023,edition_deprecated:EDITION_2024,deprecation_warning:\"Feature will be removed in 2025\",edition_removed:EDITION_2025,}"
            },
            {
              "OptionName": "edition_defaults",
              "Constant": "{edition:EDITION_LEGACY,value:\"VALUE1\"}"
            },
            {
              "OptionName": "edition_defaults",
              "Constant": "{edition:EDITION_2024,value:\"VALUE2\"}"
            }
          ],
          "Comments": null,
          "InlineComment": null,
          "Meta": {
            "Pos": {
              "Filename": "messageValue.proto",
              "Offset": 190,
              "Line": 14,
              "Column": 3
            },
            "LastPos": {
              "Filename": "messageValue.proto",
              "Offset": 636,
              "Line": 25,
              "Column": 4
            }
          }
        }
      ],
      "Comments": null,
      "InlineComment": null,
      "InlineCommentBehindLeftCurly": null,
      "Meta": {
        "Pos": {
          "Filename": "messageValue.proto",
          "Offset": 77,
          "Line": 7,
          "Column": 1
        },
        "LastPos": {
          "Filename": "messageValue.proto",
          "Offset": 638,
          "Line": 26,
          "Column": 1
        }
      }
    }
  ],
  "Meta": {
    "Filename": "messageValue.proto"
  }
}

@yoheimuta yoheimuta added the question Further information is requested label Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants