extensions.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2017 Ernest Micklei
  2. //
  3. // MIT License
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining
  6. // a copy of this software and associated documentation files (the
  7. // "Software"), to deal in the Software without restriction, including
  8. // without limitation the rights to use, copy, modify, merge, publish,
  9. // distribute, sublicense, and/or sell copies of the Software, and to
  10. // permit persons to whom the Software is furnished to do so, subject to
  11. // the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be
  14. // included in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. package proto
  24. import (
  25. "text/scanner"
  26. )
  27. // Extensions declare that a range of field numbers in a message are available for third-party extensions.
  28. // proto2 only
  29. type Extensions struct {
  30. Position scanner.Position
  31. Comment *Comment
  32. Ranges []Range
  33. InlineComment *Comment
  34. Parent Visitee
  35. }
  36. // inlineComment is part of commentInliner.
  37. func (e *Extensions) inlineComment(c *Comment) {
  38. e.InlineComment = c
  39. }
  40. // Accept dispatches the call to the visitor.
  41. func (e *Extensions) Accept(v Visitor) {
  42. v.VisitExtensions(e)
  43. }
  44. // parse expects ranges
  45. func (e *Extensions) parse(p *Parser) error {
  46. list, err := parseRanges(p, e)
  47. if err != nil {
  48. return err
  49. }
  50. e.Ranges = list
  51. return nil
  52. }
  53. // parent is part of elementContainer
  54. func (e *Extensions) parent(p Visitee) { e.Parent = p }