github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/schemadsl/compiler/positionmapper.go (about)

     1  package compiler
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/authzed/spicedb/pkg/schemadsl/input"
     7  )
     8  
     9  type positionMapper struct {
    10  	schema InputSchema
    11  	mapper input.SourcePositionMapper
    12  }
    13  
    14  func newPositionMapper(schema InputSchema) input.PositionMapper {
    15  	return &positionMapper{
    16  		schema: schema,
    17  		mapper: input.CreateSourcePositionMapper([]byte(schema.SchemaString)),
    18  	}
    19  }
    20  
    21  func (pm *positionMapper) RunePositionToLineAndCol(runePosition int, _ input.Source) (int, int, error) {
    22  	return pm.mapper.RunePositionToLineAndCol(runePosition)
    23  }
    24  
    25  func (pm *positionMapper) LineAndColToRunePosition(lineNumber int, colPosition int, _ input.Source) (int, error) {
    26  	return pm.mapper.LineAndColToRunePosition(lineNumber, colPosition)
    27  }
    28  
    29  func (pm *positionMapper) TextForLine(lineNumber int, _ input.Source) (string, error) {
    30  	lines := strings.Split(pm.schema.SchemaString, "\n")
    31  	return lines[lineNumber], nil
    32  }