diff --git a/parser/src/char_traits.rs b/parser/src/char_traits.rs index 4a08da1..2cb5d8d 100644 --- a/parser/src/char_traits.rs +++ b/parser/src/char_traits.rs @@ -2,25 +2,29 @@ /// Check whether the character is nil (`\0`). #[inline] -pub(crate) fn is_z(c: char) -> bool { +#[must_use] +pub fn is_z(c: char) -> bool { c == '\0' } /// Check whether the character is a line break (`\r` or `\n`). #[inline] -pub(crate) fn is_break(c: char) -> bool { +#[must_use] +pub fn is_break(c: char) -> bool { c == '\n' || c == '\r' } /// Check whether the character is nil or a line break (`\0`, `\r`, `\n`). #[inline] -pub(crate) fn is_breakz(c: char) -> bool { +#[must_use] +pub fn is_breakz(c: char) -> bool { is_break(c) || is_z(c) } /// Check whether the character is a whitespace (` ` or `\t`). #[inline] -pub(crate) fn is_blank(c: char) -> bool { +#[must_use] +pub fn is_blank(c: char) -> bool { c == ' ' || c == '\t' } @@ -28,31 +32,36 @@ pub(crate) fn is_blank(c: char) -> bool { /// /// `\0`, ` `, `\t`, `\n`, `\r` #[inline] -pub(crate) fn is_blank_or_breakz(c: char) -> bool { +#[must_use] +pub fn is_blank_or_breakz(c: char) -> bool { is_blank(c) || is_breakz(c) } /// Check whether the character is an ascii digit. #[inline] -pub(crate) fn is_digit(c: char) -> bool { +#[must_use] +pub fn is_digit(c: char) -> bool { c.is_ascii_digit() } /// Check whether the character is a digit, letter, `_` or `-`. #[inline] -pub(crate) fn is_alpha(c: char) -> bool { +#[must_use] +pub fn is_alpha(c: char) -> bool { matches!(c, '0'..='9' | 'a'..='z' | 'A'..='Z' | '_' | '-') } /// Check whether the character is a hexadecimal character (case insensitive). #[inline] -pub(crate) fn is_hex(c: char) -> bool { +#[must_use] +pub fn is_hex(c: char) -> bool { c.is_ascii_digit() || ('a'..='f').contains(&c) || ('A'..='F').contains(&c) } /// Convert the hexadecimal digit to an integer. #[inline] -pub(crate) fn as_hex(c: char) -> u32 { +#[must_use] +pub fn as_hex(c: char) -> u32 { match c { '0'..='9' => (c as u32) - ('0' as u32), 'a'..='f' => (c as u32) - ('a' as u32) + 10, @@ -63,49 +72,57 @@ pub(crate) fn as_hex(c: char) -> u32 { /// Check whether the character is a YAML flow character (one of `,[]{}`). #[inline] -pub(crate) fn is_flow(c: char) -> bool { +#[must_use] +pub fn is_flow(c: char) -> bool { matches!(c, ',' | '[' | ']' | '{' | '}') } /// Check whether the character is the BOM character. #[inline] -pub(crate) fn is_bom(c: char) -> bool { +#[must_use] +pub fn is_bom(c: char) -> bool { c == '\u{FEFF}' } /// Check whether the character is a YAML non-breaking character. #[inline] -pub(crate) fn is_yaml_non_break(c: char) -> bool { +#[must_use] +pub fn is_yaml_non_break(c: char) -> bool { // TODO(ethiraric, 28/12/2023): is_printable !is_break(c) && !is_bom(c) } /// Check whether the character is NOT a YAML whitespace (` ` / `\t`). #[inline] -pub(crate) fn is_yaml_non_space(c: char) -> bool { +#[must_use] +pub fn is_yaml_non_space(c: char) -> bool { is_yaml_non_break(c) && !is_blank(c) } /// Check whether the character is a valid YAML anchor name character. #[inline] -pub(crate) fn is_anchor_char(c: char) -> bool { +#[must_use] +pub fn is_anchor_char(c: char) -> bool { is_yaml_non_space(c) && !is_flow(c) && !is_z(c) } /// Check whether the character is a valid word character. #[inline] -pub(crate) fn is_word_char(c: char) -> bool { +#[must_use] +pub fn is_word_char(c: char) -> bool { is_alpha(c) && c != '_' } /// Check whether the character is a valid URI character. #[inline] -pub(crate) fn is_uri_char(c: char) -> bool { +#[must_use] +pub fn is_uri_char(c: char) -> bool { is_word_char(c) || "#;/?:@&=+$,_.!~*\'()[]%".contains(c) } /// Check whether the character is a valid tag character. #[inline] -pub(crate) fn is_tag_char(c: char) -> bool { +#[must_use] +pub fn is_tag_char(c: char) -> bool { is_uri_char(c) && !is_flow(c) && c != '!' } diff --git a/parser/src/input.rs b/parser/src/input.rs index 13c309c..d2b3e7c 100644 --- a/parser/src/input.rs +++ b/parser/src/input.rs @@ -1,10 +1,15 @@ -pub mod buffered; -pub mod str; +//! Utilities to create a source of input to the parser. +//! +//! [`Input`] must be implemented for the parser to fetch input. Make sure your needs aren't +//! covered by the [`BufferedInput`]. + +pub(crate) mod buffered; +pub(crate) mod str; #[allow(clippy::module_name_repetitions)] pub use buffered::BufferedInput; -use crate::char_traits::{ +pub use crate::char_traits::{ is_alpha, is_blank, is_blank_or_breakz, is_break, is_breakz, is_digit, is_flow, is_z, }; @@ -440,6 +445,7 @@ impl SkipTabs { /// Whether tabs were found while skipping whitespace. /// /// This function must be called after a call to `skip_ws_to_eol`. + #[must_use] pub fn found_tabs(self) -> bool { matches!(self, SkipTabs::Result(true, _)) } @@ -447,6 +453,7 @@ impl SkipTabs { /// Whether a valid YAML whitespace has been found in skipped-over content. /// /// This function must be called after a call to `skip_ws_to_eol`. + #[must_use] pub fn has_valid_yaml_ws(self) -> bool { matches!(self, SkipTabs::Result(_, true)) } diff --git a/parser/src/lib.rs b/parser/src/lib.rs index ae81d45..6ad94d1 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -35,7 +35,7 @@ mod char_traits; #[macro_use] mod debug; -mod input; +pub mod input; mod parser; mod scanner;