From 3ee9223bb476e664f37079e4024a826f9b8703ca Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Fri, 4 Mar 2022 18:12:31 +0800 Subject: [PATCH] x/json2: add missing docs --- vlib/x/json2/decoder.v | 8 ++++++++ vlib/x/json2/scanner.v | 1 + 2 files changed, 9 insertions(+) diff --git a/vlib/x/json2/decoder.v b/vlib/x/json2/decoder.v index b77f26a7d9..a66b0da2be 100644 --- a/vlib/x/json2/decoder.v +++ b/vlib/x/json2/decoder.v @@ -19,6 +19,7 @@ pub enum ValueKind { number } +// str returns the string representation of the specific ValueKind pub fn (k ValueKind) str() string { return match k { .unknown { 'unknown' } @@ -39,10 +40,13 @@ pub struct DecodeError { message string } + +// code returns the error code of DecodeError pub fn (err DecodeError) code() int { return 3 } +// msg returns the message of the DecodeError pub fn (err DecodeError) msg() string { return format_message(err.message, err.line, err.column) } @@ -53,10 +57,12 @@ pub struct InvalidTokenError { expected TokenKind } +// code returns the error code of the InvalidTokenError pub fn (err InvalidTokenError) code() int { return 2 } +// msg returns the message of the InvalidTokenError pub fn (err InvalidTokenError) msg() string { footer_text := if err.expected != .none_ { ', expecting `$err.expected`' } else { '' } return format_message('invalid token `$err.token.kind`$footer_text', err.token.line, @@ -69,10 +75,12 @@ pub struct UnknownTokenError { kind ValueKind = .unknown } +// code returns the error code of the UnknownTokenError pub fn (err UnknownTokenError) code() int { return 1 } +// msg returns the error message of the UnknownTokenError pub fn (err UnknownTokenError) msg() string { return format_message("unknown token '$err.token.lit' when decoding ${err.kind}.", err.token.line, err.token.full_col()) diff --git a/vlib/x/json2/scanner.v b/vlib/x/json2/scanner.v index 3ad59797d4..8840fbf844 100644 --- a/vlib/x/json2/scanner.v +++ b/vlib/x/json2/scanner.v @@ -37,6 +37,7 @@ pub struct Token { col int } +// full_col returns the full column information which includes the length pub fn (t Token) full_col() int { return t.col + t.lit.len }