pkger/parser/stat.go

58 lines
923 B
Go
Raw Permalink Normal View History

2019-10-23 20:19:39 +03:00
package parser
import (
"encoding/json"
2019-11-05 23:04:38 +03:00
"fmt"
2019-10-23 20:19:39 +03:00
"go/token"
"os"
)
var _ Decl = StatDecl{}
type StatDecl struct {
file *File
pos token.Position
2019-10-23 20:19:39 +03:00
value string
}
func (d StatDecl) String() string {
2019-11-05 23:04:38 +03:00
return fmt.Sprintf("pkger.Stat(%q)", d.value)
2019-10-23 20:19:39 +03:00
}
func (d StatDecl) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"type": "pkger.Stat",
"file": d.file,
"pos": d.pos,
"value": d.value,
})
}
func (d StatDecl) File() (*File, error) {
if d.file == nil {
return nil, os.ErrNotExist
}
return d.file, nil
}
func (d StatDecl) Position() (token.Position, error) {
2019-10-23 20:19:39 +03:00
return d.pos, nil
}
func (d StatDecl) Value() (string, error) {
if d.value == "" {
return "", os.ErrNotExist
}
return d.value, nil
}
func (d StatDecl) Files(virtual map[string]string) ([]*File, error) {
2019-11-01 22:53:54 +03:00
od := OpenDecl{
file: d.file,
pos: d.pos,
value: d.value,
2019-10-23 20:19:39 +03:00
}
2019-11-01 22:53:54 +03:00
return od.Files(virtual)
2019-10-23 20:19:39 +03:00
}