summaryrefslogtreecommitdiff
path: root/vendor/github.com/authzed/spicedb/pkg/schemadsl/compiler/positionmapper.go
blob: aa33c43b2cf8021fe4888170103a032bd8b17599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package compiler

import (
	"strings"

	"github.com/authzed/spicedb/pkg/schemadsl/input"
)

type positionMapper struct {
	schema InputSchema
	mapper input.SourcePositionMapper
}

func newPositionMapper(schema InputSchema) input.PositionMapper {
	return &positionMapper{
		schema: schema,
		mapper: input.CreateSourcePositionMapper([]byte(schema.SchemaString)),
	}
}

func (pm *positionMapper) RunePositionToLineAndCol(runePosition int, _ input.Source) (int, int, error) {
	return pm.mapper.RunePositionToLineAndCol(runePosition)
}

func (pm *positionMapper) LineAndColToRunePosition(lineNumber int, colPosition int, _ input.Source) (int, error) {
	return pm.mapper.LineAndColToRunePosition(lineNumber, colPosition)
}

func (pm *positionMapper) TextForLine(lineNumber int, _ input.Source) (string, error) {
	lines := strings.Split(pm.schema.SchemaString, "\n")
	return lines[lineNumber], nil
}