From da5d171479574f199cd3b57c74186e53f9cfb432 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 27 Oct 2023 18:57:44 +0200 Subject: [PATCH] Fix lint errors --- gg/decoder.go | 10 ++++------ gg/grammar/location.go | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gg/decoder.go b/gg/decoder.go index 6d41d80..e3acbcf 100644 --- a/gg/decoder.go +++ b/gg/decoder.go @@ -53,9 +53,7 @@ var ( Rune('-'), positiveNumber, func(neg Located[rune], posNum Located[string]) Located[string] { - return Located[string]{ - neg.Location, string(neg.Value) + posNum.Value, - } + return Locate(neg.Location, string(neg.Value)+posNum.Value) }, ) @@ -68,7 +66,7 @@ var ( panic(fmt.Errorf("parsing %q as int: %w", str, err)) } - return Located[Value]{str.Location, Number(i)} + return Locate(str.Location, Number(i)) }, ) ) @@ -93,7 +91,7 @@ var ( for _, r := range tail { name = append(name, r.Value) } - return Located[Value]{head.Location, Name(string(name))} + return Locate(head.Location, Name(string(name))) }, ) ) @@ -228,7 +226,7 @@ var graphSym, value = func() ( gs.g = new(Graph) } - return Located[Value]{r.Location, Value{Graph: gs.g}} + return Locate(r.Location, Value{Graph: gs.g}) }, ) diff --git a/gg/grammar/location.go b/gg/grammar/location.go index 1c45171..9e0c64e 100644 --- a/gg/grammar/location.go +++ b/gg/grammar/location.go @@ -18,6 +18,11 @@ type Located[T any] struct { Value T } +// Locate returns a Located instance combining the given values. +func Locate[T any](l Location, v T) Located[T] { + return Located[T]{l, v} +} + // LocatedError is an error related to a specific point within a stream of // runes. type LocatedError Located[error]