Remove quickerror in favor of thiserror
This commit is contained in:
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
quick-error = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
parser = { path = "../parser" }
|
||||
tokenizer = { path = "../tokenizer" }
|
||||
helpers = { path = "../helpers" }
|
||||
|
||||
@@ -11,11 +11,11 @@ use parser::{
|
||||
LoopExpression, MemberAccessExpression, Span, Spanned, WhileExpression,
|
||||
},
|
||||
};
|
||||
use quick_error::quick_error;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io::{BufWriter, Write},
|
||||
};
|
||||
use thiserror::Error;
|
||||
use tokenizer::token::Number;
|
||||
|
||||
macro_rules! debug {
|
||||
@@ -50,40 +50,37 @@ fn extract_literal(literal: Literal, allow_strings: bool) -> Result<String, Erro
|
||||
})
|
||||
}
|
||||
|
||||
quick_error! {
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
ParseError(error: parser::Error) {
|
||||
from()
|
||||
}
|
||||
IoError(error: String) {
|
||||
display("IO Error: {}", error)
|
||||
}
|
||||
ScopeError(error: variable_manager::Error) {
|
||||
from()
|
||||
}
|
||||
DuplicateIdentifier(func_name: String, span: Span) {
|
||||
display("`{func_name}` has already been defined")
|
||||
}
|
||||
UnknownIdentifier(ident: String, span: Span) {
|
||||
display("`{ident}` is not found in the current scope.")
|
||||
}
|
||||
InvalidDevice(device: String, span: Span) {
|
||||
display("`{device}` is not valid")
|
||||
}
|
||||
AgrumentMismatch(func_name: String, span: Span) {
|
||||
display("Incorrect number of arguments passed into `{func_name}`")
|
||||
}
|
||||
ConstAssignment(ident: String, span: Span) {
|
||||
display("Attempted to re-assign a value to const variable `{ident}`")
|
||||
}
|
||||
DeviceAssignment(ident: String, span: Span) {
|
||||
display("Attempted to re-assign a value to a device const `{ident}`")
|
||||
}
|
||||
Unknown(reason: String, span: Option<Span>) {
|
||||
display("{reason}")
|
||||
}
|
||||
}
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Parse(#[from] parser::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
Scope(#[from] variable_manager::Error),
|
||||
|
||||
#[error("IO Error: {0}")]
|
||||
IO(String),
|
||||
|
||||
#[error("`{0}` has already been defined.")]
|
||||
DuplicateIdentifier(String, Span),
|
||||
|
||||
#[error("`{0}` is not found in the current scope.")]
|
||||
UnknownIdentifier(String, Span),
|
||||
|
||||
#[error("`{0}` is not valid.")]
|
||||
InvalidDevice(String, Span),
|
||||
|
||||
#[error("Incorrent number of arguments passed into `{0}`")]
|
||||
AgrumentMismatch(String, Span),
|
||||
|
||||
#[error("Attempted to re-assign a value to const variable `{0}`")]
|
||||
ConstAssignment(String, Span),
|
||||
|
||||
#[error("Attempted to re-assign a value to a device const `{0}`")]
|
||||
DeviceAssignment(String, Span),
|
||||
|
||||
#[error("{0}")]
|
||||
Unknown(String, Option<Span>),
|
||||
}
|
||||
|
||||
impl From<Error> for lsp_types::Diagnostic {
|
||||
@@ -91,13 +88,13 @@ impl From<Error> for lsp_types::Diagnostic {
|
||||
use Error::*;
|
||||
use lsp_types::*;
|
||||
match value {
|
||||
ParseError(e) => e.into(),
|
||||
IoError(e) => Diagnostic {
|
||||
Parse(e) => e.into(),
|
||||
IO(e) => Diagnostic {
|
||||
message: e.to_string(),
|
||||
severity: Some(DiagnosticSeverity::ERROR),
|
||||
..Default::default()
|
||||
},
|
||||
ScopeError(e) => e.into(),
|
||||
Scope(e) => e.into(),
|
||||
DuplicateIdentifier(_, span)
|
||||
| UnknownIdentifier(_, span)
|
||||
| InvalidDevice(_, span)
|
||||
@@ -122,7 +119,7 @@ impl From<Error> for lsp_types::Diagnostic {
|
||||
// Map io::Error to Error manually since we can't clone io::Error
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Error::IoError(err.to_string())
|
||||
Error::IO(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +178,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
||||
|
||||
// Copy errors from parser
|
||||
for e in std::mem::take(&mut self.parser.errors) {
|
||||
self.errors.push(Error::ParseError(e));
|
||||
self.errors.push(Error::Parse(e));
|
||||
}
|
||||
|
||||
// We treat parse_all result as potentially partial
|
||||
@@ -190,7 +187,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
||||
Ok(None) => return self.errors,
|
||||
Err(e) => {
|
||||
// Should be covered by parser.errors, but just in case
|
||||
self.errors.push(Error::ParseError(e));
|
||||
self.errors.push(Error::Parse(e));
|
||||
return self.errors;
|
||||
}
|
||||
};
|
||||
@@ -979,7 +976,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
||||
for register in active_registers {
|
||||
let VariableLocation::Stack(stack_offset) = stack
|
||||
.get_location_of(format!("temp_{register}"), None)
|
||||
.map_err(Error::ScopeError)?
|
||||
.map_err(Error::Scope)?
|
||||
else {
|
||||
// This shouldn't happen if we just added it
|
||||
return Err(Error::Unknown(
|
||||
|
||||
@@ -5,25 +5,22 @@
|
||||
|
||||
use lsp_types::{Diagnostic, DiagnosticSeverity};
|
||||
use parser::tree_node::{Literal, Span};
|
||||
use quick_error::quick_error;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use thiserror::Error;
|
||||
|
||||
const TEMP: [u8; 7] = [1, 2, 3, 4, 5, 6, 7];
|
||||
const PERSIST: [u8; 7] = [8, 9, 10, 11, 12, 13, 14];
|
||||
|
||||
quick_error! {
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
DuplicateVariable(var: String, span: Option<Span>) {
|
||||
display("{var} already exists.")
|
||||
}
|
||||
UnknownVariable(var: String, span: Option<Span>) {
|
||||
display("{var} does not exist.")
|
||||
}
|
||||
Unknown(reason: String, span: Option<Span>) {
|
||||
display("{reason}")
|
||||
}
|
||||
}
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("{0} already exists.")]
|
||||
DuplicateVariable(String, Option<Span>),
|
||||
|
||||
#[error("{0} does not exist.")]
|
||||
UnknownVariable(String, Option<Span>),
|
||||
|
||||
#[error("{0}")]
|
||||
Unknown(String, Option<Span>),
|
||||
}
|
||||
|
||||
impl From<Error> for lsp_types::Diagnostic {
|
||||
|
||||
@@ -4,11 +4,10 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
quick-error = { workspace = true }
|
||||
tokenizer = { path = "../tokenizer" }
|
||||
helpers = { path = "../helpers" }
|
||||
lsp-types = { workspace = true }
|
||||
thiserror = "2"
|
||||
thiserror = { workspace = true }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
pub mod sys_call;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
pub mod sys_call;
|
||||
pub mod tree_node;
|
||||
|
||||
use crate::sys_call::{Math, System};
|
||||
@@ -28,8 +27,8 @@ macro_rules! boxed {
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Tokenizer Error: {0}")]
|
||||
TokenizerError(#[from] tokenizer::Error),
|
||||
#[error(transparent)]
|
||||
Tokenizer(#[from] tokenizer::Error),
|
||||
|
||||
#[error("Unexpected token: {1}")]
|
||||
UnexpectedToken(Span, Token),
|
||||
@@ -52,7 +51,7 @@ impl From<Error> for lsp_types::Diagnostic {
|
||||
use Error::*;
|
||||
use lsp_types::*;
|
||||
match value {
|
||||
TokenizerError(e) => e.into(),
|
||||
Tokenizer(e) => e.into(),
|
||||
UnexpectedToken(span, _)
|
||||
| DuplicateIdentifier(span, _)
|
||||
| InvalidSyntax(span, _)
|
||||
@@ -216,7 +215,7 @@ impl<'a> Parser<'a> {
|
||||
match self.tokenizer.peek() {
|
||||
Ok(None) => break,
|
||||
Err(e) => {
|
||||
self.errors.push(Error::TokenizerError(e));
|
||||
self.errors.push(Error::Tokenizer(e));
|
||||
break;
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::sys_call;
|
||||
|
||||
use super::sys_call::SysCall;
|
||||
use crate::sys_call;
|
||||
use std::ops::Deref;
|
||||
use tokenizer::token::Number;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
|
||||
@@ -5,11 +5,10 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rust_decimal = { workspace = true }
|
||||
quick-error = { workspace = true }
|
||||
lsp-types = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
helpers = { path = "../helpers" }
|
||||
logos = "0.16"
|
||||
thiserror = "2"
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = { version = "^1" }
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
pub mod token;
|
||||
|
||||
use logos::{Lexer, Logos};
|
||||
use quick_error::quick_error;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
collections::VecDeque,
|
||||
io::{Read, Seek, SeekFrom},
|
||||
};
|
||||
use thiserror::Error;
|
||||
use token::{Token, TokenType};
|
||||
|
||||
quick_error! {
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
IOError(err: std::io::Error) {
|
||||
from()
|
||||
display("IO Error: {}", err)
|
||||
source(err)
|
||||
}
|
||||
LexError(err: token::LexError) {
|
||||
from()
|
||||
}
|
||||
}
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("IO Error: {0}")]
|
||||
IOError(#[from()] std::io::Error),
|
||||
#[error(transparent)]
|
||||
LexError(#[from] token::LexError),
|
||||
}
|
||||
|
||||
impl From<Error> for lsp_types::Diagnostic {
|
||||
|
||||
@@ -7,7 +7,7 @@ use thiserror::Error;
|
||||
#[derive(Debug, Error, Default, Clone, PartialEq)]
|
||||
pub enum LexError {
|
||||
#[error("Attempted to parse an invalid number: {2}")]
|
||||
NumberParseError(usize, Span, String),
|
||||
NumberParse(usize, Span, String),
|
||||
|
||||
#[error("An invalid character was found in token stream: {2}")]
|
||||
InvalidInput(usize, Span, String),
|
||||
@@ -20,7 +20,7 @@ pub enum LexError {
|
||||
impl From<LexError> for Diagnostic {
|
||||
fn from(value: LexError) -> Self {
|
||||
match value {
|
||||
LexError::NumberParseError(line, col, str) | LexError::InvalidInput(line, col, str) => {
|
||||
LexError::NumberParse(line, col, str) | LexError::InvalidInput(line, col, str) => {
|
||||
Diagnostic {
|
||||
range: Range {
|
||||
start: Position {
|
||||
@@ -281,13 +281,13 @@ fn parse_number<'a>(lexer: &mut Lexer<'a, TokenType>) -> Result<Number, LexError
|
||||
Number::Decimal(
|
||||
clean_str
|
||||
.parse::<Decimal>()
|
||||
.map_err(|_| LexError::NumberParseError(line, span, slice.to_string()))?,
|
||||
.map_err(|_| LexError::NumberParse(line, span, slice.to_string()))?,
|
||||
)
|
||||
} else {
|
||||
Number::Integer(
|
||||
clean_str
|
||||
.parse::<i128>()
|
||||
.map_err(|_| LexError::NumberParseError(line, span, slice.to_string()))?,
|
||||
.map_err(|_| LexError::NumberParse(line, span, slice.to_string()))?,
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user