a940c30903
The new "Nav" member on a zcl.File is an opaque object that can be populated by parsers with an object that supports certain interfaces that are not part of the main API but are useful for integration with editors and other tooling. As a first example of this, we replace the hack for getting context in the diagnostic package with a new ContextString interface, which can then be optionally implemented by a given parser to return a contextual string native to the source language.
21 lines
575 B
Go
21 lines
575 B
Go
package zcled
|
|
|
|
import (
|
|
"github.com/apparentlymart/go-zcl/zcl"
|
|
)
|
|
|
|
type contextStringer interface {
|
|
ContextString(offset int) string
|
|
}
|
|
|
|
// ContextString returns a string describing the context of the given byte
|
|
// offset, if available. An empty string is returned if no such information
|
|
// is available, or otherwise the returned string is in a form that depends
|
|
// on the language used to write the referenced file.
|
|
func ContextString(file *zcl.File, offset int) string {
|
|
if cser, ok := file.Nav.(contextStringer); ok {
|
|
return cser.ContextString(offset)
|
|
}
|
|
return ""
|
|
}
|