From bc9b755ab959015202af2596cb5841db5b00daa7 Mon Sep 17 00:00:00 2001 From: Teascade Date: Thu, 25 Jun 2020 00:46:05 +0300 Subject: [PATCH] Add loads of errors, add argh --- Cargo.lock | 83 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/compiler.rs | 2 +- src/errors.rs | 13 ++------ src/parser/mod.rs | 6 ++-- src/vm/mod.rs | 2 -- 6 files changed, 92 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6af4047..a1dc00d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,89 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "argh" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "argh_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "argh_shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "argh_derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "argh_shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "argh_shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "reid" version = "0.1.0" +dependencies = [ + "argh 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] +[[package]] +name = "syn" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-segmentation" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum argh 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca1877e24cecacd700d469066e0160c4f8497cc5635367163f50c8beec820154" +"checksum argh_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e742194e0f43fc932bcb801708c2b279d3ec8f527e3acda05a6a9f342c5ef764" +"checksum argh_shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e1ba68f4276a778591e36a0c348a269888f3a177c8d2054969389e3b59611ff5" +"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +"checksum syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd" +"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" +"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" diff --git a/Cargo.toml b/Cargo.toml index def62c4..2715837 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ keywords = ["compiler", "language", "scripting", "parsing", "virtual machine"] edition = "2018" [dependencies] +argh = "0.1.3" \ No newline at end of file diff --git a/src/compiler.rs b/src/compiler.rs index d89bb5c..4b1f16a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -3,7 +3,7 @@ use std::num::ParseIntError; use super::errors::CompilerError; use super::parser::{Expression, LiteralPattern, ParsedReid, Pattern, Position, Statement}; -use super::vm::{BuiltinFunctionDef, FunctionDef, FunctionSignature, VariableType}; +use super::vm::{FunctionSignature, VariableType}; type Variable = (HeapID, VariableType); pub type FuncID = usize; diff --git a/src/errors.rs b/src/errors.rs index 7fd999c..f003ba4 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -19,6 +19,7 @@ impl From for GenericError { #[derive(Debug)] pub enum SyntaxError { + #[allow(dead_code)] Fatal, ExpectedToken(Position, char), ExpectedExpression(Position, Option>), @@ -61,6 +62,7 @@ impl Display for SyntaxError { #[derive(Debug)] pub enum CompilerError { + #[allow(dead_code)] Fatal, VariableExists(Position, String), VariableNotExists(Position, String), @@ -71,16 +73,6 @@ pub enum CompilerError { ParseIntError(ParseIntError), } -impl CompilerError { - fn from_opt(from: &Option>) -> String { - if let Some(err) = from { - format!("\n {}", err) - } else { - String::new() - } - } -} - impl Display for CompilerError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let text = match self { @@ -129,6 +121,7 @@ impl Display for ParamList { #[derive(Debug)] pub enum RuntimePanic { + #[allow(dead_code)] Fatal, InvalidCommandIdx(usize), ScopeStackUnderflow, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index edf9ccc..09308a5 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -82,8 +82,8 @@ impl Parser { pub fn expect>(&mut self, expectable: Expectable) -> Expect { match expectable { Expectable::Static(val) => self.expect_static(val), - Ident => self.expect_ident(), - StringLit => self.expect_string_lit(), + Expectable::Ident => self.expect_ident(), + Expectable::StringLit => self.expect_string_lit(), } } @@ -221,6 +221,7 @@ impl Parser { Position(self.line_number, self.character_number) } + #[allow(unused_assignments)] fn skip_whitespace_confident(&mut self, confident: bool) { let mut next = ' '; while self.remaining() > 0 && { @@ -239,6 +240,7 @@ impl Parser { } } +#[allow(dead_code)] pub enum Expectable> { Static(T), Ident, diff --git a/src/vm/mod.rs b/src/vm/mod.rs index d917a7a..77a05d4 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -1,8 +1,6 @@ pub mod functions; use std::collections::HashMap; -use std::fmt; -use std::fmt::Display; use super::compiler::{Command, CompiledReid, HeapID}; use super::errors::RuntimePanic;