yoheimuta/go-protoparser

Multiline string literals error

Closed this issue · 6 comments

String literals that are split between multiple lines in proto annotations cause an error in go-protoparser. Running the parser on _testdata/simple.proto with the following modification

enum EnumAllowingAlias {
    option allow_alias = true;
    UNKNOWN = 0;
    STARTED = 1;
    RUNNING = 2 [(custom_option) = "this is a "
                                   "string on two lines"
                ];
}

results in this error

failed to parse, err found "\""(Token=11, Pos=simple.proto:12:36) but expected []] at //go/src/github.com/yoheimuta/go-protoparser/parser/enum.go:293:found "\"" but expected [;]

Despite this syntax being accepted by the compiler. It's not clear from the language spec what the proper syntax for multiline literals is, however.

Thank you for reporting the issue and providing a failing example.
The go-protoparser should support this case. I will take a look.

@pleask I have cut a release to support this case.
Please let me know if you can still experience the problem.

@yoheimuta thanks for the quick response. This fixes this issue for enum values, however the issue is exists for string literals in general (so annotations on all other proto objects are also affected). Based on your changes for the enum I can make similar changes for other objects, if you like.

@pleask Thank you for the additional comment.
Actually, I was not sure about the specific scopes at that moment.

Based on your changes for the enum I can make similar changes for other objects, if you like.

I appreciate it. It will help me a lot.

I've opened a pull request that merges together consecutive string literals when they are constant in an option. This solves our problem, I think, without negative consequences.

@pleask I merged the PR and pushed it to releases.
Plus, I also published a protolint release by updating this parser. Great thanks!