From a5148c7ccf3d68b7fe49166ec2f1d57aa0c5e4ca Mon Sep 17 00:00:00 2001 From: Walter Schulze Date: Fri, 24 Jan 2025 10:00:20 +0000 Subject: [PATCH] add comments to parser interface --- parser/parser.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index ee2bff8..b5cd534 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -12,33 +12,44 @@ // See the License for the specific language governing permissions and // limitations under the License. -//Package parser represents the parser.Interface and some errors for implementing parsers. +// Package parser represents the parser.Interface and some errors for implementing parsers. package parser import "fmt" -//A type conforming to the parser.Interface interface, abstracts away the implementation details of a parser. +// A type conforming to the parser.Interface interface, abstracts away the implementation details of a parser. type Interface interface { + // Next skips to the next field or item in an array Next() error + // IsLeaf is true if this is a value and you cannot traverse down anymore IsLeaf() bool - Up() + // Down traverses down into a field value, which could be another message or array. Next must always be called after Down. Down() + // Up traverses up out of a field value and back to the field's next sibling. Next must always be called after Up. + Up() + // Value is a collection of possible values that the field might have. Value } -//A type confirming to the parser.Value interface, repesents one native value, tree node label (field name) or some repesentation a node label. -//Typically only one of the methods returns a value without an error, but more than one method can return without an error. -//For example a positive json number can return an errorless value for the Double, Int and Uint methods. +// A type confirming to the parser.Value interface, repesents one native value, tree node label (field name) or some repesentation a node label. +// Typically only one of the methods returns a value without an error, but more than one method can return without an error. +// For example a positive json number can return an errorless value for the Double, Int and Uint methods. type Value interface { + // String returns the string value if it is a string type or an error if it is not a string. + String() (string, error) + // Double returns the float64 value if it is a double type or an error if it is not a double. Double() (float64, error) + // Int returns the int64 value if it is an integer type or an error if it is not an integer. Int() (int64, error) + // Uint returns the uint64 value if it is an unsinged integer type or an error if it is not an unsinged integer. Uint() (uint64, error) + // Bool returns the bool value if it is a boolean type or an error if it is not a boolean. Bool() (bool, error) - String() (string, error) + // Bytes returns a byte slice value if it is a bytes type or an error if it is not bytes. Bytes() ([]byte, error) } -//Sprint returns a value printed as a string. +// Sprint returns a value printed as a string. func Sprint(value Value) string { return fmt.Sprintf("%#v", getValue(value)) }