From dd38069bc1f8b696e8f0c50f43e0e7954729acf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 5 Mar 2021 20:12:39 +0100 Subject: better errors on invalid outer tokens --- src/compiler.rs | 12 ++++++++---- src/sectionizer.rs | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/compiler.rs b/src/compiler.rs index 9f9d6ef..16887a0 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -1571,8 +1571,8 @@ impl Compiler { (Token::Newline, ..) => {} - _ => { - error!(self, "Invalid outer statement."); + (a, b, c, d) => { + error!(self, format!("Unknown outer token sequence: {:?} {:?} {:?} {:?}.", a, b, c, d)) } } } @@ -1686,7 +1686,7 @@ impl Compiler { pub(crate) fn compile(&mut self, name: &str, file: &Path, functions: &[(String, RustFunction)]) -> Result> { for section in 0..self.sections.len() { self.init_section(section); - let section = &self.sections[section]; + let section = &mut self.sections[section]; match (section.tokens.get(0), section.tokens.get(1), section.tokens.get(2)) { (Some((Token::Use, _)), Some((Token::Identifier(name), _)), ..) => { @@ -1737,7 +1737,8 @@ impl Compiler { (None, ..) => {} (a, b, c) => { - let msg = format!("Unknown outer token sequence: {:?} {:?} {:?}", a, b, c); + section.faulty = true; + let msg = format!("Unknown outer token sequence: {:?} {:?} {:?}. Expected 'use', function, blob or variable.", a, b, c); error!(self, msg); } } @@ -1755,6 +1756,9 @@ impl Compiler { let mut block = Block::new(name, file); for section in 0..self.sections.len() { self.init_section(section); + if self.sections[section].faulty { + continue; + } while !matches!(self.peek(), Token::EOF | Token::Use) { self.outer_statement(&mut block); expect!(self, Token::Newline | Token::EOF, diff --git a/src/sectionizer.rs b/src/sectionizer.rs index c9cfcd5..8c5e238 100644 --- a/src/sectionizer.rs +++ b/src/sectionizer.rs @@ -6,6 +6,7 @@ use std::path::{Path, PathBuf}; pub struct Section { pub tokens: Vec, pub path: PathBuf, + pub faulty: bool, } impl Section { @@ -13,6 +14,7 @@ impl Section { Self { tokens: Vec::from(tokens), path, + faulty: false, } } } -- cgit v1.2.1