blob: b066c3be01f5f1a4241bbd8b1d0710b4f3bf8bff (
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/composableschemadsl/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
}
|