zclwrite: File-level AllTokens
This captures any leftover tokens that aren't considered part of the file's main body, such as the trailing EOF token.
This commit is contained in:
parent
fa8a707c7f
commit
363d08ed0d
@ -16,12 +16,13 @@ type File struct {
|
||||
Name string
|
||||
SrcBytes []byte
|
||||
|
||||
Body *Body
|
||||
Body *Body
|
||||
AllTokens *TokenSeq
|
||||
}
|
||||
|
||||
// WriteTo writes the tokens underlying the receiving file to the given writer.
|
||||
func (f *File) WriteTo(wr io.Writer) (int, error) {
|
||||
return f.Body.AllTokens.WriteTo(wr)
|
||||
return f.AllTokens.WriteTo(wr)
|
||||
}
|
||||
|
||||
// Bytes returns a buffer containing the source code resulting from the
|
||||
|
@ -48,15 +48,18 @@ func parse(src []byte, filename string, start zcl.Pos) (*File, zcl.Diagnostics)
|
||||
writerTokens: writerTokens,
|
||||
}
|
||||
|
||||
// we ignore "before" and "after" at the root, because the root body covers
|
||||
// the entire input.
|
||||
_, root, _ := parseBody(file.Body.(*zclsyntax.Body), from)
|
||||
before, root, after := parseBody(file.Body.(*zclsyntax.Body), from)
|
||||
|
||||
return &File{
|
||||
Name: filename,
|
||||
SrcBytes: src,
|
||||
|
||||
Body: root,
|
||||
AllTokens: &TokenSeq{
|
||||
before.Seq(),
|
||||
root.AllTokens,
|
||||
after.Seq(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user