<commit_before>package class

import (
    "strings"
)

type MemberDescriptorParser struct {
    descriptor  string
    offset      int
    md          *MethodDescriptor
}

func calcArgCount(descriptor string) (uint) {
    return parseMethodDescriptor(descriptor).argCount()
}

func parseMethodDescriptor(descriptor string) (*MethodDescriptor) {
    parser := &MemberDescriptorParser{descriptor: descriptor}
    return parser.parse()
}

func (self *MemberDescriptorParser) parse() (*MethodDescriptor) {
    self.md = &MethodDescriptor{}
    self.startParams()
    self.parseParamTypes()
    self.endParams()
    self.parseReturnType()
    self.finish()
    return self.md
}

func (self *MemberDescriptorParser) startParams() {
    if self.readUint8() != '(' {
        self.causePanic()
    }
}
func (self *MemberDescriptorParser) endParams() {
    if self.readUint8() != ')' {
        self.causePanic()
    }
}
func (self *MemberDescriptorParser) finish() {
    if self.offset != len(self.descriptor) {
        self.causePanic()
    }
}

func (self *MemberDescriptorParser) causePanic() {
    panic("BAD descriptor: " + self.descriptor)
}

func (self *MemberDescriptorParser) readUint8() uint8 {
    b := self.descriptor[self.offset]
    self.offset++
    return b
}
func (self *MemberDescriptorParser) unreadUint8() {
    self.offset--
}

func (self *MemberDescriptorParser) parseParamTypes() {
    for {
        t := self.parseFieldType()
        if t != nil {
            self.md.addParameterType(t)
        } else {
            break
        }
    }
}
func (self *MemberDescriptorParser) parseReturnType() {
    t := self.parseFieldType()
    if t != nil {
        self.md.returnType = t
    } else {
        self.causePanic()
    }
}

func (self *MemberDescriptorParser) parseFieldType() (*FieldType) {
    switch self.readUint8() {
    case 'B': return baseTypeB
    case 'C': return baseTypeC
    case 'D': return baseTypeD
    case 'F': return baseTypeF
    case 'I': return baseTypeI
    case 'J': return baseTypeJ
    case 'S': return baseTypeS
    case 'Z': return baseTypeZ
    case 'V': return baseTypeV
    case 'L': return self.parseObjectType()
    case '[': return self.parseArrayType()
    default:
        self.unreadUint8()
        return nil
    }
}
func (self *MemberDescriptorParser) parseObjectType() (*FieldType) {
    unread := self.descriptor[self.offset:]
    semicolonIndex := strings.IndexRune(unread, ';')
    if semicolonIndex == -1 {
        self.causePanic()
        return nil
    } else {
        objStart := self.offset - 1
        objEnd := self.offset + semicolonIndex + 1
        self.offset = objEnd
        descriptor := self.descriptor[objStart: objEnd]
        return &FieldType{descriptor}
    }
}
func (self *MemberDescriptorParser) parseArrayType() (*FieldType) {
    arrStart := self.offset - 1
    self.parseFieldType()
    arrEnd := self.offset
    descriptor := self.descriptor[arrStart: arrEnd]
    return &FieldType{descriptor}
}<commit_msg>reorder code<commit_after>package class

import (
    "strings"
)

type MemberDescriptorParser struct {
    descriptor  string
    offset      int
    md          *MethodDescriptor
}

func (self *MemberDescriptorParser) parse() (*MethodDescriptor) {
    self.md = &MethodDescriptor{}
    self.startParams()
    self.parseParamTypes()
    self.endParams()
    self.parseReturnType()
    self.finish()
    return self.md
}

func (self *MemberDescriptorParser) startParams() {
    if self.readUint8() != '(' {
        self.causePanic()
    }
}
func (self *MemberDescriptorParser) endParams() {
    if self.readUint8() != ')' {
        self.causePanic()
    }
}
func (self *MemberDescriptorParser) finish() {
    if self.offset != len(self.descriptor) {
        self.causePanic()
    }
}

func (self *MemberDescriptorParser) causePanic() {
    panic("BAD descriptor: " + self.descriptor)
}

func (self *MemberDescriptorParser) readUint8() uint8 {
    b := self.descriptor[self.offset]
    self.offset++
    return b
}
func (self *MemberDescriptorParser) unreadUint8() {
    self.offset--
}

func (self *MemberDescriptorParser) parseParamTypes() {
    for {
        t := self.parseFieldType()
        if t != nil {
            self.md.addParameterType(t)
        } else {
            break
        }
    }
}
func (self *MemberDescriptorParser) parseReturnType() {
    t := self.parseFieldType()
    if t != nil {
        self.md.returnType = t
    } else {
        self.causePanic()
    }
}

func (self *MemberDescriptorParser) parseFieldType() (*FieldType) {
    switch self.readUint8() {
    case 'B': return baseTypeB
    case 'C': return baseTypeC
    case 'D': return baseTypeD
    case 'F': return baseTypeF
    case 'I': return baseTypeI
    case 'J': return baseTypeJ
    case 'S': return baseTypeS
    case 'Z': return baseTypeZ
    case 'V': return baseTypeV
    case 'L': return self.parseObjectType()
    case '[': return self.parseArrayType()
    default:
        self.unreadUint8()
        return nil
    }
}
func (self *MemberDescriptorParser) parseObjectType() (*FieldType) {
    unread := self.descriptor[self.offset:]
    semicolonIndex := strings.IndexRune(unread, ';')
    if semicolonIndex == -1 {
        self.causePanic()
        return nil
    } else {
        objStart := self.offset - 1
        objEnd := self.offset + semicolonIndex + 1
        self.offset = objEnd
        descriptor := self.descriptor[objStart: objEnd]
        return &FieldType{descriptor}
    }
}
func (self *MemberDescriptorParser) parseArrayType() (*FieldType) {
    arrStart := self.offset - 1
    self.parseFieldType()
    arrEnd := self.offset
    descriptor := self.descriptor[arrStart: arrEnd]
    return &FieldType{descriptor}
}


func calcArgCount(descriptor string) (uint) {
    return parseMethodDescriptor(descriptor).argCount()
}

func parseMethodDescriptor(descriptor string) (*MethodDescriptor) {
    parser := &MemberDescriptorParser{descriptor: descriptor}
    return parser.parse()
}
{'fraction_non_alphanumeric': 0.11957247828991316, 'fraction_numerical': 0.003674014696058784, 'mean_word_length': 2.942725477287689, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4930395', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1789, 'n_words': 425}