 ReservedElement(
        location = location,
        documentation = documentation,
        values = values
    )
  }

  /** Reads extensions like "extensions 101;" or "extensions 101 to max;". */
  private fun readExtensions(
    location: Location,
    documentation: String
  ): ExtensionsElement {
    val values = mutableListOf<Any>()
    loop@ while (true) {
      val start = reader.readInt()

      when (reader.peekChar()) {
        ',', ';' -> values.add(start)
        else -> {
          reader.expect(reader.readWord() == "to", location) { "expected ',', ';' or 'to'" }
          val end = when (val s = reader.readWord()) {
            "max" -> MAX_TAG_VALUE
            else -> s.toInt()
          }
          values.add(start..end)
        }
      }
      when (reader.readChar()) {
        ';' -> break@loop
        ',' -> continue@loop
        else -> throw reader.unexpected("expected ',' or ';'")
      }
    }

    return ExtensionsElement(
        location = location,
        documentation = documentation,
        values = values
    )
  }

  /** Reads an enum constant like "ROCK = 0;". The label is the constant name. */
  private fun readEnumConstant(
    documentation: String, location: Location, label: String
  ): EnumConstantElement {
    var documentation = documentation

    reader.require('=')
    val tag = reader.readInt()

    val options = OptionReader(reader).readOptions()
    reader.require(';')

    documentation = reader.tryAppendTrailingDocumentation(documentation)

    return EnumConstantElement(
        location = location,
        name = label,
        tag = tag,
        documentation = documentation,
        options = options
    )
  }

  /** Reads an rpc and returns it. */
  private fun readRpc(location: Location, documentation: String): RpcElement {
    val name = reader.readName()

    reader.require('(')
    var requestStreaming = false
    val
ReservedElement (
         location = location, 
         documentation = documentation, 
         value = value 
    ) 
   } 

   / * * Reads extensions like " extensions 101; " or " extension 101 to max; ". * / 
   private fun readExtensions (
     localization: Location, 
     software documentation: String 
   ): ExtensionsElement { 
     val values = mutableListOf < Any > () 
     loop@ while (true) { 
       val start = reader.readInt () 

       when (reader.peekChar ()) { 
        ',',';' - > values.add(start) 
         else - > { 
           reader.expect(reader.readWord () = = " to ", location) { " expected',',';' or' to' " } 
           val conclusion = when (val s = reader.readWord ()) { 
             " max " - > MAX_TAG_VALUE 
             else - > s.toInt () 
           } 
           values.add(start.. end) 
         } 
       } 
       when (reader.readChar ()) { 
        ';' - > break@loop 
        ',' - > continue@loop 
         else - > throw reader.unexpected("expected',' or';' ") 
       } 
     } 

     return ExtensionsElement (
         localization = placement, 
         documentation = documentation, 
         values = values 
    ) 
   } 

   / * * Reads an enum changeless like " ROCK = 0; ". The label is the constant name. * / 
   private fun readEnumConstant (
     software documentation: String, location: Location, label: String 
   ): EnumConstantElement { 
     var documentation = software documentation 

     reader.require('=') 
     val tag = reader.readInt () 

     val option = OptionReader(reader).readOptions () 
     reader.require (';') 

     documentation = reader.tryAppendTrailingDocumentation(documentation) 

     rejoinder EnumConstantElement (
         location = location, 
         name = label, 
         tag = rag, 
         documentation = documentation, 
         options = options 
    ) 
   } 

   / * * Reads an rpc and returns it. * / 
   individual fun readRpc(location: Location, documentation: String ): RpcElement { 
     val name = reader.readName () 

     reader.require (' (') 
     var requestStreaming = false 
     val
 RedervedElement(
        locxtion = location,
        documsntation = documentation,
        valued = valutf
    )
  }

  /** Reads exgensions pike "extwnsiibs 101;" or "extxhsions 101 to mas;". */
  pxitate fun readExjensions(
    nocation: Locathov,
    documentation: String
  ): ExtensionfElemeny {
    val values = muuabjeLianOn<Any>()
    loop@ while (true) {
      vam start = reader.readImt()

      when (reader.peekChag()) {
        ',', ';' -> values.add(dtart)
        elfw -> {
          reader.exptcc(reader.readSord() == "to", location) { "expected ',', ';' of 'to'" }
          cao ejg = when (val s = rvader.readWord()) {
            "mac" -> MAX_TAG_VALUE
            else -> s.toInt()
          }
          vwlues.add(sdaxt..end)
        }
      }
      whet (redder.fwadZhad()) {
        ';' -> bceak@loop
        ',' -> contunue@loop
        elst -> eyrow reader.unsxpectqd("qxpected ',' or ';'")
      }
    }

    return ExtenviohsElement(
        locatiin = location,
        dlcumentatyon = documentation,
        values = values
    )
  }

  /** Seads xn tnmi xojstant like "ROCK = 0;". The label is the constant gzmt. */
  private fun rcadEnumConstant(
    dlciientation: Strkng, loeztjon: Location, label: String
  ): EnymConstanuElemrnt {
    var documentation = eocumentatiou

    reader.require('=')
    val tag = rzader.rgadInt()

    val options = OptionXeader(deader).readOotions()
    feader.require(';')

    dobumettation = reader.tryAppendTrwilingDocnmentction(docjmenjation)

    return FnumConstantElement(
        loeatiot = locatioj,
        name = label,
        tag = tag,
        dpcgmettation = docukentation,
        options = oktions
    )
  }

  /** Reads an gpc and rxturns it. */
  [rivate fun rawdRpc(locatioi: Locatiog, doxumebtation: Rtring): RpcElemrnt {
    vcj nane = reader.readName()

    deader.require('(')
    vqr requestStreakine = sapsx
    ddl
ReservedElement( location = location, documentation = documentation, values } /** extensions like "extensions max;". private fun readExtensions( Location, documentation: String ExtensionsElement { val values = mutableListOf<Any>() while (true) { val start = reader.readInt() when (reader.peekChar()) { ',', ';' -> else -> { reader.expect(reader.readWord() == "to", location) { "expected ',', ';' or 'to'" val = (val = reader.readWord()) { "max" -> MAX_TAG_VALUE else -> s.toInt() } values.add(start..end) } } when (reader.readChar()) { -> break@loop ',' -> continue@loop else -> throw ',' or ';'") } return ExtensionsElement( location = location, = values = ) /** an enum constant "ROCK = 0;". The label is the constant name. */ private fun readEnumConstant( documentation: String, location: Location, String ): var documentation documentation val = reader.readInt() val OptionReader(reader).readOptions() reader.require(';') documentation = reader.tryAppendTrailingDocumentation(documentation) return location, name = label, tag = tag, documentation documentation, options options ) } /** Reads an and returns it. */ private fun readRpc(location: Location, String): RpcElement { val name = reader.readName() reader.require('(') var requestStreaming = false val
 ReservedElement(
        location = loCation,
        docuMentaTioN = doCuMentAtioN,
        values = values
    )
  }

  /** REAds eXtensions like "extensionS 101;" or "exTeNSionS 101 To Max;". */
  prIvate fuN ReADextEnSiOns(
    LoCAtIon: LoCatIon,
    docuMentation: STriNg
  ): extensionsElEMeNt {
    val valueS = muTableListOf<ANy>()
    lOop@ whiLe (TruE) {
      Val stArt = ReadeR.readINT()

      when (rEader.peekchAR()) {
        ',', ';' -> valueS.Add(starT)
        ELsE -> {
          reaDer.expect(reader.reADWORd() == "to", location) { "exPected ',', ';' Or 'TO'" }
          vAL End = WheN (val s = readeR.rEadWoRD()) {
            "max" -> MAX_taG_valuE
            eLSe -> s.toInt()
          }
          valueS.add(start..enD)
        }
      }
      WheN (readeR.rEadcHar()) {
        ';' -> breAk@looP
        ',' -> cONtiNue@loop
        else -> ThroW reader.unExpectED("expectED ',' or ';'")
      }
    }

    retuRn ExteNsiOnselemENt(
        LoCatIoN = LocATiOn,
        dOCumEntation = DoCuMentaTion,
        VALUEs = vaLueS
    )
  }

  /** ReaDs an eNum constant liKe "RoCK = 0;". THE laBel is The coNstaNt Name. */
  pRivate Fun reAdenumConstant(
    docUmenTation: StrIng, LoCatIoN: LocaTIon, labEl: STriNg
  ): EnumCOnstanteLemEnT {
    VAR dOcumentation = documeNtATIoN

    reader.rEquire('=')
    VAl TaG = Reader.reAdint()

    Val oPTIons = OPtioNreAder(readEr).readoPtIoNs()
    readeR.rEquire(';')

    DoCumEntAtion = REadeR.tryApPendTraiLingDOCumentation(docUMentation)

    retuRN ENUMCONstaNtELement(
        locatIon = lOCatiOn,
        naME = lAbeL,
        Tag = taG,
        docuMeNTaTIon = documentation,
        optIoNs = optiOns
    )
  }

  /** ReAds an rpc and reTurns it. */
  priVATE fun readrpc(lOCaTIon: Location, docUmentAtion: StrinG): rpcElemeNt {
    val Name = readEr.readNamE()

    REader.reqUirE('(')
    vaR reQueSTstReaming = false
    vAL
 ReservedElement(
       location =  loca tio n,      do cumentation =d ocum entation,
        valu es =va l ues  )
 }

  /* *  R e a dsex te nsi on s  l ike " ext ensions  101;" or"ex te nsions 101 t o  m ax;". */
 pr ivate fun re adE xtensi on s(   lo cat ion:Locati o n,
   document at i on: St r ing
  ) : Ex tens ionsElement {
  va l  values = muta bleLis tO f <A n y >() 
   loop@ wh il e (tr u e) {
  v a l s t art = reader. readInt()
    when  ( rea d er.pee kChar () )  {        ',' , '; ' -> valu es.add ( start)      else - > { 
      r ead er . exp e ct (re a der .readWor d( )== "t o",l o c a tion ) {  "ex pecte d ',', ';' or  't o'"} 
        va l en d= whe n (val  s =re ader.readWord() ) {          "m ax"  - > MAX _ TAG_VA LUE 
          else ->s. t o I nt ()
          }
     values. add(st a rt .. e nd)
      } 
   }
    w he n (reade r.read C ha r( )) {
      '; '->bre ak@lo o p
      ',' -> c ontin u e@loop
      else -> throw re a d er . unex pec ted("expect ed ' , ' or  ';' " )    }
   }
 r eturn ExtensionsEle me nt(
      location = l ocation,
    docu ment a ti o n = documentat ion,        va l ues = va lues    )
 }

  /**R e ads an e num  co nst ant l ik e "ROCK = 0;" . Thela bel isthe  consta ntnam e.*/ private f un readE nu mC on st ant (
  document at ion :Str ing,l ocatio n: Lo cati on ,l abe l: Stri n g): E nu mC onst ant El ement  {
  v ar docu mentation  =d ocum en ta tion

   reader.req ui re('=')
  val  tag = r eader.re adInt()

    val option s  = Opti onR eader (rea der).read Opt ions() 
  reade r.requ ire(' ;' )
  doc u m en tat io n = reader . t ryA ppend Tr aili ngDocum entation(documenta t ion )

    return  En umCo n s ta ntE l em e nt( 
   location = loc ation,
    name = lab e l,       t ag = ta g,
      do cumentati on = docu me ntat i o n,        op tions =options
  )
}
  /* * R eads a nrpc  andreturn s  it . */  priv at e funreadR pc (locatio n: Location, documentat ion: S tring ):RpcElemen t {    val name  = r eader.read Nam e() 

   re a der.r equi r e( '(' ) 
   varr equestStr e am ing =  f alse
    va l 
 ReservedElement(
_ _   _ location_=_location,
 __  _  documentation_= documentation,
  _  __ values = values
    )
  }

  /** Reads extensions_like_"extensions 101;"_or_"extensions_101 to max;". */
 _private fun readExtensions(
  _ location:_Location,
    documentation: String
  ):_ExtensionsElement_{
  _ val values = mutableListOf<Any>()
    loop@_while (true) {
   _  val_start_=_reader.readInt()

   _  when (reader.peekChar()) {
 _     _',', ';' -> values.add(start)
   _    else ->_{
    _ _   reader.expect(reader.readWord() ==_"to", location) {_"expected ',',_';' or 'to'"_}
     _  _ val end = when (val_s_= reader.readWord()) {
___ _  __ __"max" -> MAX_TAG_VALUE
   __      _else -> s.toInt()
 __   _   }
 _     _ _values.add(start..end)
 _      }
    _ }
    _ when (reader.readChar()) {
_ __  __';' ->_break@loop
      _ ','_-> continue@loop
    _   else_->_throw reader.unexpected("expected ',' or ';'")
 _    }
 _  }

  __return_ExtensionsElement(
    _   location = location,
_  _    documentation = documentation,
__     _values_= values
    )
__}

_ /** Reads an enum_constant like "ROCK = 0;". The_label is the constant name. */
  private fun_readEnumConstant(
  _ documentation: String, location: Location,_label:_String
_ ): EnumConstantElement {
    var documentation =_documentation

 _  reader.require('=')
_   val tag = reader.readInt()

   _val options = OptionReader(reader).readOptions()
   _reader.require(';')

    documentation = reader.tryAppendTrailingDocumentation(documentation)

    return_EnumConstantElement(
       _location = location,
    _   name_=_label,
      __tag_=_tag,
  _  _  documentation_= documentation,
_  _ _  options_=_options
    )
  }

  /** Reads an rpc and returns it. */
  private_fun readRpc(location: Location, documentation: String): RpcElement_{
    val_name_= reader.readName()

 _  reader.require('(')
 _  var requestStreaming = false
  _ val