src/encoding/json/jsontext/decode.go | 12 +++++++----- src/encoding/json/jsontext/doc.go | 10 +++++----- src/encoding/json/jsontext/encode.go | 10 +++++----- src/encoding/json/jsontext/errors.go | 2 +- src/encoding/json/jsontext/options.go | 6 +++--- src/encoding/json/jsontext/state.go | 8 ++++---- src/encoding/json/jsontext/token.go | 8 ++++---- src/encoding/json/jsontext/value.go | 18 +++++++----------- diff --git a/src/encoding/json/jsontext/decode.go b/src/encoding/json/jsontext/decode.go index 0e1ff4b185b914b930d22ce9cf9f9fb555bacc74..4402cae523e6586dd012c5c2243f4878d77d85e9 100644 --- a/src/encoding/json/jsontext/decode.go +++ b/src/encoding/json/jsontext/decode.go @@ -409,10 +409,11 @@ return wrapSyntacticError(d, err, pos, 0) } // SkipValue is semantically equivalent to calling [Decoder.ReadValue] and discarding -// the result except that memory is not wasted trying to hold the entire result. +// the result, except that memory is not wasted trying to hold the entire result. func (d *Decoder) SkipValue() error { return d.s.SkipValue() } + func (d *decoderState) SkipValue() error { switch d.PeekKind() { case '{', '[': @@ -1131,7 +1132,7 @@ // InputOffset returns the current input byte offset. It gives the location // of the next byte immediately after the most recently returned token or value. // The number of bytes actually read from the underlying [io.Reader] may be more -// than this offset due to internal buffering effects. +// than this offset due to internal buffering. func (d *Decoder) InputOffset() int64 { return d.s.previousOffsetEnd() } @@ -1140,7 +1141,7 @@ // UnreadBuffer returns the data remaining in the unread buffer, // which may contain zero or more bytes. // This is the data already consumed from the input [io.Reader], // but not yet read by a [Decoder.ReadToken] or [Decoder.ReadValue] call. -// It may contain bytes that do not form valid JSON as it has not yet +// It may contain bytes that do not form valid JSON, since it has not yet // been validated according to the JSON grammar. // The exact amount of buffered data is an implementation detail // of the Decoder and may change over time. @@ -1155,7 +1156,8 @@ func (d *Decoder) UnreadBuffer() []byte { return d.s.unreadBuffer() } -// StackDepth returns the depth of the state machine for read JSON data. +// StackDepth returns the depth of the state machine for JSON data +// that has already been read. // Each level on the stack represents a nested JSON object or array. // It is incremented whenever a [BeginObject] or [BeginArray] token is encountered // and decremented whenever an [EndObject] or [EndArray] token is encountered. @@ -1193,7 +1195,7 @@ // - [KindBeginArray] for a level representing a JSON array. // // It also reports the length of that JSON object or array decoded so far. // Each name and value in a JSON object is counted separately, -// so the effective number of members would be half the length. +// so the effective number of members is half the length. // A complete JSON object must have an even length. func (d *Decoder) StackIndex(i int) (Kind, int64) { // NOTE: Keep in sync with Encoder.StackIndex. diff --git a/src/encoding/json/jsontext/doc.go b/src/encoding/json/jsontext/doc.go index fc53cf0bfe8e73cb5ca28c27cf5b52fee8038121..1364e69d7d02ab3b5fc86887c3f68ee9398175ca 100644 --- a/src/encoding/json/jsontext/doc.go +++ b/src/encoding/json/jsontext/doc.go @@ -43,18 +43,18 @@ // However, only a value can represent the entirety of a JSON object or array. // // The [Encoder] and [Decoder] types contain methods to read or write the next // [Token] or [Value] in a sequence. They maintain a state machine to validate -// whether the sequence of JSON tokens and/or values produces a valid JSON. +// whether the sequence of JSON tokens and/or values produces valid JSON. // [Options] may be passed to the [NewEncoder] or [NewDecoder] constructors -// to configure the syntactic behavior of encoding and decoding. +// to configure the behavior of encoding and decoding. // // # Terminology // // The terms "encode" and "decode" are used for syntactic functionality // that is concerned with processing JSON based on its grammar, and // the terms "marshal" and "unmarshal" are used for semantic functionality -// that determines the meaning of JSON values as Go values and vice-versa. -// This package (i.e., [jsontext]) deals with JSON at a syntactic layer, -// while [encoding/json/v2] deals with JSON at a semantic layer. +// that determines the meaning of JSON values as Go values and vice versa. +// This package deals with JSON syntax, +// while [encoding/json/v2] deals with JSON semantics. // The goal is to provide a clear distinction between functionality that // is purely concerned with encoding versus that of marshaling. // For example, one can directly encode a stream of JSON tokens without diff --git a/src/encoding/json/jsontext/encode.go b/src/encoding/json/jsontext/encode.go index 047b00a1c11e1540f59b7893f014d519de0c9324..0fa7e800605a3f276bca4303f43413c8b6d28922 100644 --- a/src/encoding/json/jsontext/encode.go +++ b/src/encoding/json/jsontext/encode.go @@ -16,7 +16,7 @@ "encoding/json/internal/jsonopts" "encoding/json/internal/jsonwire" ) -// Encoder is a streaming encoder from raw JSON tokens and values. +// Encoder is a streaming encoder to raw JSON tokens and values. // It is used to write a stream of top-level JSON values, // each terminated with a newline character. // @@ -337,7 +337,7 @@ // The provided token kind must be consistent with the JSON grammar. // For example, it is an error to provide a number when the encoder // is expecting an object name (which is always a string), or // to provide an end object delimiter when the encoder is finishing an array. -// If the provided token is invalid, then it reports a [SyntacticError] and +// If the provided token is invalid, then WriteToken reports a [SyntacticError] and // the internal state remains unchanged. The offset reported // in [SyntacticError] will be the [Encoder.OutputOffset] plus any delimiter // or whitespace characters that would have preceded the provided token. @@ -518,7 +518,7 @@ // as the Unicode replacement character, U+FFFD. // // The provided value kind must be consistent with the JSON grammar // (see examples on [Encoder.WriteToken]). If the provided value is invalid, -// then it reports a [SyntacticError] and the internal state remains unchanged. +// then WriteValue reports a [SyntacticError] and the internal state remains unchanged. // The offset reported in [SyntacticError] will be the [Encoder.OutputOffset] // plus the offset into v of any encountered syntax error. func (e *Encoder) WriteValue(v Value) error { @@ -896,7 +896,7 @@ // OutputOffset returns the current output byte offset. It gives the location // of the next byte immediately after the most recently written token or value. // The number of bytes actually written to the underlying [io.Writer] may be less -// than this offset due to internal buffering effects. +// than this offset due to internal buffering. func (e *Encoder) OutputOffset() int64 { return e.s.previousOffsetEnd() } @@ -968,7 +968,7 @@ // - [KindBeginArray] for a level representing a JSON array. // // It also reports the length of that JSON object or array encoded so far. // Each name and value in a JSON object is counted separately, -// so the effective number of members would be half the length. +// so the effective number of members is half the length. // A complete JSON object must have an even length. func (e *Encoder) StackIndex(i int) (Kind, int64) { // NOTE: Keep in sync with Decoder.StackIndex. diff --git a/src/encoding/json/jsontext/errors.go b/src/encoding/json/jsontext/errors.go index 118b7a30548322fc023686053b51bcb57832944a..b93925413d72c66e25d9cb8ca4e6b2445e63355e 100644 --- a/src/encoding/json/jsontext/errors.go +++ b/src/encoding/json/jsontext/errors.go @@ -43,7 +43,7 @@ func (e *numError) Unwrap() error { return e.err } -// SyntacticError is a description of a syntactic error that occurred when +// SyntacticError is a description of an error that occurred when // encoding or decoding JSON according to the grammar. // // The contents of this error as produced by this package may change over time. diff --git a/src/encoding/json/jsontext/options.go b/src/encoding/json/jsontext/options.go index fd2f54f13167e79ca1ba8ffdeb25e3cc622d554d..14ef4d6ac1aadb9197d6412d7ad337207d479115 100644 --- a/src/encoding/json/jsontext/options.go +++ b/src/encoding/json/jsontext/options.go @@ -205,7 +205,7 @@ // If [SpaceAfterColon] is not specified, then the default is true. // If [SpaceAfterComma] is not specified, then the default is false. // If [WithIndent] is not specified, then the default is "\t". // -// If set to false, then the output is a single-line, +// If set to false, then the output is a single line, // where the only whitespace emitted is determined by the current // values of [SpaceAfterColon] and [SpaceAfterComma]. // @@ -222,7 +222,7 @@ // WithIndent specifies that the encoder should emit multiline output // where each element in a JSON object or array begins on a new, indented line // beginning with the indent prefix (see [WithIndentPrefix]) // followed by one or more copies of indent according to the nesting depth. -// The indent must only be composed of space or tab characters. +// The indent must be composed of only space and tab characters. // // If the intent is to emit indented output without a preference for // the particular indent string, then use [Multiline] instead. @@ -258,7 +258,7 @@ // WithIndentPrefix specifies that the encoder should emit multiline output // where each element in a JSON object or array begins on a new, indented line // beginning with the indent prefix followed by one or more copies of indent // (see [WithIndent]) according to the nesting depth. -// The prefix must only be composed of space or tab characters. +// The prefix must be composed of only space and tab characters. // // This only affects encoding and is ignored when decoding. // Use of this option implies [Multiline] being set to true. diff --git a/src/encoding/json/jsontext/state.go b/src/encoding/json/jsontext/state.go index a6c42bff18fa7b4e97163ab6366676753e442b51..c605d2d994ce3772e19669ba5d98a0c541d43bed 100644 --- a/src/encoding/json/jsontext/state.go +++ b/src/encoding/json/jsontext/state.go @@ -91,7 +91,7 @@ // the structure of the top-level JSON value that the pointer refers to. // // There is exactly one representation of a pointer to a particular value, // so comparability of Pointer values is equivalent to checking whether -// they both point to the exact same value. +// they both point to the same value. type Pointer string // IsValid reports whether p is a valid JSON Pointer according to RFC 6901. @@ -117,13 +117,13 @@ return ok && (suffix == "" || suffix[0] == '/') } // Parent strips off the last token and returns the remaining pointer. -// The parent of an empty p is an empty string. +// The parent of an empty Pointer is the empty string. func (p Pointer) Parent() Pointer { return p[:max(strings.LastIndexByte(string(p), '/'), 0)] } // LastToken returns the last token in the pointer. -// The last token of an empty p is an empty string. +// The last token of an empty Pointer is the empty string. func (p Pointer) LastToken() string { last := p[max(strings.LastIndexByte(string(p), '/'), 0):] return unescapePointerToken(strings.TrimPrefix(string(last), "/")) @@ -138,7 +138,7 @@ // TODO: Add Pointer.AppendTokens, // but should this take in a ...string or an iter.Seq[string]? // Tokens returns an iterator over the reference tokens in the JSON pointer, -// starting from the first token until the last token (unless stopped early). +// from first to last. func (p Pointer) Tokens() iter.Seq[string] { return func(yield func(string) bool) { for len(p) > 0 { diff --git a/src/encoding/json/jsontext/token.go b/src/encoding/json/jsontext/token.go index bad2bc21a67a5fc764cdf19522cd319b5cd4e490..d7e43466a8dd3b64b46a677dac452286743767f3 100644 --- a/src/encoding/json/jsontext/token.go +++ b/src/encoding/json/jsontext/token.go @@ -619,9 +619,9 @@ } // A Kind represents the kind of a JSON token. // -// Kind represents each possible JSON token kind with a single byte, -// which is conveniently the first byte of that kind's grammar -// with the restriction that numbers always be represented with '0'. +// A Kind is a single byte, which is conveniently the first byte of that +// kind's symbol in the grammar (except for numbers, which are always represented +// with '0'). type Kind byte const ( @@ -639,7 +639,7 @@ ) const invalidKind Kind = 0 -// String prints the kind in a humanly readable fashion. +// String returns a string representation of k. func (k Kind) String() string { switch k { case 0: diff --git a/src/encoding/json/jsontext/value.go b/src/encoding/json/jsontext/value.go index daed27e1ddc3f7f9a4343e35a77efc083f1615ad..40a4f793f308a272d8b31e7905a7dcd566b23a59 100644 --- a/src/encoding/json/jsontext/value.go +++ b/src/encoding/json/jsontext/value.go @@ -152,7 +152,7 @@ // Compact removes all whitespace from the raw JSON value. // // It does not reformat JSON strings or numbers to use any other representation. // To maximize the set of JSON values that can be formatted, -// this permits values with duplicate names and invalid UTF-8. +// it permits values with duplicate names and invalid UTF-8. // // Compact is equivalent to calling [Value.Format] with the following options: // - [AllowDuplicateNames](true) @@ -174,7 +174,7 @@ // in a JSON object or array begins on an indented line according to the nesting. // // It does not reformat JSON strings or numbers to use any other representation. // To maximize the set of JSON values that can be formatted, -// this permits values with duplicate names and invalid UTF-8. +// it permits values with duplicate names and invalid UTF-8. // // Indent is equivalent to calling [Value.Format] with the following options: // - [AllowDuplicateNames](true) @@ -194,20 +194,16 @@ }, opts) } // Canonicalize canonicalizes the raw JSON value according to the -// JSON Canonicalization Scheme (JCS) as defined by RFC 8785 -// where it produces a stable representation of a JSON value. +// JSON Canonicalization Scheme (JCS) as defined by RFC 8785. +// Canonicalization produces a JSON value with the same meaning as the original, +// but is stable in the sense that calling Canonicalize on a canonicalized +// value does nothing. // // JSON strings are formatted to use their minimal representation, // JSON numbers are formatted as double precision numbers according // to some stable serialization algorithm. // JSON object members are sorted in ascending order by name. // All whitespace is removed. -// -// The output stability is dependent on the stability of the application data -// (see RFC 8785, Appendix E). It cannot produce stable output from -// fundamentally unstable input. For example, if the JSON value -// contains ephemeral data (e.g., a frequently changing timestamp), -// then the value is still unstable regardless of whether this is called. // // Canonicalize is equivalent to calling [Value.Format] with the following options: // - [CanonicalizeRawInts](true) @@ -233,7 +229,7 @@ }, opts) } // MarshalJSON returns v as the JSON encoding of v. -// It returns the stored value as the raw JSON output without any validation. +// It performs no validation. // If v is nil, then this returns a JSON null. func (v Value) MarshalJSON() ([]byte, error) { // NOTE: This matches the behavior of v1 json.RawMessage.MarshalJSON.