Skip to content

Commit 3676b13

Browse files
committed
Remove HeaderError from the pub api and hide it.
1 parent 37c985c commit 3676b13

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

cfgrammar/src/lib/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::{error::Error, fmt};
1616
/// * An error during parsing the section.
1717
/// * An error resulting from a value in the section having an invalid value.
1818
#[derive(Debug, Clone)]
19+
#[doc(hidden)]
1920
pub struct HeaderError<T> {
2021
pub kind: HeaderErrorKind,
2122
pub locations: Vec<T>,

cfgrammar/src/lib/yacc/ast.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ impl ASTWithValidityInfo {
7373
}
7474

7575
impl FromStr for ASTWithValidityInfo {
76-
type Err = Vec<HeaderError<Span>>;
76+
type Err = Vec<YaccGrammarError>;
7777
/// Parses the `%grmtools section` expecting it to contain a `yacckind` entry.
78-
fn from_str(src: &str) -> Result<Self, Vec<HeaderError<Span>>> {
78+
fn from_str(src: &str) -> Result<Self, Vec<YaccGrammarError>> {
7979
let mut errs = Vec::new();
80-
let (header, _) = GrmtoolsSectionParser::new(src, true).parse()?;
80+
let (header, _) = GrmtoolsSectionParser::new(src, true)
81+
.parse()
82+
.map_err(|mut errs| errs.drain(..).map(|e| e.into()).collect::<Vec<_>>())?;
8183
if let Some(HeaderValue(_, yk_val)) = header.get("yacckind") {
82-
let yacc_kind = YaccKind::try_from(yk_val).map_err(|e| vec![e])?;
84+
let yacc_kind = YaccKind::try_from(yk_val).map_err(|e| vec![e.into()])?;
8385
let ast = {
8486
// We don't want to strip off the header so that span's will be correct.
8587
let mut yp = YaccParser::new(yacc_kind, src);
@@ -96,8 +98,9 @@ impl FromStr for ASTWithValidityInfo {
9698
} else {
9799
Err(vec![HeaderError {
98100
kind: HeaderErrorKind::InvalidEntry("yacckind"),
99-
locations: vec![],
100-
}])
101+
locations: vec![Span::new(0, 0)],
102+
}
103+
.into()])
101104
}
102105
}
103106
}

cfgrammar/src/lib/yacc/grammar.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ where
193193
{
194194
type Err = Vec<YaccGrammarError>;
195195
fn from_str(s: &str) -> YaccGrammarResult<Self> {
196-
let ast_validation = ast::ASTWithValidityInfo::from_str(s)
197-
.map_err(|mut errs| errs.drain(..).map(|e| e.into()).collect::<Vec<_>>())?;
196+
let ast_validation = ast::ASTWithValidityInfo::from_str(s)?;
198197
Self::new_from_ast_with_validity_info(&ast_validation)
199198
}
200199
}

0 commit comments

Comments
 (0)