@@ -44,6 +44,8 @@ type Oneof struct {
4444 OneofFields []* OneofField
4545 OneofName string
4646
47+ Options []* Option
48+
4749 // Comments are the optional ones placed at the beginning.
4850 Comments []* Comment
4951 // InlineComment is the optional one placed at the ending.
@@ -68,6 +70,9 @@ func (o *Oneof) Accept(v Visitor) {
6870 for _ , field := range o .OneofFields {
6971 field .Accept (v )
7072 }
73+ for _ , option := range o .Options {
74+ option .Accept (v )
75+ }
7176 for _ , comment := range o .Comments {
7277 comment .Accept (v )
7378 }
@@ -101,6 +106,7 @@ func (p *Parser) ParseOneof() (*Oneof, error) {
101106 inlineLeftCurly := p .parseInlineComment ()
102107
103108 var oneofFields []* OneofField
109+ var options []* Option
104110 for {
105111 comments := p .ParseComments ()
106112
@@ -109,13 +115,27 @@ func (p *Parser) ParseOneof() (*Oneof, error) {
109115 continue
110116 }
111117
112- oneofField , err := p .parseOneofField ()
113- if err != nil {
114- return nil , err
118+ p .lex .NextKeyword ()
119+ token := p .lex .Token
120+ p .lex .UnNext ()
121+ if p .permissive && token == scanner .TOPTION {
122+ // accept an option. See https://github.com/yoheimuta/go-protoparser/issues/39.
123+ option , err := p .ParseOption ()
124+ if err != nil {
125+ return nil , err
126+ }
127+ option .Comments = comments
128+ p .MaybeScanInlineComment (option )
129+ options = append (options , option )
130+ } else {
131+ oneofField , err := p .parseOneofField ()
132+ if err != nil {
133+ return nil , err
134+ }
135+ oneofField .Comments = comments
136+ p .MaybeScanInlineComment (oneofField )
137+ oneofFields = append (oneofFields , oneofField )
115138 }
116- oneofField .Comments = comments
117- p .MaybeScanInlineComment (oneofField )
118- oneofFields = append (oneofFields , oneofField )
119139
120140 p .lex .Next ()
121141 if p .lex .Token == scanner .TRIGHTCURLY {
@@ -137,6 +157,7 @@ func (p *Parser) ParseOneof() (*Oneof, error) {
137157 return & Oneof {
138158 OneofFields : oneofFields ,
139159 OneofName : oneofName ,
160+ Options : options ,
140161 InlineCommentBehindLeftCurly : inlineLeftCurly ,
141162 Meta : meta .NewMetaWithLastPos (startPos , lastPos ),
142163 }, nil
0 commit comments