diff --git a/lib/doc.go b/lib/doc.go index fea44de..7b34dc0 100644 --- a/lib/doc.go +++ b/lib/doc.go @@ -29,6 +29,7 @@ import ( "strings" ) +// Doc represents a Moon document. type Doc struct { items map[string]interface{} } diff --git a/lib/parse.go b/lib/parse.go index 76a326e..b0048c9 100644 --- a/lib/parse.go +++ b/lib/parse.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "os" "strings" ) @@ -42,6 +43,16 @@ func ReadBytes(b []byte) (*Doc, error) { return Read(bytes.NewBuffer(b)) } +func ReadFile(path string) (*Doc, error) { + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + + return Read(f) +} + func parse(r io.Reader) (node, error) { p := &parser{ root: newRootNode(),