summaryrefslogtreecommitdiffstats
path: root/vendor/toml_edit/src/parser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/toml_edit/src/parser
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/toml_edit/src/parser')
-rw-r--r--vendor/toml_edit/src/parser/array.rs2
-rw-r--r--vendor/toml_edit/src/parser/datetime.rs4
-rw-r--r--vendor/toml_edit/src/parser/error.rs87
-rw-r--r--vendor/toml_edit/src/parser/errors.rs315
-rw-r--r--vendor/toml_edit/src/parser/inline_table.rs4
-rw-r--r--vendor/toml_edit/src/parser/key.rs4
-rw-r--r--vendor/toml_edit/src/parser/mod.rs14
-rw-r--r--vendor/toml_edit/src/parser/numbers.rs2
-rw-r--r--vendor/toml_edit/src/parser/state.rs2
-rw-r--r--vendor/toml_edit/src/parser/strings.rs4
-rw-r--r--vendor/toml_edit/src/parser/trivia.rs2
-rw-r--r--vendor/toml_edit/src/parser/value.rs2
12 files changed, 116 insertions, 326 deletions
diff --git a/vendor/toml_edit/src/parser/array.rs b/vendor/toml_edit/src/parser/array.rs
index e3b1f3f52..078319193 100644
--- a/vendor/toml_edit/src/parser/array.rs
+++ b/vendor/toml_edit/src/parser/array.rs
@@ -81,6 +81,8 @@ pub(crate) fn array_value<'i>(
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/datetime.rs b/vendor/toml_edit/src/parser/datetime.rs
index 96a3854d4..945dc6935 100644
--- a/vendor/toml_edit/src/parser/datetime.rs
+++ b/vendor/toml_edit/src/parser/datetime.rs
@@ -1,6 +1,6 @@
use std::ops::RangeInclusive;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::prelude::*;
use crate::parser::trivia::from_utf8_unchecked;
@@ -263,6 +263,8 @@ pub(crate) fn unsigned_digits<'i, const MIN: usize, const MAX: usize>(
const DIGIT: RangeInclusive<u8> = b'0'..=b'9';
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/error.rs b/vendor/toml_edit/src/parser/error.rs
new file mode 100644
index 000000000..22e8e6626
--- /dev/null
+++ b/vendor/toml_edit/src/parser/error.rs
@@ -0,0 +1,87 @@
+use std::error::Error as StdError;
+use std::fmt::{Display, Formatter, Result};
+
+use crate::Key;
+
+#[derive(Debug, Clone)]
+pub(crate) enum CustomError {
+ DuplicateKey {
+ key: String,
+ table: Option<Vec<Key>>,
+ },
+ DottedKeyExtendWrongType {
+ key: Vec<Key>,
+ actual: &'static str,
+ },
+ OutOfRange,
+ #[cfg_attr(feature = "unbounded", allow(dead_code))]
+ RecursionLimitExceeded,
+}
+
+impl CustomError {
+ pub(crate) fn duplicate_key(path: &[Key], i: usize) -> Self {
+ assert!(i < path.len());
+ let key = &path[i];
+ let repr = key
+ .as_repr()
+ .and_then(|key| key.as_raw().as_str())
+ .map(|s| s.to_owned())
+ .unwrap_or_else(|| {
+ #[cfg(feature = "display")]
+ {
+ key.default_repr().as_raw().as_str().unwrap().to_owned()
+ }
+ #[cfg(not(feature = "display"))]
+ {
+ format!("{:?}", key.get())
+ }
+ });
+ Self::DuplicateKey {
+ key: repr,
+ table: Some(path[..i].to_vec()),
+ }
+ }
+
+ pub(crate) fn extend_wrong_type(path: &[Key], i: usize, actual: &'static str) -> Self {
+ assert!(i < path.len());
+ Self::DottedKeyExtendWrongType {
+ key: path[..=i].to_vec(),
+ actual,
+ }
+ }
+}
+
+impl StdError for CustomError {
+ fn description(&self) -> &'static str {
+ "TOML parse error"
+ }
+}
+
+impl Display for CustomError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+ match self {
+ CustomError::DuplicateKey { key, table } => {
+ if let Some(table) = table {
+ if table.is_empty() {
+ write!(f, "duplicate key `{}` in document root", key)
+ } else {
+ let path = table.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
+ write!(f, "duplicate key `{}` in table `{}`", key, path)
+ }
+ } else {
+ write!(f, "duplicate key `{}`", key)
+ }
+ }
+ CustomError::DottedKeyExtendWrongType { key, actual } => {
+ let path = key.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
+ write!(
+ f,
+ "dotted key `{}` attempted to extend non-table type ({})",
+ path, actual
+ )
+ }
+ CustomError::OutOfRange => write!(f, "value is out of range"),
+ CustomError::RecursionLimitExceeded => write!(f, "recursion limit exceeded"),
+ }
+ }
+}
diff --git a/vendor/toml_edit/src/parser/errors.rs b/vendor/toml_edit/src/parser/errors.rs
deleted file mode 100644
index 685e9f716..000000000
--- a/vendor/toml_edit/src/parser/errors.rs
+++ /dev/null
@@ -1,315 +0,0 @@
-use std::error::Error as StdError;
-use std::fmt::{Display, Formatter, Result};
-
-use crate::parser::prelude::*;
-use crate::Key;
-
-use winnow::error::ContextError;
-use winnow::error::ParseError;
-
-/// Type representing a TOML parse error
-#[derive(Debug, Clone, Eq, PartialEq, Hash)]
-pub struct TomlError {
- message: String,
- original: Option<String>,
- keys: Vec<String>,
- span: Option<std::ops::Range<usize>>,
-}
-
-impl TomlError {
- pub(crate) fn new(error: ParseError<Input<'_>, ContextError>, mut original: Input<'_>) -> Self {
- use winnow::stream::Stream;
-
- let offset = error.offset();
- let span = if offset == original.len() {
- offset..offset
- } else {
- offset..(offset + 1)
- };
-
- let message = error.inner().to_string();
- let original = original.finish();
-
- Self {
- message,
- original: Some(
- String::from_utf8(original.to_owned()).expect("original document was utf8"),
- ),
- keys: Vec::new(),
- span: Some(span),
- }
- }
-
- #[cfg(feature = "serde")]
- pub(crate) fn custom(message: String, span: Option<std::ops::Range<usize>>) -> Self {
- Self {
- message,
- original: None,
- keys: Vec::new(),
- span,
- }
- }
-
- #[cfg(feature = "serde")]
- pub(crate) fn add_key(&mut self, key: String) {
- self.keys.insert(0, key);
- }
-
- /// What went wrong
- pub fn message(&self) -> &str {
- &self.message
- }
-
- /// The start/end index into the original document where the error occurred
- pub fn span(&self) -> Option<std::ops::Range<usize>> {
- self.span.clone()
- }
-
- #[cfg(feature = "serde")]
- pub(crate) fn set_span(&mut self, span: Option<std::ops::Range<usize>>) {
- self.span = span;
- }
-
- #[cfg(feature = "serde")]
- pub(crate) fn set_original(&mut self, original: Option<String>) {
- self.original = original;
- }
-}
-
-/// Displays a TOML parse error
-///
-/// # Example
-///
-/// TOML parse error at line 1, column 10
-/// |
-/// 1 | 00:32:00.a999999
-/// | ^
-/// Unexpected `a`
-/// Expected `digit`
-/// While parsing a Time
-/// While parsing a Date-Time
-impl Display for TomlError {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result {
- let mut context = false;
- if let (Some(original), Some(span)) = (&self.original, self.span()) {
- context = true;
-
- let (line, column) = translate_position(original.as_bytes(), span.start);
- let line_num = line + 1;
- let col_num = column + 1;
- let gutter = line_num.to_string().len();
- let content = original.split('\n').nth(line).expect("valid line number");
-
- writeln!(
- f,
- "TOML parse error at line {}, column {}",
- line_num, col_num
- )?;
- // |
- for _ in 0..=gutter {
- write!(f, " ")?;
- }
- writeln!(f, "|")?;
-
- // 1 | 00:32:00.a999999
- write!(f, "{} | ", line_num)?;
- writeln!(f, "{}", content)?;
-
- // | ^
- for _ in 0..=gutter {
- write!(f, " ")?;
- }
- write!(f, "|")?;
- for _ in 0..=column {
- write!(f, " ")?;
- }
- // The span will be empty at eof, so we need to make sure we always print at least
- // one `^`
- write!(f, "^")?;
- for _ in (span.start + 1)..(span.end.min(span.start + content.len())) {
- write!(f, "^")?;
- }
- writeln!(f)?;
- }
- writeln!(f, "{}", self.message)?;
- if !context && !self.keys.is_empty() {
- writeln!(f, "in `{}`", self.keys.join("."))?;
- }
-
- Ok(())
- }
-}
-
-impl StdError for TomlError {
- fn description(&self) -> &'static str {
- "TOML parse error"
- }
-}
-
-fn translate_position(input: &[u8], index: usize) -> (usize, usize) {
- if input.is_empty() {
- return (0, index);
- }
-
- let safe_index = index.min(input.len() - 1);
- let column_offset = index - safe_index;
- let index = safe_index;
-
- let nl = input[0..index]
- .iter()
- .rev()
- .enumerate()
- .find(|(_, b)| **b == b'\n')
- .map(|(nl, _)| index - nl - 1);
- let line_start = match nl {
- Some(nl) => nl + 1,
- None => 0,
- };
- let line = input[0..line_start].iter().filter(|b| **b == b'\n').count();
-
- let column = std::str::from_utf8(&input[line_start..=index])
- .map(|s| s.chars().count() - 1)
- .unwrap_or_else(|_| index - line_start);
- let column = column + column_offset;
-
- (line, column)
-}
-
-#[cfg(test)]
-mod test_translate_position {
- use super::*;
-
- #[test]
- fn empty() {
- let input = b"";
- let index = 0;
- let position = translate_position(&input[..], index);
- assert_eq!(position, (0, 0));
- }
-
- #[test]
- fn start() {
- let input = b"Hello";
- let index = 0;
- let position = translate_position(&input[..], index);
- assert_eq!(position, (0, 0));
- }
-
- #[test]
- fn end() {
- let input = b"Hello";
- let index = input.len() - 1;
- let position = translate_position(&input[..], index);
- assert_eq!(position, (0, input.len() - 1));
- }
-
- #[test]
- fn after() {
- let input = b"Hello";
- let index = input.len();
- let position = translate_position(&input[..], index);
- assert_eq!(position, (0, input.len()));
- }
-
- #[test]
- fn first_line() {
- let input = b"Hello\nWorld\n";
- let index = 2;
- let position = translate_position(&input[..], index);
- assert_eq!(position, (0, 2));
- }
-
- #[test]
- fn end_of_line() {
- let input = b"Hello\nWorld\n";
- let index = 5;
- let position = translate_position(&input[..], index);
- assert_eq!(position, (0, 5));
- }
-
- #[test]
- fn start_of_second_line() {
- let input = b"Hello\nWorld\n";
- let index = 6;
- let position = translate_position(&input[..], index);
- assert_eq!(position, (1, 0));
- }
-
- #[test]
- fn second_line() {
- let input = b"Hello\nWorld\n";
- let index = 8;
- let position = translate_position(&input[..], index);
- assert_eq!(position, (1, 2));
- }
-}
-
-#[derive(Debug, Clone)]
-pub(crate) enum CustomError {
- DuplicateKey {
- key: String,
- table: Option<Vec<Key>>,
- },
- DottedKeyExtendWrongType {
- key: Vec<Key>,
- actual: &'static str,
- },
- OutOfRange,
- #[cfg_attr(feature = "unbounded", allow(dead_code))]
- RecursionLimitExceeded,
-}
-
-impl CustomError {
- pub(crate) fn duplicate_key(path: &[Key], i: usize) -> Self {
- assert!(i < path.len());
- let key = &path[i];
- let repr = key.display_repr();
- Self::DuplicateKey {
- key: repr.into(),
- table: Some(path[..i].to_vec()),
- }
- }
-
- pub(crate) fn extend_wrong_type(path: &[Key], i: usize, actual: &'static str) -> Self {
- assert!(i < path.len());
- Self::DottedKeyExtendWrongType {
- key: path[..=i].to_vec(),
- actual,
- }
- }
-}
-
-impl StdError for CustomError {
- fn description(&self) -> &'static str {
- "TOML parse error"
- }
-}
-
-impl Display for CustomError {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result {
- match self {
- CustomError::DuplicateKey { key, table } => {
- if let Some(table) = table {
- if table.is_empty() {
- write!(f, "duplicate key `{}` in document root", key)
- } else {
- let path = table.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
- write!(f, "duplicate key `{}` in table `{}`", key, path)
- }
- } else {
- write!(f, "duplicate key `{}`", key)
- }
- }
- CustomError::DottedKeyExtendWrongType { key, actual } => {
- let path = key.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
- write!(
- f,
- "dotted key `{}` attempted to extend non-table type ({})",
- path, actual
- )
- }
- CustomError::OutOfRange => write!(f, "value is out of range"),
- CustomError::RecursionLimitExceeded => write!(f, "recursion limit exceeded"),
- }
- }
-}
diff --git a/vendor/toml_edit/src/parser/inline_table.rs b/vendor/toml_edit/src/parser/inline_table.rs
index f7cf2e9c5..c2e6619a3 100644
--- a/vendor/toml_edit/src/parser/inline_table.rs
+++ b/vendor/toml_edit/src/parser/inline_table.rs
@@ -5,7 +5,7 @@ use winnow::token::one_of;
use winnow::trace::trace;
use crate::key::Key;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::key::key;
use crate::parser::prelude::*;
use crate::parser::trivia::ws;
@@ -165,6 +165,8 @@ fn keyval<'i>(
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/key.rs b/vendor/toml_edit/src/parser/key.rs
index bd8804a23..71b756300 100644
--- a/vendor/toml_edit/src/parser/key.rs
+++ b/vendor/toml_edit/src/parser/key.rs
@@ -7,7 +7,7 @@ use winnow::token::take_while;
use winnow::trace::trace;
use crate::key::Key;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::prelude::*;
use crate::parser::strings::{basic_string, literal_string};
use crate::parser::trivia::{from_utf8_unchecked, ws};
@@ -88,6 +88,8 @@ const UNQUOTED_CHAR: (
const DOT_SEP: u8 = b'.';
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/mod.rs b/vendor/toml_edit/src/parser/mod.rs
index eb4755055..e0322024c 100644
--- a/vendor/toml_edit/src/parser/mod.rs
+++ b/vendor/toml_edit/src/parser/mod.rs
@@ -3,7 +3,7 @@
pub(crate) mod array;
pub(crate) mod datetime;
pub(crate) mod document;
-pub(crate) mod errors;
+pub(crate) mod error;
pub(crate) mod inline_table;
pub(crate) mod key;
pub(crate) mod numbers;
@@ -13,7 +13,7 @@ pub(crate) mod table;
pub(crate) mod trivia;
pub(crate) mod value;
-pub use errors::TomlError;
+pub use crate::error::TomlError;
pub(crate) fn parse_document(raw: &str) -> Result<crate::Document, TomlError> {
use prelude::*;
@@ -95,11 +95,11 @@ pub(crate) mod prelude {
#[cfg(not(feature = "unbounded"))]
impl RecursionCheck {
- pub(crate) fn check_depth(depth: usize) -> Result<(), super::errors::CustomError> {
+ pub(crate) fn check_depth(depth: usize) -> Result<(), super::error::CustomError> {
if depth < 128 {
Ok(())
} else {
- Err(super::errors::CustomError::RecursionLimitExceeded)
+ Err(super::error::CustomError::RecursionLimitExceeded)
}
}
@@ -114,7 +114,7 @@ pub(crate) mod prelude {
Err(winnow::error::ErrMode::from_external_error(
input,
winnow::error::ErrorKind::Eof,
- super::errors::CustomError::RecursionLimitExceeded,
+ super::error::CustomError::RecursionLimitExceeded,
))
}
}
@@ -126,7 +126,7 @@ pub(crate) mod prelude {
#[cfg(feature = "unbounded")]
impl RecursionCheck {
- pub(crate) fn check_depth(_depth: usize) -> Result<(), super::errors::CustomError> {
+ pub(crate) fn check_depth(_depth: usize) -> Result<(), super::error::CustomError> {
Ok(())
}
@@ -140,6 +140,8 @@ pub(crate) mod prelude {
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/numbers.rs b/vendor/toml_edit/src/parser/numbers.rs
index 4c77f51c1..96815268e 100644
--- a/vendor/toml_edit/src/parser/numbers.rs
+++ b/vendor/toml_edit/src/parser/numbers.rs
@@ -319,6 +319,8 @@ pub(crate) const HEXDIG: (RangeInclusive<u8>, RangeInclusive<u8>, RangeInclusive
(DIGIT, b'A'..=b'F', b'a'..=b'f');
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/state.rs b/vendor/toml_edit/src/parser/state.rs
index 235391c75..8388c8847 100644
--- a/vendor/toml_edit/src/parser/state.rs
+++ b/vendor/toml_edit/src/parser/state.rs
@@ -1,5 +1,5 @@
use crate::key::Key;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::repr::Decor;
use crate::table::TableKeyValue;
use crate::{ArrayOfTables, Document, InternalString, Item, RawString, Table};
diff --git a/vendor/toml_edit/src/parser/strings.rs b/vendor/toml_edit/src/parser/strings.rs
index 8c366fad5..675b5c67c 100644
--- a/vendor/toml_edit/src/parser/strings.rs
+++ b/vendor/toml_edit/src/parser/strings.rs
@@ -21,7 +21,7 @@ use winnow::token::tag;
use winnow::token::take_while;
use winnow::trace::trace;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::numbers::HEXDIG;
use crate::parser::prelude::*;
use crate::parser::trivia::{from_utf8_unchecked, newline, ws, ws_newlines, NON_ASCII, WSCHAR};
@@ -363,6 +363,8 @@ fn mll_quotes<'i>(
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/trivia.rs b/vendor/toml_edit/src/parser/trivia.rs
index a359805b2..4575fb153 100644
--- a/vendor/toml_edit/src/parser/trivia.rs
+++ b/vendor/toml_edit/src/parser/trivia.rs
@@ -120,6 +120,8 @@ pub(crate) fn line_trailing(input: &mut Input<'_>) -> PResult<std::ops::Range<us
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/value.rs b/vendor/toml_edit/src/parser/value.rs
index 9e1f0781c..33300ec4c 100644
--- a/vendor/toml_edit/src/parser/value.rs
+++ b/vendor/toml_edit/src/parser/value.rs
@@ -121,6 +121,8 @@ fn apply_raw(mut val: Value, span: std::ops::Range<usize>) -> Result<Value, std:
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;