Skip to content

Commit

Permalink
Merge pull request #333 from KisaragiEffective/refactor/improve-simpl…
Browse files Browse the repository at this point in the history
…e-error-with-pos
  • Loading branch information
KisaragiEffective authored Dec 21, 2023
2 parents 54ebcc3 + 741c802 commit c434e61
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 187 deletions.
4 changes: 2 additions & 2 deletions package/origlang-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use thiserror::Error;
use origlang_compiler::parser::SimpleErrorWithPos;
use origlang_compiler::parser::ParserError;
use origlang_compiler::type_check::error::TypeCheckError;
use origlang_runtime::RuntimeError;
use crate::args::ReadSourceError;
Expand All @@ -10,7 +10,7 @@ pub enum TaskExecutionError {
#[error("Failed to read source: {0}")]
Source(#[from] ReadSourceError),
#[error("{0}")]
Generic(#[from] SimpleErrorWithPos),
Generic(#[from] ParserError),
#[error("{0}")]
TypeCheck(#[from] TypeCheckError),
#[error("{0}")]
Expand Down
4 changes: 2 additions & 2 deletions package/origlang-cli/src/task/emit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;
use origlang_compiler::lexer::Lexer;
use origlang_compiler::parser::{Parser, SimpleErrorWithPos};
use origlang_compiler::parser::{Parser, ParserError};
use origlang_compiler::type_check::error::TypeCheckError;
use origlang_compiler::type_check::TypeChecker;
use origlang_ir::{IR1, IR2, IntoVerbatimSequencedIR};
Expand All @@ -19,7 +19,7 @@ pub enum EmitError {
#[error("source: {0}")]
Source(#[from] ReadSourceError),
#[error("parser: {0}")]
Parser(#[from] SimpleErrorWithPos),
Parser(#[from] ParserError),
#[error("type check: {0}")]
TypeCheck(#[from] TypeCheckError),
}
Expand Down
30 changes: 15 additions & 15 deletions package/origlang-cli/src/task/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ariadne::{Report, ReportKind, Source};
use crate::task::Task;
use crate::error::TaskExecutionError;
use origlang_platform::CTRL_D_NL;
use origlang_compiler::parser::{Parser, ParserError};
use origlang_compiler::parser::{Parser, ParserErrorInner};
use origlang_runtime::{PrintToStdout, Runtime, TypeBox};
use origlang_compiler::type_check::TypeChecker;
use origlang_ir::{IntoVerbatimSequencedIR, IR2};
Expand Down Expand Up @@ -65,9 +65,9 @@ impl Task for Repl {
runtime.start(&Self::naive_lower(ast));
}
Err(error_message) => {
let error = error_message.kind;
let error = error_message.kind();
let handled = false;
if let ParserError::PartiallyParsed { hint: _, intermediate_state: _ } = &error {
if let ParserErrorInner::PartiallyParsed { hint: _, intermediate_state: _ } = &error {
// TODO: insta-expression eval
// TODO: revisit this
/*
Expand All @@ -92,18 +92,18 @@ impl Task for Repl {
if !handled {
let error_offset = 0;
let error_code = match error {
ParserError::LexerError(_) => 1,
ParserError::UnconsumedToken { .. } => 2,
ParserError::StatementTerminationError => 3,
ParserError::EndOfFileError => 4,
ParserError::UnexpectedToken { .. } => 5,
ParserError::UnParsableIntLiteral { .. } => 6,
ParserError::OverflowedLiteral { .. } => 7,
ParserError::IfExpressionWithoutElseClause => 8,
ParserError::IfExpressionWithoutThenClauseAndElseClause => 9,
ParserError::PartiallyParsed { .. } => 10,
ParserError::InsufficientElementsForTupleLiteral(_) => 11,
ParserError::UnderscoreCanNotBeRightHandExpression => 12,
ParserErrorInner::LexerError(_) => 1,
ParserErrorInner::UnconsumedToken { .. } => 2,
ParserErrorInner::StatementTerminationError => 3,
ParserErrorInner::EndOfFileError => 4,
ParserErrorInner::UnexpectedToken { .. } => 5,
ParserErrorInner::UnParsableIntLiteral { .. } => 6,
ParserErrorInner::OverflowedLiteral { .. } => 7,
ParserErrorInner::IfExpressionWithoutElseClause => 8,
ParserErrorInner::IfExpressionWithoutThenClauseAndElseClause => 9,
ParserErrorInner::PartiallyParsed { .. } => 10,
ParserErrorInner::InsufficientElementsForTupleLiteral(_) => 11,
ParserErrorInner::UnderscoreCanNotBeRightHandExpression => 12,
};

let d = Report::<Range<usize>>::build(ReportKind::Error, (), error_offset)
Expand Down
4 changes: 2 additions & 2 deletions package/origlang-compiler-entrypoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use log::debug;
use thiserror::Error;
use origlang_ast::Statement;
use origlang_compiler::lexer::token::{Token as LexerToken};
use origlang_compiler::parser::{Parser, SimpleErrorWithPos};
use origlang_compiler::parser::{Parser, ParserError};
use origlang_compiler::type_check::error::TypeCheckError;
use origlang_compiler::type_check::TypeChecker;
use origlang_diagnostics::{Diagnostic, DiagnosticSink};
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Default for TheCompiler {
#[derive(Debug, Eq, PartialEq, Error)]
pub enum PartialCompilation {
#[error("syntax error: {0}")]
Parser(#[from] SimpleErrorWithPos),
Parser(#[from] ParserError),
#[error("type check error: {0}")]
TypeChecker(#[from] TypeCheckError),
}
Expand Down
Loading

0 comments on commit c434e61

Please sign in to comment.