From bc98b29723777266c43a1bca55bc82ffc50129e9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 22 Oct 2024 21:31:17 +0200 Subject: [PATCH 01/43] =?UTF-8?q?=F0=9F=8E=89=20Start=20of=20rewrite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit semver: chore --- .gitignore | 1 + src/diagnostic.rs | 167 ---------------- src/files.rs | 84 -------- src/main.rs | 65 +------ src/parser/ast.rs | 53 ------ src/parser/expression.rs | 142 -------------- src/parser/lookup.rs | 227 ---------------------- src/parser/macros.rs | 145 -------------- src/parser/mod.rs | 219 --------------------- src/parser/statement.rs | 155 --------------- src/parser/typing.rs | 128 ------------- src/scanner/lexeme.rs | 229 ---------------------- src/scanner/mod.rs | 402 --------------------------------------- src/transpiler/bend.rs | 135 ------------- src/transpiler/mod.rs | 7 - 15 files changed, 3 insertions(+), 2156 deletions(-) delete mode 100644 src/diagnostic.rs delete mode 100644 src/files.rs delete mode 100644 src/parser/ast.rs delete mode 100644 src/parser/expression.rs delete mode 100644 src/parser/lookup.rs delete mode 100644 src/parser/macros.rs delete mode 100644 src/parser/mod.rs delete mode 100644 src/parser/statement.rs delete mode 100644 src/parser/typing.rs delete mode 100644 src/scanner/lexeme.rs delete mode 100644 src/scanner/mod.rs delete mode 100644 src/transpiler/bend.rs delete mode 100644 src/transpiler/mod.rs diff --git a/.gitignore b/.gitignore index ea8c4bf..5733f74 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/.history diff --git a/src/diagnostic.rs b/src/diagnostic.rs deleted file mode 100644 index 739d85f..0000000 --- a/src/diagnostic.rs +++ /dev/null @@ -1,167 +0,0 @@ -use crate::scanner::lexeme::Lexeme; - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Diagnostic<'a> { - pub severity: Severity, - pub title: String, - pub errors: Vec>, -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Error<'a> { - pub message: String, - pub label: Label, - pub range: Range<'a>, -} - -impl<'a> Error<'a> { - pub fn primary( - file_id: impl Into<&'a str>, - position: usize, - length: usize, - message: impl Into, - ) -> Error<'a> { - Error::new(file_id, Label::Primary, position, length, message) - } - - pub fn secondary( - file_id: impl Into<&'a str>, - position: usize, - length: usize, - message: impl Into, - ) -> Error<'a> { - Error::new(file_id, Label::Secondary, position, length, message) - } - - pub fn new( - file_id: impl Into<&'a str>, - label: Label, - position: usize, - length: usize, - message: impl Into, - ) -> Error<'a> { - Error { - message: message.into(), - label, - range: Range { - file_id: file_id.into(), - position, - length, - }, - } - } - - pub(crate) fn transform_range(mut self, lexemes: &'a [Lexeme<'a>]) -> Error { - self.range = self.range.to_source_code_range(lexemes); - self - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Severity { - Error, - Warning, - Note, - Help, -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Label { - Primary, - Secondary, -} - -impl From for codespan_reporting::diagnostic::Severity { - fn from(val: Severity) -> Self { - match val { - Severity::Error => codespan_reporting::diagnostic::Severity::Error, - Severity::Warning => codespan_reporting::diagnostic::Severity::Warning, - Severity::Note => codespan_reporting::diagnostic::Severity::Note, - Severity::Help => codespan_reporting::diagnostic::Severity::Help, - } - } -} - -impl<'a> Diagnostic<'a> { - pub fn error(message: impl Into) -> Diagnostic<'a> { - Diagnostic::new(Severity::Error, message) - } - - pub fn warning(message: impl Into) -> Diagnostic<'a> { - Diagnostic::new(Severity::Warning, message) - } - - pub fn new(severity: Severity, message: impl Into) -> Diagnostic<'a> { - Diagnostic { - severity, - title: message.into(), - errors: vec![], - } - } - - pub fn with_error(mut self, error: Error<'a>) -> Self { - self.errors.push(error); - self - } -} - -impl<'a> From> for codespan_reporting::diagnostic::Diagnostic<&'a str> { - fn from(val: Diagnostic<'a>) -> Self { - codespan_reporting::diagnostic::Diagnostic::<&'a str>::new(val.severity.into()) - .with_message(val.title) - .with_labels(val.errors.into_iter().map(|error| error.into()).collect()) - } -} - -impl<'a> From> for codespan_reporting::diagnostic::Label<&'a str> { - fn from(val: Error<'a>) -> Self { - codespan_reporting::diagnostic::Label::new( - val.label.into(), - val.range.file_id, - val.range.position..val.range.position + val.range.length, - ) - .with_message(val.message) - } -} - -impl From