From 7a119d606d71914a6fd00c0bd51bca227a13f8d3 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Thu, 27 Jun 2024 13:24:50 +0800 Subject: [PATCH] Fix index logic in detecting descriptor kind --- bindings/go/scip/symbol.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bindings/go/scip/symbol.go b/bindings/go/scip/symbol.go index e10eec01..8a0ca020 100644 --- a/bindings/go/scip/symbol.go +++ b/bindings/go/scip/symbol.go @@ -511,11 +511,9 @@ func (z *zeroAllocSymbolParser) Advance(nextRune rune, nextRuneByteLength int32) func (z *zeroAllocSymbolParser) parseDescriptor(out *RawDescriptorList) error { start := z.byteIndex - nextRune, nextRuneByteLength := z.peekNext() - switch nextRune { + switch z.currentRune { case '(': - z.Advance('(', nextRuneByteLength) - z.advanceRune() + z.advanceOneByte('(') name, err := z.acceptIdentifier(parseCtxParameterName) if err != nil { return err @@ -524,8 +522,7 @@ func (z *zeroAllocSymbolParser) parseDescriptor(out *RawDescriptorList) error { return z.acceptOneByte(')', parseCtxClosingParameterName) //return &Descriptor{Name: name, Suffix: Descriptor_Parameter}, z.acceptCharacter(')', "closing parameter name") case '[': - z.Advance('[', nextRuneByteLength) - z.advanceRune() + z.advanceOneByte('[') name, err := z.acceptIdentifier(parseCtxTypeParameterName) if err != nil { return err @@ -608,12 +605,15 @@ func (s *symbolParser) acceptIdentifier(what string) (string, error) { func (z *zeroAllocSymbolParser) advanceOneByte(_ byte) { // TODO: Add build tag with asserts and check that current byte matches the passed in byte. nextRune, nextRuneByteLength := z.peekNext() - z.Advance(nextRune, nextRuneByteLength) + // z.byteIndex can become equal to len(z.SymbolString) here + z.byteIndex += 1 + z.currentRune = nextRune + z.bytesToNextRune = nextRuneByteLength } func (z *zeroAllocSymbolParser) advanceRune() { nextRune, nextRuneByteLength := z.peekNext() - z.Advance(nextRune, nextRuneByteLength) + z.Advance(nextRune, min(nextRuneByteLength, 1)) } func (z *zeroAllocSymbolParser) acceptOneByte(b byte, what parseCtx) error {