1package json23import (4 "errors"5)67// ParsePath takes a JSONPath string and returns a slice of strings representing the path segments.8func ParsePath(path string) ([]string, error) {9 buf := newBuffer([]byte(path))10 result := make([]string, 0)1112 for {13 b, err := buf.current()14 if err != nil {15 break16 }1718 switch {19 case b == dollarSign || b == atSign:20 result = append(result, string(b))21 buf.step()2223 case b == dot:24 buf.step()2526 if next, _ := buf.current(); next == dot {27 buf.step()28 result = append(result, "..")2930 extractNextSegment(buf, &result)31 } else {32 extractNextSegment(buf, &result)33 }3435 case b == bracketOpen:36 start := buf.index37 buf.step()3839 for {40 if buf.index >= buf.length || buf.data[buf.index] == bracketClose {41 break42 }4344 buf.step()45 }4647 if buf.index >= buf.length {48 return nil, errors.New("unexpected end of path")49 }5051 segment := string(buf.sliceFromIndices(start+1, buf.index))52 result = append(result, segment)5354 buf.step()5556 default:57 buf.step()58 }59 }6061 return result, nil62}6364// extractNextSegment extracts the segment from the current index65// to the next significant character and adds it to the resulting slice.66func extractNextSegment(buf *buffer, result *[]string) {67 start := buf.index68 buf.skipToNextSignificantToken()6970 if buf.index <= start {71 return72 }7374 segment := string(buf.sliceFromIndices(start, buf.index))75 if segment != "" {76 *result = append(*result, segment)77 }78}79Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.