diff options
Diffstat (limited to 'vendor/github.com/graphql-go/graphql/language/location')
-rw-r--r-- | vendor/github.com/graphql-go/graphql/language/location/location.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/github.com/graphql-go/graphql/language/location/location.go b/vendor/github.com/graphql-go/graphql/language/location/location.go new file mode 100644 index 00000000..04bbde6e --- /dev/null +++ b/vendor/github.com/graphql-go/graphql/language/location/location.go @@ -0,0 +1,35 @@ +package location + +import ( + "regexp" + + "github.com/graphql-go/graphql/language/source" +) + +type SourceLocation struct { + Line int `json:"line"` + Column int `json:"column"` +} + +func GetLocation(s *source.Source, position int) SourceLocation { + body := []byte{} + if s != nil { + body = s.Body + } + line := 1 + column := position + 1 + lineRegexp := regexp.MustCompile("\r\n|[\n\r]") + matches := lineRegexp.FindAllIndex(body, -1) + for _, match := range matches { + matchIndex := match[0] + if matchIndex < position { + line++ + l := len(s.Body[match[0]:match[1]]) + column = position + 1 - (matchIndex + l) + continue + } else { + break + } + } + return SourceLocation{Line: line, Column: column} +} |