fun parseDescriptorElement()

in src/main/kotlin/ScipSymbolDescriptor.kt [47:78]


      fun parseDescriptorElement(): ScipSymbolDescriptorElement {
        if (descriptor[index] == '(') {
          return parseDescriptorElementUntil(')', Scip.Descriptor.Suffix.Parameter)
        }
        if (descriptor[index] == '[') {
          return parseDescriptorElementUntil(']', Scip.Descriptor.Suffix.TypeParameter)
        }
        val lastIndex = descriptor.indexOfAny("/#.:(".toCharArray(), index)
        if (lastIndex == -1) {
          index = descriptor.length
          return ScipSymbolDescriptorElement(descriptor.substring(index),null, Scip.Descriptor.Suffix.UnspecifiedSuffix)
        }
        val name = descriptor.substring(index, lastIndex)
        if (descriptor[lastIndex] == '(') {
          val nameEndIndex = descriptor.indexOf(").", lastIndex + 1)
          index = nameEndIndex + 1
          return ScipSymbolDescriptorElement(
            name,
            descriptor.substring(lastIndex+1, nameEndIndex),
            Scip.Descriptor.Suffix.Method
          )
        }
        val suffix = when (descriptor[lastIndex]) {
          '/' -> Scip.Descriptor.Suffix.Package
          '#' -> Scip.Descriptor.Suffix.Type
          '.' -> Scip.Descriptor.Suffix.Term
          ':' -> Scip.Descriptor.Suffix.Meta
          else -> throw IllegalStateException()
        }
        index = lastIndex + 1
        return ScipSymbolDescriptorElement(name, null, suffix)
      }