Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader provides services to objects that parse streams.
Example ¶
r := NewReader(strings.NewReader(`a{} a{b{c: "value"}}`))
var parse func(r *Reader)
parse = func(r *Reader) {
for r.Next() {
switch r.Kind() {
case Field:
fmt.Println(r.Name(), r.StringField())
case Record:
name := r.Name()
fmt.Println("record", name)
parse(r.Record())
fmt.Println("end", name)
}
}
}
parse(r)
Output: record a end a record a record b c value end b end a
func (*Reader) BoolField ¶
BoolField reads a field and interprets it as a boolean. If the current section is not a field containing a boolean then an error is signalled.
func (*Reader) ExpectEOF ¶
func (p *Reader) ExpectEOF()
ExpectEOF asserts that the entire file was parsed.
func (*Reader) IntField ¶
IntField reads a field and interprets it as an integer. If the current section is not a field containing an integer then an error is signalled.
func (*Reader) Kind ¶
Kind gives the kind of the section under consideration, either Field or Record. If it returns anything other than one of these values, the reader is in a bad state and it would be unwise to continue parsing.
func (*Reader) Name ¶
Name gives the name of the current section under consideration. Note that if Kind() does not return Field or Value then this value is undefined.
func (*Reader) Next ¶
Next moves to the next named section (field or record) of the input. It returns whether progress can be made by a consumer.
If Next is called twice without a call to either a Field() method or the Record() method in between then an error is signalled and the second Next() returns false.
func (*Reader) Record ¶
Record uses the provided parser to parse a record. An error will be signalled if the current section is not a record.
func (*Reader) StringField ¶
StringField reads a field and interprets it as a string. If the current section is not a field then an error is signalled.
type Writer ¶
type Writer struct {
Indent, LineEnd string
// contains filtered or unexported fields
}