Check edited values, keep comments in place and make edits cheap
- Header.Set, Document.SetDefine and Document.AddHeader return an error for a value or name that can't be written as one opcode, define or header, and Build returns the same error for what it can't write. - Set puts a new opcode after the last one's trailing comment, and never where text on its line would become part of its value. Delete keeps the line breaks it doesn't own. - Node.Line and Node.Col are replaced by File.Position, which works lines and columns out when asked, and a node remembers where it was in its file, so an edit no longer renumbers the file or searches it from the start. - Add FuzzEdit checks that an edited file reads back as its nodes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+8
-2
@@ -79,13 +79,17 @@ type Node struct {
|
||||
// Value is an opcode's or a define's value without surrounding
|
||||
// whitespace, or an include's path as written.
|
||||
Value string
|
||||
// Line and Col are where the node starts, from 1, with Col in bytes.
|
||||
Line, Col int
|
||||
// Resolved is an include's path with its variables substituted, with
|
||||
// forward slashes, relative to the folder of the main file.
|
||||
Resolved string
|
||||
// File is the file an include reads, or nil if it wasn't read.
|
||||
File *File
|
||||
// line and col are where the node starts, from 1, with col in bytes, as of
|
||||
// the last time the file's positions were worked out (see [File.Position]).
|
||||
line, col int
|
||||
// idx is where the node was in its file's nodes the last time it was
|
||||
// looked for, which stays close to where it is.
|
||||
idx int
|
||||
}
|
||||
|
||||
// File is one file of a document: the main file or an included one.
|
||||
@@ -94,6 +98,8 @@ type File struct {
|
||||
// forward slashes. For a file read with [Parse] and no name, it is empty.
|
||||
Path string
|
||||
Nodes []*Node
|
||||
// dirty is whether edits have left the nodes' lines and columns out of date.
|
||||
dirty bool
|
||||
}
|
||||
|
||||
// String returns the file's text.
|
||||
|
||||
Reference in New Issue
Block a user