summaryrefslogtreecommitdiffstats
path: root/vendor/toml_edit/src/parser/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/toml_edit/src/parser/document.rs')
-rw-r--r--vendor/toml_edit/src/parser/document.rs105
1 files changed, 49 insertions, 56 deletions
diff --git a/vendor/toml_edit/src/parser/document.rs b/vendor/toml_edit/src/parser/document.rs
index 791185b68..aa8fb1158 100644
--- a/vendor/toml_edit/src/parser/document.rs
+++ b/vendor/toml_edit/src/parser/document.rs
@@ -5,9 +5,9 @@ use winnow::combinator::eof;
use winnow::combinator::opt;
use winnow::combinator::peek;
use winnow::combinator::repeat;
-use winnow::error::FromExternalError;
use winnow::token::any;
use winnow::token::one_of;
+use winnow::trace::trace;
use crate::document::Document;
use crate::key::Key;
@@ -30,11 +30,11 @@ use crate::RawString;
// ( ws keyval ws [ comment ] ) /
// ( ws table ws [ comment ] ) /
// ws )
-pub(crate) fn document(input: Input<'_>) -> IResult<Input<'_>, Document, ParserError<'_>> {
+pub(crate) fn document(input: &mut Input<'_>) -> PResult<Document> {
let state = RefCell::new(ParseState::default());
let state_ref = &state;
- let (i, _o) = (
+ let _o = (
// Remove BOM if present
opt(b"\xEF\xBB\xBF"),
parse_ws(state_ref),
@@ -52,23 +52,15 @@ pub(crate) fn document(input: Input<'_>) -> IResult<Input<'_>, Document, ParserE
eof,
)
.parse_next(input)?;
- state
- .into_inner()
- .into_document()
- .map(|document| (i, document))
- .map_err(|err| {
- winnow::error::ErrMode::Backtrack(ParserError::from_external_error(
- i,
- winnow::error::ErrorKind::Verify,
- err,
- ))
- })
+ state.into_inner().into_document().map_err(|err| {
+ winnow::error::ErrMode::from_external_error(input, winnow::error::ErrorKind::Verify, err)
+ })
}
pub(crate) fn parse_comment<'s, 'i>(
state: &'s RefCell<ParseState>,
-) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'_>> + 's {
- move |i| {
+) -> impl Parser<Input<'i>, (), ContextError> + 's {
+ move |i: &mut Input<'i>| {
(comment, line_ending)
.span()
.map(|span| {
@@ -80,8 +72,8 @@ pub(crate) fn parse_comment<'s, 'i>(
pub(crate) fn parse_ws<'s, 'i>(
state: &'s RefCell<ParseState>,
-) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's {
- move |i| {
+) -> impl Parser<Input<'i>, (), ContextError> + 's {
+ move |i: &mut Input<'i>| {
ws.span()
.map(|span| state.borrow_mut().on_ws(span))
.parse_next(i)
@@ -90,8 +82,8 @@ pub(crate) fn parse_ws<'s, 'i>(
pub(crate) fn parse_newline<'s, 'i>(
state: &'s RefCell<ParseState>,
-) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's {
- move |i| {
+) -> impl Parser<Input<'i>, (), ContextError> + 's {
+ move |i: &mut Input<'i>| {
newline
.span()
.map(|span| state.borrow_mut().on_ws(span))
@@ -101,8 +93,8 @@ pub(crate) fn parse_newline<'s, 'i>(
pub(crate) fn keyval<'s, 'i>(
state: &'s RefCell<ParseState>,
-) -> impl FnMut(Input<'i>) -> IResult<Input<'i>, (), ParserError<'i>> + 's {
- move |i| {
+) -> impl Parser<Input<'i>, (), ContextError> + 's {
+ move |i: &mut Input<'i>| {
parse_keyval
.try_map(|(p, kv)| state.borrow_mut().on_keyval(p, kv))
.parse_next(i)
@@ -110,39 +102,40 @@ pub(crate) fn keyval<'s, 'i>(
}
// keyval = key keyval-sep val
-pub(crate) fn parse_keyval(
- input: Input<'_>,
-) -> IResult<Input<'_>, (Vec<Key>, TableKeyValue), ParserError<'_>> {
- (
- key,
- cut_err((
- one_of(KEYVAL_SEP)
- .context(Context::Expected(ParserValue::CharLiteral('.')))
- .context(Context::Expected(ParserValue::CharLiteral('='))),
- (
- ws.span(),
- value(RecursionCheck::default()),
- line_trailing
- .context(Context::Expected(ParserValue::CharLiteral('\n')))
- .context(Context::Expected(ParserValue::CharLiteral('#'))),
- ),
- )),
- )
- .try_map::<_, _, std::str::Utf8Error>(|(key, (_, v))| {
- let mut path = key;
- let key = path.pop().expect("grammar ensures at least 1");
+pub(crate) fn parse_keyval(input: &mut Input<'_>) -> PResult<(Vec<Key>, TableKeyValue)> {
+ trace(
+ "keyval",
+ (
+ key,
+ cut_err((
+ one_of(KEYVAL_SEP)
+ .context(StrContext::Expected(StrContextValue::CharLiteral('.')))
+ .context(StrContext::Expected(StrContextValue::CharLiteral('='))),
+ (
+ ws.span(),
+ value(RecursionCheck::default()),
+ line_trailing
+ .context(StrContext::Expected(StrContextValue::CharLiteral('\n')))
+ .context(StrContext::Expected(StrContextValue::CharLiteral('#'))),
+ ),
+ )),
+ )
+ .try_map::<_, _, std::str::Utf8Error>(|(key, (_, v))| {
+ let mut path = key;
+ let key = path.pop().expect("grammar ensures at least 1");
- let (pre, v, suf) = v;
- let pre = RawString::with_span(pre);
- let suf = RawString::with_span(suf);
- let v = v.decorated(pre, suf);
- Ok((
- path,
- TableKeyValue {
- key,
- value: Item::Value(v),
- },
- ))
- })
- .parse_next(input)
+ let (pre, v, suf) = v;
+ let pre = RawString::with_span(pre);
+ let suf = RawString::with_span(suf);
+ let v = v.decorated(pre, suf);
+ Ok((
+ path,
+ TableKeyValue {
+ key,
+ value: Item::Value(v),
+ },
+ ))
+ }),
+ )
+ .parse_next(input)
}