Rename more Error and Result types.

This commit is contained in:
Dan Gohman
2018-06-12 04:43:02 -07:00
parent 43bd3cb2a3
commit 1b55a2d005
12 changed files with 157 additions and 150 deletions

View File

@@ -1,9 +1,8 @@
//! Define the `Location`, `Error`, and `Result` types.
//! Define the `Location`, `ParseError`, and `ParseResult` types.
#![macro_use]
use std::fmt;
use std::result;
/// The location of a `Token` or `Error`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
@@ -15,14 +14,14 @@ pub struct Location {
/// A parse error is returned when the parse failed.
#[derive(Debug)]
pub struct Error {
pub struct ParseError {
/// Location of the error.
pub location: Location,
/// Error message.
pub message: String,
}
impl fmt::Display for Error {
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.location.line_number == 0 {
write!(f, "command-line arguments: {}", self.message)
@@ -32,20 +31,20 @@ impl fmt::Display for Error {
}
}
/// Result of a parser operation. The `Error` variant includes a location.
pub type Result<T> = result::Result<T, Error>;
/// Result of a parser operation. The `ParseError` variant includes a location.
pub type ParseResult<T> = Result<T, ParseError>;
// Create an `Err` variant of `Result<X>` from a location and `format!` args.
// Create an `Err` variant of `ParseResult<X>` from a location and `format!` args.
macro_rules! err {
( $loc:expr, $msg:expr ) => {
Err($crate::Error {
Err($crate::ParseError {
location: $loc.clone(),
message: $msg.to_string(),
})
};
( $loc:expr, $fmt:expr, $( $arg:expr ),+ ) => {
Err($crate::Error {
Err($crate::ParseError {
location: $loc.clone(),
message: format!( $fmt, $( $arg ),+ ),
})