tamer: obj::xmlo: Extract error types into own module
parent
f519dab2b6
commit
7367e20c01
|
@ -37,7 +37,10 @@
|
|||
//! it is wrapped in an [`Option`] so that [`take`](Option::take) can be
|
||||
//! used to take ownership over the data.
|
||||
|
||||
use super::reader::{XmloError, XmloEvent, XmloResult};
|
||||
use super::{
|
||||
reader::{XmloEvent, XmloResult},
|
||||
XmloError,
|
||||
};
|
||||
use crate::asg::{
|
||||
Asg, AsgError, IdentKind, IdentKindError, IdentObjectState, IndexType,
|
||||
ObjectRef, Source,
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
// XIR-based xmlo object errors
|
||||
//
|
||||
// Copyright (C) 2014-2021 Ryan Specialty Group, LLC.
|
||||
//
|
||||
// This file is part of TAME.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Errors while processing `xmlo` object files.
|
||||
|
||||
use crate::sym::SymbolId;
|
||||
use crate::tpwrap::quick_xml::{Error as XmlError, InnerXmlError};
|
||||
use std::fmt::Display;
|
||||
|
||||
/// Error during `xmlo` processing.
|
||||
///
|
||||
/// Errors contain only owned values rather than references to original
|
||||
/// data since they represent conditions requiring termination from
|
||||
/// malformed compiler output,
|
||||
/// and so should rarely occur.
|
||||
/// This drastically simplifies the reader and [`Result`] chaining.
|
||||
///
|
||||
/// TODO: These errors provide no context (byte offset).
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum XmloError {
|
||||
/// XML parsing error (legacy, quick-xml).
|
||||
XmlError(XmlError),
|
||||
/// The root node was not an `lv:package`.
|
||||
UnexpectedRoot,
|
||||
/// A `preproc:sym` node was found, but is missing `@name`.
|
||||
UnassociatedSym,
|
||||
/// The provided `preproc:sym/@type` is unknown or invalid.
|
||||
InvalidType(String),
|
||||
/// The provided `preproc:sym/@dtype` is unknown or invalid.
|
||||
InvalidDtype(String),
|
||||
/// The provided `preproc:sym/@dim` is invalid.
|
||||
InvalidDim(String),
|
||||
/// A `preproc:sym-dep` element was found, but is missing `@name`.
|
||||
UnassociatedSymDep,
|
||||
/// The `preproc:sym[@type="map"]` contains unexpected or invalid data.
|
||||
InvalidMapFrom(String),
|
||||
/// Invalid dependency in adjacency list
|
||||
/// (`preproc:sym-dep/preproc:sym-ref`).
|
||||
MalformedSymRef(String),
|
||||
/// A `preproc:fragment` element was found, but is missing `@id`.
|
||||
UnassociatedFragment,
|
||||
/// A `preproc:fragment` element was found, but is missing `text()`.
|
||||
MissingFragmentText(SymbolId),
|
||||
/// Token stream ended unexpectedly.
|
||||
UnexpectedEof,
|
||||
}
|
||||
|
||||
impl From<InnerXmlError> for XmloError {
|
||||
fn from(e: InnerXmlError) -> Self {
|
||||
XmloError::XmlError(e.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for XmloError {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::XmlError(e) => e.fmt(fmt),
|
||||
Self::UnexpectedRoot => {
|
||||
write!(fmt, "unexpected package root (is this a package?)")
|
||||
}
|
||||
Self::UnassociatedSym => write!(
|
||||
fmt,
|
||||
"unassociated symbol table entry: preproc:sym/@name missing"
|
||||
),
|
||||
Self::InvalidType(ty) => {
|
||||
write!(fmt, "invalid preproc:sym/@type `{}`", ty)
|
||||
}
|
||||
Self::InvalidDtype(dtype) => {
|
||||
write!(fmt, "invalid preproc:sym/@dtype `{}`", dtype)
|
||||
}
|
||||
Self::InvalidDim(dim) => {
|
||||
write!(fmt, "invalid preproc:sym/@dim `{}`", dim)
|
||||
}
|
||||
Self::InvalidMapFrom(msg) => {
|
||||
write!(fmt, "invalid preproc:sym[@type=\"map\"]: {}", msg)
|
||||
}
|
||||
Self::UnassociatedSymDep => write!(
|
||||
fmt,
|
||||
"unassociated dependency list: preproc:sym-dep/@name missing"
|
||||
),
|
||||
Self::MalformedSymRef(msg) => {
|
||||
write!(fmt, "malformed dependency ref: {}", msg)
|
||||
}
|
||||
Self::UnassociatedFragment => write!(
|
||||
fmt,
|
||||
"unassociated fragment: preproc:fragment/@id missing"
|
||||
),
|
||||
Self::MissingFragmentText(symname) => write!(
|
||||
fmt,
|
||||
"fragment found, but missing text for symbol `{}`",
|
||||
symname,
|
||||
),
|
||||
Self::UnexpectedEof => write!(fmt, "unexpected EOF"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for XmloError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::XmlError(e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,9 +75,11 @@
|
|||
//! ```
|
||||
|
||||
mod asg_builder;
|
||||
mod error;
|
||||
mod ir;
|
||||
mod reader;
|
||||
|
||||
pub use asg_builder::{AsgBuilder, AsgBuilderState};
|
||||
pub use error::XmloError;
|
||||
pub use ir::{PackageAttrs, SymAttrs, SymDtype, SymType};
|
||||
pub use reader::{XmloError, XmloEvent, XmloReader};
|
||||
pub use reader::{XmloEvent, XmloReader};
|
||||
|
|
|
@ -17,10 +17,8 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{PackageAttrs, SymAttrs};
|
||||
use super::{PackageAttrs, SymAttrs, XmloError};
|
||||
use crate::sym::SymbolId;
|
||||
use crate::tpwrap::quick_xml::{Error as XmlError, InnerXmlError};
|
||||
use std::fmt::Display;
|
||||
|
||||
// While the _use_ is gated, this isn't, to ensure that we still try to
|
||||
// compile it while the flag is off (and so it's parsed by the language
|
||||
|
@ -157,103 +155,6 @@ pub enum XmloEvent {
|
|||
Eoh,
|
||||
}
|
||||
|
||||
/// Error during `xmlo` processing.
|
||||
///
|
||||
/// Errors contain only owned values rather than references to original
|
||||
/// data since they represent conditions requiring termination from
|
||||
/// malformed compiler output,
|
||||
/// and so should rarely occur.
|
||||
/// This drastically simplifies the reader and [`Result`] chaining.
|
||||
///
|
||||
/// TODO: These errors provide no context (byte offset).
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum XmloError {
|
||||
/// XML parsing error (legacy, quick-xml).
|
||||
XmlError(XmlError),
|
||||
/// The root node was not an `lv:package`.
|
||||
UnexpectedRoot,
|
||||
/// A `preproc:sym` node was found, but is missing `@name`.
|
||||
UnassociatedSym,
|
||||
/// The provided `preproc:sym/@type` is unknown or invalid.
|
||||
InvalidType(String),
|
||||
/// The provided `preproc:sym/@dtype` is unknown or invalid.
|
||||
InvalidDtype(String),
|
||||
/// The provided `preproc:sym/@dim` is invalid.
|
||||
InvalidDim(String),
|
||||
/// A `preproc:sym-dep` element was found, but is missing `@name`.
|
||||
UnassociatedSymDep,
|
||||
/// The `preproc:sym[@type="map"]` contains unexpected or invalid data.
|
||||
InvalidMapFrom(String),
|
||||
/// Invalid dependency in adjacency list
|
||||
/// (`preproc:sym-dep/preproc:sym-ref`).
|
||||
MalformedSymRef(String),
|
||||
/// A `preproc:fragment` element was found, but is missing `@id`.
|
||||
UnassociatedFragment,
|
||||
/// A `preproc:fragment` element was found, but is missing `text()`.
|
||||
MissingFragmentText(SymbolId),
|
||||
/// Token stream ended unexpectedly.
|
||||
UnexpectedEof,
|
||||
}
|
||||
|
||||
impl From<InnerXmlError> for XmloError {
|
||||
fn from(e: InnerXmlError) -> Self {
|
||||
XmloError::XmlError(e.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for XmloError {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::XmlError(e) => e.fmt(fmt),
|
||||
Self::UnexpectedRoot => {
|
||||
write!(fmt, "unexpected package root (is this a package?)")
|
||||
}
|
||||
Self::UnassociatedSym => write!(
|
||||
fmt,
|
||||
"unassociated symbol table entry: preproc:sym/@name missing"
|
||||
),
|
||||
Self::InvalidType(ty) => {
|
||||
write!(fmt, "invalid preproc:sym/@type `{}`", ty)
|
||||
}
|
||||
Self::InvalidDtype(dtype) => {
|
||||
write!(fmt, "invalid preproc:sym/@dtype `{}`", dtype)
|
||||
}
|
||||
Self::InvalidDim(dim) => {
|
||||
write!(fmt, "invalid preproc:sym/@dim `{}`", dim)
|
||||
}
|
||||
Self::InvalidMapFrom(msg) => {
|
||||
write!(fmt, "invalid preproc:sym[@type=\"map\"]: {}", msg)
|
||||
}
|
||||
Self::UnassociatedSymDep => write!(
|
||||
fmt,
|
||||
"unassociated dependency list: preproc:sym-dep/@name missing"
|
||||
),
|
||||
Self::MalformedSymRef(msg) => {
|
||||
write!(fmt, "malformed dependency ref: {}", msg)
|
||||
}
|
||||
Self::UnassociatedFragment => write!(
|
||||
fmt,
|
||||
"unassociated fragment: preproc:fragment/@id missing"
|
||||
),
|
||||
Self::MissingFragmentText(symname) => write!(
|
||||
fmt,
|
||||
"fragment found, but missing text for symbol `{}`",
|
||||
symname,
|
||||
),
|
||||
Self::UnexpectedEof => write!(fmt, "unexpected EOF"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for XmloError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::XmlError(e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wip-xmlo-xir-reader")]
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::super::{InnerXmlError, XmlError};
|
||||
use super::*;
|
||||
use crate::obj::xmlo::{SymDtype, SymType};
|
||||
use crate::sym::GlobalSymbolIntern;
|
||||
use crate::test::quick_xml::*;
|
||||
use crate::tpwrap::quick_xml::{Error as XmlError, InnerXmlError};
|
||||
|
||||
type Sut<B> = XmloReader<B>;
|
||||
|
||||
|
|
|
@ -444,6 +444,7 @@ pub mod st {
|
|||
L_DESC: cid "desc",
|
||||
L_DIM: cid "dim",
|
||||
L_DTYPE: cid "dtype",
|
||||
L_ELIG_CLASS_YIELDS: tid "elig-class-yields",
|
||||
L_EMPTY: cid "empty",
|
||||
L_EXEC: cid "exec",
|
||||
L_FALSE: cid "false",
|
||||
|
|
Loading…
Reference in New Issue