@@ -2,6 +2,7 @@ package parser
22
33import (
44 "fmt"
5+ "strings"
56
67 "github.com/yoheimuta/go-protoparser/internal/lexer/scanner"
78 "github.com/yoheimuta/go-protoparser/parser/meta"
@@ -313,8 +314,47 @@ func (p *Parser) parseEnumValueOption() (*EnumValueOption, error) {
313314 return nil , err
314315 }
315316
317+ if p .permissive {
318+ // accept a multiple string literals. See https://github.com/yoheimuta/go-protoparser/issues/35.
319+ for {
320+ next := p .lex .Peek ()
321+ if next == scanner .TCOMMA || next == scanner .TRIGHTSQUARE {
322+ break
323+ }
324+
325+ lit , _ , err := p .lex .ReadConstant ()
326+ if err != nil {
327+ return nil , err
328+ }
329+ constant = p .concatLiteral (constant , lit )
330+ }
331+ }
332+
316333 return & EnumValueOption {
317334 OptionName : optionName ,
318335 Constant : constant ,
319336 }, nil
320337}
338+
339+ func (p * Parser ) concatLiteral (base , next string ) string {
340+ unQuoteNext , _ , err := p .unQuote (next )
341+ if err != nil {
342+ return base + next
343+ }
344+
345+ unQuoteBase , quote , err := p .unQuote (base )
346+ if err != nil {
347+ return base + next
348+ }
349+
350+ return string (quote ) + unQuoteBase + unQuoteNext + string (quote )
351+ }
352+
353+ func (p * Parser ) unQuote (lit string ) (string , rune , error ) {
354+ for _ , c := range []rune {'\'' , '"' } {
355+ if strings .HasPrefix (lit , string (c )) && strings .HasSuffix (lit , string (c )) {
356+ return lit [1 : len (lit )- 1 ], c , nil
357+ }
358+ }
359+ return lit , 0 , p .unexpected ("quote" )
360+ }
0 commit comments