Documentation
¶
Overview ¶
Package tree is the boundary between a file's syntax and everything that reads it. Each syntax front (YAML and HOCON) fills a Node, and the format check and the decoder read only Nodes, so nothing after this package knows which syntax a file used.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Absolute ¶
Absolute is the path two spellings of one file share, so ./a.yaml and a.yaml are one file: the includes' set of files seen compares paths by it, and the command line's rule that no output names an input starts from it for an output that is not there yet. It falls back to the cleaned path when the working directory cannot be read, so two relative paths still compare by their text.
func Beside ¶
Beside returns the path a name written in file reads: a relative name from file's own directory, so the same file reads the same files from any working directory, and an absolute one as written, because joining it under that directory would name a file that is not the one written. HOCON reads an include's name so, and render reads the origins file and each rpc.proto root a proxyfile names the same way, so every file a proxyfile names is found by one rule.
Types ¶
type Entry ¶
Entry carries the key's own position so that a problem with the key, such as an unknown key, points at the key, and a problem with the value points at the value.
type Node ¶
type Node struct {
Kind Kind
Text string
// Quoted is true for a scalar a YAML reader takes as text whatever it holds: one written in quotes, or as a
// literal or folded block. The format check refuses one where a number or a boolean is expected, because the JSON
// Schema an editor checks the file with refuses text there. The HOCON front sets it for every HOCON string, quoted
// or not, because HOCON types unquoted text as a string.
Quoted bool
// NumberOrBool is true for a plain scalar go-yaml takes as a number or a boolean, such as 404, 1.5 or true. The
// format check refuses one where text is expected, because the JSON Schema refuses a number or a boolean there; the
// origins and methods files follow the same rule, because one checker serves all three files. go-yaml also takes
// some YAML 1.1 spellings as numbers (1_000, 0b1, 0X1F) that YAML 1.2's core schema reads as text, so an editor
// reading YAML 1.2 accepts them as text where the check refuses them: there the check is the stricter side. The
// HOCON front sets it for every HOCON number and boolean.
NumberOrBool bool
Items []*Node
Entries []Entry
Pos model.Pos
}
Node is a value of either syntax: a scalar is its text without the quotes (a YAML null is ""), a map keeps its entries in written order.
func FromHOCON ¶
FromHOCON reads the HOCON file at path into the tree the YAML front builds for the same gateway, so every check after the tree reads one form, and returns the files its include statements name, which are inputs of the run as much as the file at path. It returns either the root and the files or the problems, never both, as FromYAML does. It takes the path, not the bytes, because the library reads an include relative to the including file only when it opens that file.
The files are found in the text, before the library parses, because the library opens the included files itself and does not say which (resolveInclude and loadIncludeFile, o3co internal/resolver/resolver.go:1615 and 1747, read with os.ReadFile at 1769). The same scan refuses include file(...) before the library opens anything, because the library reads a relative name inside file(...) from the working directory, not beside the including file (resolver.go:1628-1641), so one proxyfile would read different files from different directories.
func FromJSON ¶
FromJSON reads a JSON file with the YAML front, which reads JSON as YAML's flow form, with the two escapes of JSON that go-yaml refuses read first. JSON writes a slash in a string as / or \/ (RFC 8259, section 7), and go-yaml refuses \/ (found unknown escape character), though YAML 1.2 defines it for JSON's sake (YAML 1.2.2, section 5.7), because go-yaml follows YAML 1.1 there. JSON writes a character outside the Basic Multilingual Plane as two \u escapes, a high surrogate and a low one (RFC 8259, section 7), as Python's json.dumps does by default, and go-yaml refuses every escape from D800 to DFFF (found invalid Unicode character escape code).
func FromYAML ¶
FromYAML returns either the root or the problems, never both, so no caller can read a tree with a value left out of it.
func (*Node) Entry ¶
Entry is Get for a reader that also needs the key's position, such as a problem that names the key.