arrow-parser 0.0.2

Parser for the Arrow programming language
Documentation
use super::source::SourceRange;
use super::token::TokenType;

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum SyntaxErrorType {
  BindingToNonImpl,
  ExpectedNotFound,
  ExpectedSyntax(&'static str),
  InvalidAssigmentTarget,
  LoopCannotResult,
  MalformedLiteral,
  RedeclaredVar,
  RequiredTokenNotFound(TokenType),
  UnexpectedEnd,
}

#[derive(Clone, Debug)]
pub struct SyntaxError {
  pub source: SourceRange,
  pub typ: SyntaxErrorType,
  pub actual_token: Option<TokenType>,
}

impl SyntaxError {
  pub fn new(
    typ: SyntaxErrorType,
    source: SourceRange,
    actual_token: Option<TokenType>,
  ) -> SyntaxError {
    SyntaxError {
      typ,
      source,
      actual_token,
    }
  }

  pub fn from_loc(
    loc: SourceRange,
    typ: SyntaxErrorType,
    actual_token: Option<TokenType>,
  ) -> SyntaxError {
    SyntaxError {
      source: loc,
      typ,
      actual_token,
    }
  }
}

pub type SyntaxResult<T> = Result<T, SyntaxError>;