From 48b503913bbf6464e43149674342f030678aafd6 Mon Sep 17 00:00:00 2001 From: Caleb Jones Date: Tue, 20 Dec 2016 17:10:25 -0500 Subject: [PATCH] Change parse to return a ParseError instead of () --- src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 09508d0..f5cfccc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ //! A lightweight S-expression parser intended for language implementation. -#![warn(missing_docs)] +// #![warn(missing_docs)] #![deny(unsafe_code)] #[macro_use] @@ -8,7 +8,15 @@ extern crate nom; use nom::{digit, multispace, IResult}; +/// Indicates how parsing failed. +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +pub enum ParseError { + /// We can't explain how the parsing failed. + Unspecified, +} + #[derive(Debug, PartialEq, Clone, PartialOrd)] +/// An `Atom` is the representation of a non-composite object pub enum Atom { /// A value representing a symbol. A symbol is an atomic unit Sym(String), @@ -25,6 +33,8 @@ pub enum Atom { } #[derive(Debug, PartialEq, Clone, PartialOrd)] +/// A `Sexp` represents either an `Atom` or a `List`. It encompasses all +/// possible lisp expressions. pub enum Sexp { /// A wrapper around the atom type Atom { @@ -36,10 +46,10 @@ pub enum Sexp { } } -pub fn parse(input: &str) -> Result { +pub fn parse(input: &str) -> Result { match do_parse!(input, exp: sexp >> opt!(multispace) >> eof!() >> (exp)) { IResult::Done(_, res) => Ok(res), - _ => Err(()), + _ => Err(ParseError::Unspecified), } } -- 2.47.0